2 #include "../version.h"
\r
4 #include <wx/tokenzr.h>
\r
5 #include <wx/ffile.h>
\r
6 #include <libxml/parser.h>
\r
7 #include <libxml/tree.h>
\r
10 #include "../vcard/vcard.h"
\r
11 #include "../common/dirs.h"
\r
13 size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *stream){
\r
16 Data = wxString::FromUTF8((char *)ptr);
\r
18 stream->Append(Data);
\r
20 return size * nmemb;
\r
24 struct UploadDataStruc{
\r
30 int ProgressFunc(void *clientdata, double TTDown, double NDown, double TTUp, double NUp){
\r
34 CardDAV *IncCardDAV = static_cast<CardDAV*>(clientdata);
\r
35 ProgressRet = IncCardDAV->ProgressFuncProc(clientdata, TTDown, NDown, TTUp, NUp);
\r
36 if (ProgressRet != 0){
\r
43 wxString CardDAV::ServerAddress;
\r
44 int CardDAV::ServerPort;
\r
45 wxString CardDAV::ServerUser;
\r
46 wxString CardDAV::ServerPass;
\r
47 wxString CardDAV::ServerPrefix;
\r
48 wxString CardDAV::ServerAccount;
\r
49 bool CardDAV::ServerSSL;
\r
50 bool *CardDAV::ServerResult;
\r
51 bool *CardDAV::ServerMonitor;
\r
52 bool CardDAV::SSLStatus;
\r
53 bool CardDAV::SSLVerified;
\r
54 bool CardDAV::ValidResponse;
\r
55 bool CardDAV::AuthPassed;
\r
56 bool CardDAV::HasCalDAVSupport;
\r
57 bool CardDAV::AbortConnection;
\r
58 wxString CardDAV::ServerResponse;
\r
59 wxString CardDAV::ServerMethod;
\r
60 wxString CardDAV::ServerFilenameLocation;
\r
61 wxString CardDAV::ServerUploadData;
\r
62 wxString CardDAV::ETagData;
\r
63 wxString CardDAV::ETagResult;
\r
64 bool CardDAV::UploadMode;
\r
65 bool CardDAV::EditMode;
\r
66 long CardDAV::ItemIndex;
\r
67 std::map<int, int> *CardDAV::ActivityListPtr;
\r
68 char CardDAV::curlerrbuffer[CURL_ERROR_SIZE];
\r
69 SSLCertCollection CardDAV::SSLCertCol;
\r
70 int CardDAV::SSLErrorCode;
\r
71 int CardDAV::ConnectionErrorCode;
\r
72 wxString CardDAV::PageHeader;
\r
73 wxString CardDAV::PageData;
\r
74 CURLcode CardDAV::claconncode;
\r
75 int CardDAV::HTTPErrorCode;
\r
76 wxString CardDAV::ErrorMessage;
\r
77 SSLCertCollection CardDAV::VerifyCertCollection;
\r
78 bool CardDAV::AllowSelfSign;
\r
83 SSLVerified = FALSE;
\r
85 ValidResponse = FALSE;
\r
86 HasCalDAVSupport = FALSE;
\r
87 SSLCertCol.SuccessCode = 0;
\r
88 AllowSelfSign = FALSE;
\r
90 AbortConnection = FALSE;
\r
96 CardDAV::~CardDAV(){
\r
100 size_t UploadReadFunc(void *ptr, size_t size, size_t nmemb, void *userdata){
\r
102 struct UploadDataStruc *UploadPtr = (struct UploadDataStruc *)userdata;
\r
104 if (UploadPtr->sizeleft){
\r
106 //MeepMoop->sizeleft--;
\r
109 UploadPtr->sizeleft--;
\r
112 wxSChar = UploadPtr->readptr->Mid(UploadPtr->seek,1);
\r
114 //*(char *)ptr = (char)wxSChar.mb_str();
\r
116 strncpy((char *)ptr, (const char*)wxSChar.mb_str(wxConvUTF8), 1);
\r
128 bool CardDAV::SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL){
\r
130 ServerAddress = SvrAddress;
\r
131 ServerPort = SvrPort;
\r
132 ServerUser = SvrUser;
\r
133 ServerPass = SvrPass;
\r
134 ServerSSL = SvrSSL;
\r
140 bool CardDAV::SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL, wxString SvrPrefix, wxString SvrAccount){
\r
142 ServerAddress = SvrAddress;
\r
143 ServerPort = SvrPort;
\r
144 ServerUser = SvrUser;
\r
145 ServerPass = SvrPass;
\r
146 ServerSSL = SvrSSL;
\r
147 ServerPrefix = SvrPrefix;
\r
148 ServerAccount = SvrAccount;
\r
154 bool CardDAV::SetupResultBools(bool *SvrResult, bool *SvrMonitor){
\r
156 ServerResult = SvrResult;
\r
157 ServerMonitor = SvrMonitor;
\r
163 bool CardDAV::HasValidResponse(){
\r
165 return ValidResponse;
\r
169 bool CardDAV::CanDoCardDAV(){
\r
171 return HasCalDAVSupport;
\r
175 bool CardDAV::CanDoSSL(){
\r
181 bool CardDAV::SSLVerify(){
\r
183 return SSLVerified;
\r
187 bool CardDAV::AbleToLogin(){
\r
193 bool CardDAV::IsSelfSigned(){
\r
195 return AllowSelfSign;
\r
201 size_t CardDAV::WritebackFunc(char *ptr, size_t size, size_t nmemb, FILE *stream){
\r
204 Data = wxString::FromUTF8((char *)ptr);
\r
205 if ((bool)stream == TRUE){
\r
206 PageHeader.Append(Data);
\r
208 PageData.Append(Data);
\r
210 return size * nmemb;
\r
216 int CardDAV::ProgressFuncProc(void *clientdata, double TTUp, double NUp, double TTDown, double NDown){
\r
218 if (AbortConnection == TRUE){
\r
230 void CardDAV::Abort(){
\r
232 AbortConnection = TRUE;
\r
236 CURLcode CardDAV::SSLVerifyTest(){
\r
239 PageHeader.Clear();
\r
243 AbortConnection = FALSE;
\r
248 wxString ServerAddressURL;
\r
249 wxString ServerAuth;
\r
250 wxString ServerAddressSSL;
\r
251 wxString ServerAddressNormal;
\r
253 conn = curl_easy_init();
\r
255 /*struct CardDAVCURLPasser {
\r
258 bool HeaderMode = TRUE;
\r
260 } CardDAVHeader, CardDAVFooter;
\r
262 CardDAVHeader.Data = this;
\r
263 CardDAVHeader.HeaderMode = TRUE;
\r
265 CardDAVFooter.Data = this;
\r
266 CardDAVFooter.HeaderMode = FALSE;*/
\r
271 ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
272 ServerAddressSSL = wxT("https://") + ServerAddressURL;
\r
277 struct curl_slist *certdata;
\r
278 struct curl_certinfo *certinfo;
\r
281 ptr.certdata = NULL;
\r
283 // Setup two initial connections and attempt to get the certificate data.
\r
285 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
286 curl_easy_setopt(conn, CURLOPT_CERTINFO, 1);
\r
287 curl_easy_setopt(conn, CURLOPT_VERBOSE, 1L);
\r
288 //curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, FALSE);
\r
289 //curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, FALSE);
\r
290 curl_easy_setopt(conn, CURLOPT_ERRORBUFFER, curlerrbuffer);
\r
291 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
292 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
293 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
295 conncode = (curl_easy_perform(conn));
\r
297 // Check if the SSL certificate is valid or self-signed or some other
\r
300 if (conncode == CURLE_OK){
\r
302 // Connection is OK. Do nothing.
\r
304 *ServerResult = TRUE;
\r
306 } else if (conncode == CURLE_SSL_CACERT || conncode == CURLE_SSL_CONNECT_ERROR){
\r
308 connssldata = curl_easy_init();
\r
310 // Retry but get the certificates without peer/host verification.
\r
312 curl_easy_setopt(connssldata, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
313 curl_easy_setopt(connssldata, CURLOPT_CERTINFO, 1);
\r
314 curl_easy_setopt(connssldata, CURLOPT_VERBOSE, 1L);
\r
315 curl_easy_setopt(connssldata, CURLOPT_ERRORBUFFER, curlerrbuffer);
\r
316 curl_easy_setopt(connssldata, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
317 curl_easy_setopt(connssldata, CURLOPT_WRITEDATA, &PageData);
\r
318 curl_easy_setopt(connssldata, CURLOPT_WRITEHEADER, &PageHeader);
\r
319 curl_easy_setopt(connssldata, CURLOPT_SSL_VERIFYPEER, 0L);
\r
320 curl_easy_setopt(connssldata, CURLOPT_SSL_VERIFYHOST, 0L);
\r
322 CURLcode certfetchcode;
\r
324 certfetchcode = (curl_easy_perform(connssldata));
\r
326 VerifyCertCollection = BuildSSLCollection(connssldata);
\r
328 if (certfetchcode == CURLE_OK){
\r
330 curl_easy_getinfo(connssldata, CURLINFO_CERTINFO, &ptr.certdata);
\r
332 VerifyCertCollection = BuildSSLCollection(connssldata);
\r
336 conncode = certfetchcode;
\r
340 *ServerResult = FALSE;
\r
344 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
345 curl_easy_strerror(conncode));
\r
347 ErrorMessage = wxString::Format(wxT("%s"), curl_easy_strerror(conncode));
\r
349 *ServerResult = FALSE;
\r
355 curl_easy_cleanup(conn);
\r
361 SSLCertCollection CardDAV::GetSSLVerifyResults(){
\r
362 return VerifyCertCollection;
\r
365 void CardDAV::AllowSelfSignTest(bool AllowSelfSignIn){
\r
366 AllowSelfSign = AllowSelfSignIn;
\r
369 bool CardDAV::Connect(){
\r
372 PageHeader.Clear();
\r
376 AbortConnection = FALSE;
\r
380 wxString ServerAddressURL;
\r
381 wxString ServerAuth;
\r
382 wxString ServerAddressSSL;
\r
383 wxString ServerAddressNormal;
\r
385 conn = curl_easy_init();
\r
387 struct CardDAVCURLPasser {
\r
390 bool HeaderMode = TRUE;
\r
392 } CardDAVHeader, CardDAVFooter;
\r
394 CardDAVHeader.Data = this;
\r
395 CardDAVHeader.HeaderMode = TRUE;
\r
397 CardDAVFooter.Data = this;
\r
398 CardDAVFooter.HeaderMode = FALSE;
\r
403 ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
404 ServerAddressSSL = wxT("https://") + ServerAddressURL;
\r
405 ServerAddressNormal = wxT("http://") + ServerAddressURL;
\r
407 ServerAuth = ServerUser + wxT(":") + ServerPass;
\r
413 char *ServerAdrSSLChar = new char[(ServerAddressSSL.Length() - 1)];
\r
414 //memset(ServerAdrSSLChar, 0, ServerAddressSSL.Length());
\r
415 strncpy(ServerAdrSSLChar, (const char*)ServerAddressSSL.mb_str(wxConvUTF8), (ServerAddressSSL.Length() - 1));
\r
417 char *ServerAdrNorChar = new char[(ServerAddressNormal.Length() - 1)];
\r
418 //memset(ServerAdrNorChar, 0, ServerAddressSSL.Length());
\r
419 strncpy(ServerAdrNorChar, (const char*)ServerAddressNormal.mb_str(wxConvUTF8), (ServerAddressNormal.Length() - 1));
\r
421 char *ServerAuthChar = new char[(ServerAuth.Length() - 1)];
\r
422 //memset(ServerAuthChar, 0, ServerAddressSSL.Length());
\r
423 strncpy(ServerAuthChar, (const char*)ServerAuth.mb_str(wxConvUTF8), (ServerAuth.Length() - 1));
\r
430 struct curl_slist *certdata;
\r
431 struct curl_certinfo *certinfo;
\r
434 ptr.certdata = NULL;
\r
436 // Setup two initial connections and attempt to get the certificate data.
\r
438 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
439 curl_easy_setopt(conn, CURLOPT_CERTINFO, 1);
\r
441 conncode = (curl_easy_perform(conn));
\r
443 // Check if the SSL certificate is valid or self-signed or some other
\r
446 if (conncode == CURLE_OK){
\r
448 // Connection is OK. Do nothing.
\r
450 } else if (conncode == CURLE_SSL_CACERT){
\r
452 // Post message saying SSL certificate is invalid.
\r
454 curl_easy_getinfo(conn, CURLINFO_CERTINFO, &ptr.certdata);
\r
458 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
459 curl_easy_strerror(conncode));
\r
461 ErrorMessage = wxString::Format(wxT("%s"), curl_easy_strerror(conncode));
\r
463 *ServerResult = FALSE;
\r
468 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
469 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
470 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
471 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
472 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
473 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
474 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
475 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
476 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
477 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
478 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
479 curl_easy_setopt(conn, CURLOPT_CERTINFO, 1);
\r
481 if (AllowSelfSign == TRUE){
\r
482 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);
\r
483 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);
\r
486 conncode = (curl_easy_perform(conn));
\r
488 ptr.certdata = NULL;
\r
490 curl_easy_getinfo(conn, CURLINFO_CERTINFO, &ptr.certdata);
\r
492 if (conncode == CURLE_OK){
\r
494 // Process the server header response and look for
\r
495 // 'addressbook' within the DAV header.
\r
497 wxStringTokenizer wxSHeaderLines(PageHeader, wxT("\r\n"));
\r
498 wxString wxSHeaderLine;
\r
499 std::map<int, wxString> DAVHeaderLines;
\r
501 while (wxSHeaderLines.HasMoreTokens()){
\r
503 wxSHeaderLine = wxSHeaderLines.GetNextToken();
\r
505 if (wxSHeaderLine.Mid(0, 4) == wxT("DAV:")){
\r
507 // Look for address book in the line.
\r
509 if (wxSHeaderLine.Find(wxT("addressbook")) != wxNOT_FOUND){
\r
511 HasCalDAVSupport = TRUE;
\r
519 *ServerResult = TRUE;
\r
520 ValidResponse = TRUE;
\r
525 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
\r
527 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
528 curl_easy_strerror(conncode));
\r
530 ErrorMessage = wxString::Format(wxT("%s"), curl_easy_strerror(conncode));
\r
532 *ServerResult = TRUE;
\r
533 ValidResponse = FALSE;
\r
534 AuthPassed = FALSE;
\r
540 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
541 curl_easy_strerror(conncode));
\r
543 ErrorMessage = wxString::Format(wxT("%s"), curl_easy_strerror(conncode));
\r
545 *ServerResult = FALSE;
\r
554 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressNormal.mb_str(wxConvUTF8));
\r
555 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
556 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
557 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
558 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
559 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
560 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
561 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
562 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
563 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
564 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
566 conncode = (curl_easy_perform(conn));
\r
568 if (conncode == CURLE_OK){
\r
570 // Process the server header response and look for
\r
571 // 'addressbook' within the DAV header.
\r
573 wxStringTokenizer wxSHeaderLines(PageHeader, wxT("\r\n"));
\r
574 wxString wxSHeaderLine;
\r
575 std::map<int, wxString> DAVHeaderLines;
\r
577 while (wxSHeaderLines.HasMoreTokens()){
\r
579 wxSHeaderLine = wxSHeaderLines.GetNextToken();
\r
581 if (wxSHeaderLine.Mid(0, 4) == wxT("DAV:")){
\r
583 // Look for address book in the line.
\r
585 if (wxSHeaderLine.Find(wxT("addressbook")) != wxNOT_FOUND){
\r
587 HasCalDAVSupport = TRUE;
\r
595 *ServerResult = TRUE;
\r
596 ValidResponse = TRUE;
\r
601 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
\r
603 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
604 curl_easy_strerror(conncode));
\r
606 *ServerResult = TRUE;
\r
607 ValidResponse = FALSE;
\r
608 AuthPassed = FALSE;
\r
614 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
615 curl_easy_strerror(conncode));
\r
617 *ServerResult = FALSE;
\r
622 // TODO: Double check and make sure HTTP Authentication is possible.
\r
626 *ServerResult = TRUE;
\r
631 void CardDAV::GetSSLResults(){
\r
637 void CardDAV::ProcessDataThread(){
\r
640 PageHeader.Clear();
\r
644 AbortConnection = FALSE;
\r
648 wxString ServerAddressURL;
\r
649 wxString ServerAuth;
\r
650 wxString ServerAddressSSL;
\r
651 wxString ServerAddressNormal;
\r
653 conn = curl_easy_init();
\r
655 struct CardDAVCURLPasser {
\r
658 bool HeaderMode = TRUE;
\r
660 } CardDAVHeader, CardDAVFooter;
\r
662 CardDAVHeader.Data = this;
\r
663 CardDAVHeader.HeaderMode = TRUE;
\r
665 CardDAVFooter.Data = this;
\r
666 CardDAVFooter.HeaderMode = FALSE;
\r
672 wxString ETagOriginal;
\r
673 wxString ETagServer;
\r
675 ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/") + ServerPrefix + ServerFilenameLocation;
\r
676 ServerAddressSSL = wxT("https://") + ServerAddressURL;
\r
677 ServerAddressNormal = wxT("http://") + ServerAddressURL;
\r
679 ServerAuth = ServerUser + wxT(":") + ServerPass;
\r
685 char *ServerAdrSSLChar = new char[(ServerAddressSSL.Length() - 1)];
\r
686 //memset(ServerAdrSSLChar, 0, ServerAddressSSL.Length());
\r
687 strncpy(ServerAdrSSLChar, (const char*)ServerAddressSSL.mb_str(wxConvUTF8), (ServerAddressSSL.Length() - 1));
\r
689 char *ServerAdrNorChar = new char[(ServerAddressNormal.Length() - 1)];
\r
690 //memset(ServerAdrNorChar, 0, ServerAddressSSL.Length());
\r
691 strncpy(ServerAdrNorChar, (const char*)ServerAddressNormal.mb_str(wxConvUTF8), (ServerAddressNormal.Length() - 1));
\r
693 char *ServerAuthChar = new char[(ServerAuth.Length() - 1)];
\r
694 //memset(ServerAuthChar, 0, ServerAddressSSL.Length());
\r
695 strncpy(ServerAuthChar, (const char*)ServerAuth.mb_str(wxConvUTF8), (ServerAuth.Length() - 1));
\r
699 //std::string WriteDataString = std::string(ServerUploadData.mb_str());
\r
701 std::map<int,int>::iterator ActIter;
\r
702 struct UploadDataStruc UploadData;
\r
705 ActIter = ActivityListPtr->find((int)ItemIndex);
\r
707 // Update result flag.
\r
709 ActIter->second = 1;
\r
711 // Setup the request mode if it is not empty.
\r
713 if (!ServerMethod.IsEmpty()){
\r
715 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, (const char*)ServerMethod.mb_str(wxConvUTF8));
\r
721 wxString ServerCertFilename;
\r
722 bool MatchingCert = FALSE;
\r
724 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
725 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
726 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
727 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
728 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
729 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
730 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
731 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
732 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
733 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
734 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
735 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
736 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
738 if (UploadMode == TRUE){
\r
740 UploadData.readptr = &ServerUploadData;
\r
741 UploadData.sizeleft = ServerUploadData.Len();
\r
742 curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
743 curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
744 curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
748 ServerCertFilename = GetAccountDir(ServerAccount, TRUE);
\r
750 if (wxFile::Exists(ServerCertFilename) == TRUE){
\r
752 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 1);
\r
753 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 2);
\r
754 curl_easy_setopt(conn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8));
\r
758 //UploadData.readptr = &CardDAVDataQuery;
\r
759 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
760 //curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
761 //curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
762 //curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
764 //curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writefunc);
\r
766 claconncode = (curl_easy_perform(conn));
\r
768 // If CURLE_PEER_FAILED_VERIFICATION is returned, retry without
\r
769 // the local certificate in use.
\r
771 if (claconncode == CURLE_PEER_FAILED_VERIFICATION){
\r
773 curl_easy_cleanup(conn);
\r
774 conn = curl_easy_init();
\r
776 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
777 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
778 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
779 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
780 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
781 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
782 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
783 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
784 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
785 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
786 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
787 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
788 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
790 if (UploadMode == TRUE){
\r
792 UploadData.readptr = &ServerUploadData;
\r
793 UploadData.sizeleft = ServerUploadData.Len();
\r
794 curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
795 curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
796 curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
800 claconncode = (curl_easy_perform(conn));
\r
802 // If claconncode is CURLE_OK then delete the certificate file as that
\r
803 // is no longer needed.
\r
805 if (claconncode == CURLE_OK){
\r
807 // Delete the certificate file.
\r
809 wxRemoveFile(ServerCertFilename);
\r
815 // Check if it fails with a CURLE_SSL_CACERT then compare
\r
816 // the certificates as PEM files.
\r
818 if (claconncode == CURLE_SSL_CACERT && wxFile::Exists(ServerCertFilename) == TRUE){
\r
820 //curl_easy_cleanup(conn);
\r
821 //conn = curl_easy_init();
\r
824 sslerrconn = curl_easy_init();
\r
825 CURLcode sslerrconncode;
\r
827 //claconncode = (curl_easy_perform(conn));
\r
829 wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
831 curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));
\r
832 curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0);
\r
833 curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
834 curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60);
\r
835 curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE);
\r
836 curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
837 curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
838 curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData);
\r
839 curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader);
\r
840 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this);
\r
841 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
842 curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);
\r
843 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);
\r
844 curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);
\r
846 wxString SSLLocalData;
\r
847 wxString SSLServerData;
\r
849 sslerrconncode = (curl_easy_perform(sslerrconn));
\r
851 SSLCertCol = BuildSSLCollection(sslerrconn);
\r
852 std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertCol.SSLCollection.find(0);
\r
853 std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
\r
855 wxFFile SSLLocalFile;
\r
857 #if wxABI_VERSION < 20900
\r
858 SSLLocalFile.Open(ServerCertFilename.c_str(), wxT("r"));
\r
860 SSLLocalFile.Open(ServerCertFilename, wxT("r"));
\r
863 // Load the recovery database for tasks not done.
\r
865 if (SSLLocalFile.IsOpened() == TRUE){
\r
867 // Check if we are using wxWidgets version 2.8 or less and
\r
868 // execute the required command accordingly.
\r
870 SSLLocalFile.ReadAll(&SSLLocalData, wxConvAuto());
\r
875 SSLServerData = SSLDataIter->second;
\r
877 if (SSLLocalData == SSLServerData){
\r
879 // Server key matches with local key so retry with CURLOPT_SSL_VERIFYPEER
\r
880 // and CURLOPT_SSL_VERIFYHOST off.
\r
882 curl_easy_cleanup(conn);
\r
883 conn = curl_easy_init();
\r
886 PageHeader.clear();
\r
888 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
889 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
890 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
891 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
892 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
893 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
894 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
895 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
896 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
897 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
898 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
899 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
900 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
902 if (UploadMode == TRUE){
\r
904 UploadData.readptr = &ServerUploadData;
\r
905 UploadData.sizeleft = ServerUploadData.Len();
\r
906 curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
907 curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
908 curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
912 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0);
\r
913 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0);
\r
915 claconncode = (curl_easy_perform(conn));
\r
917 MatchingCert = TRUE;
\r
921 if (MatchingCert == FALSE){
\r
923 claconncode = CURLE_SSL_CACERT;
\r
928 curl_easy_cleanup(sslerrconn);
\r
932 // Sort out SSL error.
\r
934 // When SSL cert error occurs, connect again and fetch certificates.
\r
935 // Display a message to the user explaining that an invalid
\r
936 // certificate has been given and let the user decide what
\r
939 if (claconncode == CURLE_OK){
\r
941 } else if (claconncode == CURLE_SSL_CACERT || claconncode == CURLE_PEER_FAILED_VERIFICATION){
\r
944 sslerrconn = curl_easy_init();
\r
945 CURLcode sslerrconncode;
\r
947 wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
949 // Replace conn with sslerrconn!
\r
951 curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));
\r
952 curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0);
\r
953 curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
954 curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60);
\r
955 curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE);
\r
956 curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
957 curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
958 curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData);
\r
959 curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader);
\r
960 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this);
\r
961 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
962 curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);
\r
963 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);
\r
964 curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);
\r
966 sslerrconncode = (curl_easy_perform(sslerrconn));
\r
968 SSLCertCol = BuildSSLCollection(sslerrconn);
\r
969 SSLCertCol.SuccessCode = 1;
\r
973 } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){
\r
975 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
976 curl_easy_strerror(claconncode));
\r
978 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
979 fprintf(stderr, "Error code was: %d\n", http_code);
\r
985 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
986 curl_easy_strerror(claconncode));
\r
988 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
989 fprintf(stderr, "Error code was: %d\n", http_code);
\r
999 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressNormal.mb_str(wxConvUTF8));
\r
1000 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
1001 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1002 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1003 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1004 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1005 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1006 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1007 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1008 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1009 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
1010 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
1011 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1013 if (UploadMode == TRUE){
\r
1015 UploadData.readptr = &ServerUploadData;
\r
1016 UploadData.sizeleft = ServerUploadData.Len();
\r
1017 curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
1018 curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
1019 curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
1023 conncode = (curl_easy_perform(conn));
\r
1025 if (conncode == CURLE_OK){
\r
1027 // Process the server header response and look for
\r
1028 // 'addressbook' within the DAV header.
\r
1030 wxStringTokenizer wxSHeaderLines(PageHeader, wxT("\r\n"));
\r
1031 wxString wxSHeaderLine;
\r
1032 std::map<int, wxString> DAVHeaderLines;
\r
1034 while (wxSHeaderLines.HasMoreTokens()){
\r
1036 wxSHeaderLine = wxSHeaderLines.GetNextToken();
\r
1038 if (wxSHeaderLine.Mid(0, 5) == wxT("ETag:")){
\r
1040 ETagData = wxSHeaderLine.Mid(5);
\r
1042 ETagData.Trim(FALSE);
\r
1044 // Check for commas.
\r
1046 if (ETagData.Mid(0, 1) == wxT("\"") && ETagData.Mid((ETagData.Len() - 1), 1) == wxT("\"")){
\r
1048 ETagData.Remove(0, 1);
\r
1049 ETagData.RemoveLast();
\r
1055 if (wxSHeaderLine.Mid(0, 4) == wxT("DAV:")){
\r
1057 // Look for address book in the line.
\r
1059 if (wxSHeaderLine.Find(wxT("addressbook")) != wxNOT_FOUND){
\r
1061 HasCalDAVSupport = TRUE;
\r
1069 // Get the ETag from the header.
\r
1071 if (UploadMode == TRUE){
\r
1073 wxString PageHeaderLine;
\r
1075 wxStringTokenizer PageHeaderSplit(PageHeader, wxT("\r\n"));
\r
1077 if (PageHeaderSplit.HasMoreTokens()){
\r
1079 PageHeaderLine = PageHeaderSplit.GetNextToken();
\r
1085 ActIter->second = 4;
\r
1088 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
\r
1090 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
\r
1092 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1093 curl_easy_strerror(conncode));
\r
1095 fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
\r
1098 ActIter->second = 2;
\r
1103 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1104 curl_easy_strerror(conncode));
\r
1106 ActIter->second = 2;
\r
1119 // Connection was successful
\r
1124 wxString ServerAddressURL;
\r
1126 // Try secure connection first.
\r
1131 ServerAddressURL = wxT("http://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
1133 ServerAddressURL.Trim();
\r
1135 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressURL.mb_str(wxConvUTF8));
\r
1136 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1137 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, NULL);
\r
1138 curl_easy_setopt(conn, CURLOPT_WRITEDATA, NULL);
\r
1141 conncode = (curl_easy_perform(conn));
\r
1143 if (conncode == CURLE_OK){
\r
1144 *ServerResult = TRUE;
\r
1149 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1150 curl_easy_strerror(conncode));
\r
1152 *ServerResult = FALSE;
\r
1156 // Failed. So use unsecure connection.
\r
1159 ServerAddress = wxT("http://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort);
\r
1161 curl_easy_setopt(conn, CURLOPT_URL, ServerAddress.c_str());
\r
1163 conncode = (curl_easy_perform(conn));
\r
1165 if (conncode != CURLE_OK){
\r
1166 *ServerResult = FALSE;
\r
1169 *ServerResult = TRUE;
\r
1175 *ServerResult = FALSE;
\r
1184 //ActIter->second = 1;
\r
1185 *ServerResult = TRUE;
\r
1190 void CardDAV::ProcessData(){
\r
1192 std::thread ConnectThread(&CardDAV::ProcessDataThread, this);
\r
1193 ConnectThread.detach();
\r
1197 void CardDAV::SetServerFilename(wxString Filename){
\r
1199 ServerFilenameLocation = Filename;
\r
1203 void CardDAV::GetServerContactData()
\r
1207 PageHeader.Clear();
\r
1210 AuthPassed = TRUE;
\r
1211 AbortConnection = FALSE;
\r
1213 wxString ServerCertFilename;
\r
1214 bool MatchingCert = FALSE;
\r
1217 CURLcode conncode;
\r
1218 wxString ServerAddressURL;
\r
1219 wxString ServerAuth;
\r
1220 wxString ServerAddressSSL;
\r
1221 wxString ServerAddressNormal;
\r
1223 conn = curl_easy_init();
\r
1225 struct CardDAVCURLPasser {
\r
1228 bool HeaderMode = TRUE;
\r
1230 } CardDAVHeader, CardDAVFooter;
\r
1232 CardDAVHeader.Data = this;
\r
1233 CardDAVHeader.HeaderMode = TRUE;
\r
1235 CardDAVFooter.Data = this;
\r
1236 CardDAVFooter.HeaderMode = FALSE;
\r
1241 ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/") + ServerPrefix + ServerFilenameLocation;
\r
1242 ServerAddressSSL = wxT("https://") + ServerAddressURL;
\r
1243 ServerAddressNormal = wxT("http://") + ServerAddressURL;
\r
1245 ServerAuth = ServerUser + wxT(":") + ServerPass;
\r
1251 char *ServerAdrSSLChar = new char[(ServerAddressSSL.Length() - 1)];
\r
1252 //memset(ServerAdrSSLChar, 0, ServerAddressSSL.Length());
\r
1253 strncpy(ServerAdrSSLChar, (const char*)ServerAddressSSL.mb_str(wxConvUTF8), (ServerAddressSSL.Length() - 1));
\r
1255 char *ServerAdrNorChar = new char[(ServerAddressNormal.Length() - 1)];
\r
1256 //memset(ServerAdrNorChar, 0, ServerAddressSSL.Length());
\r
1257 strncpy(ServerAdrNorChar, (const char*)ServerAddressNormal.mb_str(wxConvUTF8), (ServerAddressNormal.Length() - 1));
\r
1259 char *ServerAuthChar = new char[(ServerAuth.Length() - 1)];
\r
1260 //memset(ServerAuthChar, 0, ServerAddressSSL.Length());
\r
1261 strncpy(ServerAuthChar, (const char*)ServerAuth.mb_str(wxConvUTF8), (ServerAuth.Length() - 1));
\r
1265 //std::string WriteDataString = std::string(ServerUploadData.mb_str());
\r
1267 std::map<int,int>::iterator ActIter;
\r
1268 struct UploadDataStruc UploadData;
\r
1271 ActIter = ActivityListPtr->find((int)ItemIndex);
\r
1273 //ActIter->second = 1;
\r
1275 /*wxString CardDAVDataQuery = wxT("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n");
\r
1276 CardDAVDataQuery.Append(wxT("<C:addressbook-multiget xmlns:D=\"DAV:\"\r\n"));
\r
1277 CardDAVDataQuery.Append(wxT(" xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\r\n"));
\r
1278 CardDAVDataQuery.Append(wxT("<D:prop><D:getetag/>\r\n"));
\r
1279 CardDAVDataQuery.Append(wxT("<C:address-data>\r\n"));
\r
1280 CardDAVDataQuery.Append(wxT(" <C:allprop/>\r\n"));
\r
1281 CardDAVDataQuery.Append(wxT("</C:address-data></D:prop>\r\n"));
\r
1282 CardDAVDataQuery.Append(wxT("</C:addressbook-multiget>"));*/
\r
1286 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
1287 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
1288 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1289 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1290 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1291 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1292 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1293 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1294 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1295 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1296 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1298 //UploadData.readptr = &CardDAVDataQuery;
\r
1299 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
1300 //curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
1301 //curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
1302 //curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
1304 ServerCertFilename = GetAccountDir(ServerAccount, TRUE);
\r
1306 if (wxFile::Exists(ServerCertFilename) == TRUE){
\r
1308 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 1);
\r
1309 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 2);
\r
1310 curl_easy_setopt(conn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8));
\r
1314 claconncode = (curl_easy_perform(conn));
\r
1316 // If CURLE_PEER_FAILED_VERIFICATION is returned, retry without
\r
1317 // the local certificate in use.
\r
1319 if (claconncode == CURLE_PEER_FAILED_VERIFICATION){
\r
1321 curl_easy_cleanup(conn);
\r
1322 conn = curl_easy_init();
\r
1324 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
1325 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
1326 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1327 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1328 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1329 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1330 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1331 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1332 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1333 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1334 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1336 //UploadData.readptr = &CardDAVDataQuery;
\r
1337 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
1339 claconncode = (curl_easy_perform(conn));
\r
1341 // If claconncode is CURLE_OK then delete the certificate file as that
\r
1342 // is no longer needed.
\r
1344 if (claconncode == CURLE_OK){
\r
1346 // Delete the certificate file.
\r
1348 wxRemoveFile(ServerCertFilename);
\r
1354 // Check if it fails with a CURLE_SSL_CACERT then compare
\r
1355 // the certificates as PEM files.
\r
1357 if (claconncode == CURLE_SSL_CACERT && wxFile::Exists(ServerCertFilename) == TRUE){
\r
1359 //curl_easy_cleanup(conn);
\r
1360 //conn = curl_easy_init();
\r
1363 sslerrconn = curl_easy_init();
\r
1364 CURLcode sslerrconncode;
\r
1366 //claconncode = (curl_easy_perform(conn));
\r
1368 wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
1370 curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));
\r
1371 curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 1L);
\r
1372 curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1373 curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60);
\r
1374 curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE);
\r
1375 curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1376 curl_easy_setopt(sslerrconn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1377 curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1378 curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData);
\r
1379 curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1380 curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);
\r
1382 //UploadData.readptr = &CardDAVDataQuery;
\r
1383 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
1384 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);
\r
1385 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYHOST, 0);
\r
1386 curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);
\r
1388 wxString SSLLocalData;
\r
1389 wxString SSLServerData;
\r
1391 sslerrconncode = (curl_easy_perform(sslerrconn));
\r
1393 SSLCertCol = BuildSSLCollection(sslerrconn);
\r
1394 std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertCol.SSLCollection.find(0);
\r
1395 std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
\r
1397 wxFFile SSLLocalFile;
\r
1399 #if wxABI_VERSION < 20900
\r
1400 SSLLocalFile.Open(ServerCertFilename.c_str(), wxT("r"));
\r
1402 SSLLocalFile.Open(ServerCertFilename, wxT("r"));
\r
1405 // Load the recovery database for tasks not done.
\r
1407 if (SSLLocalFile.IsOpened() == TRUE){
\r
1409 SSLLocalFile.ReadAll(&SSLLocalData, wxConvAuto());
\r
1414 SSLServerData = SSLDataIter->second;
\r
1416 if (SSLLocalData == SSLServerData){
\r
1418 // Server key matches with local key so retry with CURLOPT_SSL_VERIFYPEER
\r
1419 // and CURLOPT_SSL_VERIFYHOST off.
\r
1421 curl_easy_cleanup(conn);
\r
1422 conn = curl_easy_init();
\r
1425 PageHeader.clear();
\r
1427 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
1428 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
1429 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1430 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1431 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1432 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1433 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1434 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1435 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1436 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1437 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1439 //UploadData.readptr = &CardDAVDataQuery;
\r
1440 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
1441 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0);
\r
1442 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0);
\r
1444 claconncode = (curl_easy_perform(conn));
\r
1446 MatchingCert = TRUE;
\r
1450 if (MatchingCert == FALSE){
\r
1452 claconncode = CURLE_SSL_CACERT;
\r
1457 curl_easy_cleanup(sslerrconn);
\r
1461 // Sort out SSL error.
\r
1463 // When SSL cert error occurs, connect again and fetch certificates.
\r
1464 // Display a message to the user explaining that an invalid
\r
1465 // certificate has been given and let the user decide what
\r
1468 if (claconncode == CURLE_OK){
\r
1470 } else if (claconncode == CURLE_SSL_CACERT || claconncode == CURLE_PEER_FAILED_VERIFICATION){
\r
1473 sslerrconn = curl_easy_init();
\r
1474 CURLcode sslerrconncode;
\r
1476 wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
1478 // Replace conn with sslerrconn!
\r
1480 curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));
\r
1481 curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0);
\r
1482 curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1483 curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60);
\r
1484 curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE);
\r
1485 curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1486 curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1487 curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData);
\r
1488 curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1489 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this);
\r
1490 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
1491 curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);
\r
1492 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);
\r
1493 curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);
\r
1495 sslerrconncode = (curl_easy_perform(sslerrconn));
\r
1497 SSLCertCol = BuildSSLCollection(sslerrconn);
\r
1498 SSLCertCol.SuccessCode = 1;
\r
1502 } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){
\r
1504 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1505 curl_easy_strerror(claconncode));
\r
1506 int http_code = 0;
\r
1507 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
1508 fprintf(stderr, "Error code was: %d\n", http_code);
\r
1514 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1515 curl_easy_strerror(claconncode));
\r
1516 int http_code = 0;
\r
1517 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
1518 fprintf(stderr, "Error code was: %d\n", http_code);
\r
1527 wxString EmptyString;
\r
1529 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressNormal.mb_str(wxConvUTF8));
\r
1530 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
1531 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1532 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1533 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1534 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1535 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1536 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1537 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1538 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1539 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1541 //UploadData.readptr = &CardDAVDataQuery;
\r
1542 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
1543 //curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
1544 //curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
1545 //curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
1547 //UploadData.readptr = &CardDAVDataQuery;
\r
1548 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
1549 //curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
1550 //curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
1551 //curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
1553 //curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writefunc);
\r
1556 PageHeader.Clear();
\r
1558 conncode = (curl_easy_perform(conn));
\r
1560 if (conncode == CURLE_OK){
\r
1562 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
\r
1564 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1565 curl_easy_strerror(conncode));
\r
1567 fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
\r
1574 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1575 curl_easy_strerror(conncode));
\r
1587 wxString CardDAV::GetPageData()
\r
1594 void CardDAV::GetServerETagValueThread()
\r
1598 PageHeader.Clear();
\r
1601 AuthPassed = TRUE;
\r
1602 AbortConnection = FALSE;
\r
1604 bool FilenameIsDirectory = FALSE;
\r
1606 CURLcode conncode;
\r
1607 wxString ServerAddressURL;
\r
1608 wxString ServerAuth;
\r
1609 wxString ServerAddressSSL;
\r
1610 wxString ServerAddressNormal;
\r
1612 conn = curl_easy_init();
\r
1614 struct CardDAVCURLPasser {
\r
1617 bool HeaderMode = TRUE;
\r
1619 } CardDAVHeader, CardDAVFooter;
\r
1621 CardDAVHeader.Data = this;
\r
1622 CardDAVHeader.HeaderMode = TRUE;
\r
1624 CardDAVFooter.Data = this;
\r
1625 CardDAVFooter.HeaderMode = FALSE;
\r
1630 ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/") + ServerPrefix + ServerFilenameLocation;
\r
1631 ServerAddressSSL = wxT("https://") + ServerAddressURL;
\r
1632 ServerAddressNormal = wxT("http://") + ServerAddressURL;
\r
1634 ServerAuth = ServerUser + wxT(":") + ServerPass;
\r
1636 // Workout if path is directory or filename.
\r
1638 /*if (ServerAddress){
\r
1639 FilenameIsDirectory = TRUE;
\r
1641 FilenameIsDirectory = FALSE;
\r
1648 char *ServerAdrSSLChar = new char[(ServerAddressSSL.Length() - 1)];
\r
1649 //memset(ServerAdrSSLChar, 0, ServerAddressSSL.Length());
\r
1650 strncpy(ServerAdrSSLChar, (const char*)ServerAddressSSL.mb_str(wxConvUTF8), (ServerAddressSSL.Length() - 1));
\r
1652 char *ServerAdrNorChar = new char[(ServerAddressNormal.Length() - 1)];
\r
1653 //memset(ServerAdrNorChar, 0, ServerAddressSSL.Length());
\r
1654 strncpy(ServerAdrNorChar, (const char*)ServerAddressNormal.mb_str(wxConvUTF8), (ServerAddressNormal.Length() - 1));
\r
1656 char *ServerAuthChar = new char[(ServerAuth.Length() - 1)];
\r
1657 //memset(ServerAuthChar, 0, ServerAddressSSL.Length());
\r
1658 strncpy(ServerAuthChar, (const char*)ServerAuth.mb_str(wxConvUTF8), (ServerAuth.Length() - 1));
\r
1662 //std::string WriteDataString = std::string(ServerUploadData.mb_str());
\r
1664 std::map<int,int>::iterator ActIter;
\r
1665 struct UploadDataStruc UploadData;
\r
1668 ActIter = ActivityListPtr->find((int)ItemIndex);
\r
1670 static const char* query =
\r
1671 "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
\r
1672 "<C:addressbook-query xmlns:D=\"DAV:\""
\r
1673 " xmlns:C=\"urn:ietf:params:xml:ns:carddav\">"
\r
1674 "<D:prop><D:getetag/>"
\r
1675 //"<C:address-data>"
\r
1677 //"</C:address-data></D:prop>"
\r
1680 "</C:addressbook-query>";
\r
1684 wxString ServerCertFilename;
\r
1685 bool MatchingCert = FALSE;
\r
1687 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
1688 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
1689 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1690 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1691 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1692 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1693 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1694 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1695 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1696 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1697 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
1698 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
1699 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");
\r
1700 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1702 //UploadData.readptr = &CardDAVDataQuery;
\r
1703 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
1704 //curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
1705 //curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
1706 //curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
1708 //curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writefunc);
\r
1709 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
1710 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
1712 ServerCertFilename = GetAccountDir(ServerAccount, TRUE);
\r
1714 if (wxFile::Exists(ServerCertFilename) == TRUE){
\r
1716 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 1);
\r
1717 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 2);
\r
1718 curl_easy_setopt(conn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8));
\r
1722 claconncode = (curl_easy_perform(conn));
\r
1724 // If CURLE_PEER_FAILED_VERIFICATION is returned, retry without
\r
1725 // the local certificate in use.
\r
1727 if (claconncode == CURLE_PEER_FAILED_VERIFICATION){
\r
1729 curl_easy_cleanup(conn);
\r
1730 conn = curl_easy_init();
\r
1732 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
1733 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
1734 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1735 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1736 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1737 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1738 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1739 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1740 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1741 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1742 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
1743 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
1744 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");
\r
1745 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1746 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
1747 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
1749 claconncode = (curl_easy_perform(conn));
\r
1751 // If claconncode is CURLE_OK then delete the certificate file as that
\r
1752 // is no longer needed.
\r
1754 if (claconncode == CURLE_OK){
\r
1756 // Delete the certificate file.
\r
1758 wxRemoveFile(ServerCertFilename);
\r
1764 // Check if it fails with a CURLE_SSL_CACERT then compare
\r
1765 // the certificates as PEM files.
\r
1767 if (claconncode == CURLE_SSL_CACERT && wxFile::Exists(ServerCertFilename) == TRUE){
\r
1769 //curl_easy_cleanup(conn);
\r
1770 //conn = curl_easy_init();
\r
1773 sslerrconn = curl_easy_init();
\r
1774 CURLcode sslerrconncode;
\r
1776 //claconncode = (curl_easy_perform(conn));
\r
1778 wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
1781 PageHeader.clear();
\r
1783 curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));
\r
1784 curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0);
\r
1785 curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1786 curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60);
\r
1787 curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE);
\r
1788 curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1789 curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1790 curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData);
\r
1791 curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1792 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this);
\r
1793 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
1794 curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);
\r
1795 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);
\r
1796 curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);
\r
1797 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 1);
\r
1798 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYHOST, 2);
\r
1799 curl_easy_setopt(sslerrconn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8));
\r
1801 wxString SSLLocalData;
\r
1802 wxString SSLServerData;
\r
1804 sslerrconncode = (curl_easy_perform(sslerrconn));
\r
1806 SSLCertCol = BuildSSLCollection(sslerrconn);
\r
1807 std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertCol.SSLCollection.find(0);
\r
1808 std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
\r
1810 wxFFile SSLLocalFile;
\r
1812 #if wxABI_VERSION < 20900
\r
1813 SSLLocalFile.Open(ServerCertFilename.c_str(), wxT("r"));
\r
1815 SSLLocalFile.Open(ServerCertFilename, wxT("r"));
\r
1818 // Load the recovery database for tasks not done.
\r
1820 if (SSLLocalFile.IsOpened() == TRUE){
\r
1822 // Check if we are using wxWidgets version 2.8 or less and
\r
1823 // execute the required command accordingly.
\r
1825 SSLLocalFile.ReadAll(&SSLLocalData, wxConvAuto());
\r
1830 SSLServerData = SSLDataIter->second;
\r
1832 if (SSLLocalData == SSLServerData){
\r
1834 // Server key matches with local key so retry with CURLOPT_SSL_VERIFYPEER
\r
1835 // and CURLOPT_SSL_VERIFYHOST off.
\r
1837 curl_easy_cleanup(conn);
\r
1838 conn = curl_easy_init();
\r
1841 PageHeader.clear();
\r
1843 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
1844 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
1845 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1846 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1847 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1848 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1849 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1850 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1851 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1852 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1853 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
1854 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
1855 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");
\r
1856 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1857 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
1858 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
1859 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0);
\r
1860 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0);
\r
1862 claconncode = (curl_easy_perform(conn));
\r
1864 MatchingCert = TRUE;
\r
1868 if (MatchingCert == FALSE){
\r
1870 claconncode = CURLE_SSL_CACERT;
\r
1875 curl_easy_cleanup(sslerrconn);
\r
1879 // Sort out SSL error.
\r
1881 // When SSL cert error occurs, connect again and fetch certificates.
\r
1882 // Display a message to the user explaining that an invalid
\r
1883 // certificate has been given and let the user decide what
\r
1886 if (claconncode == CURLE_OK){
\r
1888 } else if (claconncode == CURLE_SSL_CACERT || claconncode == CURLE_PEER_FAILED_VERIFICATION){
\r
1891 sslerrconn = curl_easy_init();
\r
1892 CURLcode sslerrconncode;
\r
1894 wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
1896 // Replace conn with sslerrconn!
\r
1898 curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));
\r
1899 curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0);
\r
1900 curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1901 curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60);
\r
1902 curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE);
\r
1903 curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1904 curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1905 curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData);
\r
1906 curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1907 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this);
\r
1908 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
1909 curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);
\r
1910 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);
\r
1911 curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);
\r
1913 sslerrconncode = (curl_easy_perform(sslerrconn));
\r
1915 SSLCertCol = BuildSSLCollection(sslerrconn);
\r
1916 SSLCertCol.SuccessCode = 1;
\r
1918 curl_easy_cleanup(conn);
\r
1919 curl_easy_cleanup(sslerrconn);
\r
1923 } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){
\r
1925 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1926 curl_easy_strerror(claconncode));
\r
1927 int http_code = 0;
\r
1928 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
1929 fprintf(stderr, "Error code was: %d\n", http_code);
\r
1931 curl_easy_cleanup(conn);
\r
1937 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1938 curl_easy_strerror(claconncode));
\r
1939 int http_code = 0;
\r
1940 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
1941 fprintf(stderr, "Error code was: %d\n", http_code);
\r
1943 curl_easy_cleanup(conn);
\r
1953 wxString EmptyString;
\r
1955 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressNormal.mb_str(wxConvUTF8));
\r
1956 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
1957 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1958 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1959 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1960 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1961 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1962 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1963 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1964 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1965 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
1966 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
1967 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");
\r
1968 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1970 //UploadData.readptr = &CardDAVDataQuery;
\r
1971 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
1972 //curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
1973 //curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
1974 //curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
1976 //curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writefunc);
\r
1977 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
1978 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
1981 PageHeader.Clear();
\r
1983 conncode = (curl_easy_perform(conn));
\r
1985 if (conncode == CURLE_OK){
\r
1987 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
\r
1989 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1990 curl_easy_strerror(conncode));
\r
1996 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1997 curl_easy_strerror(conncode));
\r
2005 xmlDocPtr xmlCardDAVDoc;
\r
2007 xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
\r
2009 xmlNodePtr nodeLevel1;
\r
2010 xmlNodePtr nodeLevel2;
\r
2011 xmlNodePtr nodeLevel3;
\r
2012 xmlNodePtr nodeLevel4;
\r
2013 xmlNodePtr nodeLevel5;
\r
2014 xmlNodePtr nodeLevel6;
\r
2016 std::map<wxString,wxString> xmlDataMap;
\r
2018 wxString DataFilename;
\r
2019 wxString ETagData;
\r
2021 std::string xmlStringSafe;
\r
2023 // Tranverse through the catacombs of the response to get our ETag for the file.
\r
2025 for (nodeLevel1 = xmlCardDAVDoc->children;
\r
2026 nodeLevel1 != NULL;
\r
2027 nodeLevel1 = nodeLevel1->next)
\r
2030 bool HREFFound = FALSE;
\r
2031 bool ETagFound = FALSE;
\r
2033 for (nodeLevel2 = nodeLevel1->children;
\r
2034 nodeLevel2 != NULL;
\r
2035 nodeLevel2 = nodeLevel2->next)
\r
2038 for (nodeLevel3 = nodeLevel2->children;
\r
2039 nodeLevel3 != NULL;
\r
2040 nodeLevel3 = nodeLevel3->next)
\r
2043 if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"href") ||
\r
2044 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:href") ||
\r
2045 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:href")
\r
2048 // Get the filename.
\r
2050 for (nodeLevel4 = nodeLevel3->children;
\r
2051 nodeLevel4 != NULL;
\r
2052 nodeLevel4 = nodeLevel4->next)
\r
2055 if (!xmlStrcmp(nodeLevel4->name, (const xmlChar *)"text") ||
\r
2056 !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"d:text") ||
\r
2057 !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"D:text")
\r
2060 DataFilename = wxString::FromUTF8((const char*)nodeLevel4->content);
\r
2061 wxStringTokenizer wSTDFilename(DataFilename, wxT("/"));
\r
2063 while (wSTDFilename.HasMoreTokens()){
\r
2065 DataFilename = wSTDFilename.GetNextToken();
\r
2079 for (nodeLevel4 = nodeLevel3->children;
\r
2080 nodeLevel4 != NULL;
\r
2081 nodeLevel4 = nodeLevel4->next)
\r
2084 for (nodeLevel5 = nodeLevel4->children;
\r
2085 nodeLevel5 != NULL;
\r
2086 nodeLevel5 = nodeLevel5->next)
\r
2089 if (!xmlStrcmp(nodeLevel5->name, (const xmlChar *)"getetag") ||
\r
2090 !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"d:getetag") ||
\r
2091 !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"D:getetag")
\r
2094 for (nodeLevel6 = nodeLevel5->children;
\r
2095 nodeLevel6 != NULL;
\r
2096 nodeLevel6 = nodeLevel6->next)
\r
2099 // Strip the quotes from the ETag.
\r
2101 ETagData = wxString::FromUTF8((const char*)nodeLevel6->content);
\r
2102 if (ETagData.Mid(0, 1) == wxT("\"") && ETagData.Mid((ETagData.Len() - 1), 1) == wxT("\"")){
\r
2104 ETagData.Remove(0, 1);
\r
2105 ETagData.RemoveLast();
\r
2125 if (HREFFound == TRUE && ETagFound == TRUE){
\r
2127 // Add to the map data.
\r
2129 xmlDataMap.insert(std::make_pair(DataFilename, ETagData));
\r
2131 HREFFound = FALSE;
\r
2132 ETagFound = FALSE;
\r
2139 xmlFreeDoc(xmlCardDAVDoc);
\r
2141 // Get the first result.
\r
2143 for (std::map<wxString,wxString>::iterator iter = xmlDataMap.begin();
\r
2144 iter != xmlDataMap.end(); ++iter){
\r
2146 ETagResult = iter->second;
\r
2151 if (ETagResult.IsEmpty()){
\r
2161 wxString CardDAV::ETagValueResult(){
\r
2163 return ETagResult;
\r
2167 void CardDAV::GetServerETagValue(){
\r
2169 std::thread ConnectThread(&CardDAV::GetServerETagValueThread, this);
\r
2170 ConnectThread.detach();
\r
2174 void CardDAV::SetupData(wxString Method, wxString FilenameLocation, wxString UploadData){
\r
2176 ServerMethod = Method;
\r
2177 ServerFilenameLocation = FilenameLocation;
\r
2178 ServerUploadData = UploadData;
\r
2180 // Check if ServerFilenameLocation has a / at
\r
2181 // the start and if not then append it.
\r
2183 if (ServerFilenameLocation.Left(1) != wxT("/")){
\r
2185 // Not there so insert.
\r
2187 ServerFilenameLocation = wxT("/") + ServerFilenameLocation;
\r
2193 void CardDAV::SetupVariables(std::map<int, int> *actlist, int actindex){
\r
2195 ActivityListPtr = actlist;
\r
2196 ItemIndex = actindex;
\r
2200 wxString CardDAV::GetETagData(){
\r
2206 void CardDAV::SetUploadMode(bool IncMode){
\r
2208 UploadMode = IncMode;
\r
2212 void CardDAV::SetEditMode(bool EditModeInc){
\r
2214 EditMode = EditModeInc;
\r
2218 ContactListData CardDAV::GetContactList(wxString SyncTokenInc){
\r
2220 ContactListData ContactListFinal;
\r
2221 std::map<wxString,FileSyncData> ContactList;
\r
2224 PageHeader.Clear();
\r
2227 AuthPassed = TRUE;
\r
2228 AbortConnection = FALSE;
\r
2231 wxString ServerAddressURL;
\r
2232 wxString ServerAuth;
\r
2233 wxString ServerAddressSSL;
\r
2234 wxString ServerAddressNormal;
\r
2236 conn = curl_easy_init();
\r
2238 struct CardDAVCURLPasser {
\r
2241 bool HeaderMode = TRUE;
\r
2243 } CardDAVHeader, CardDAVFooter;
\r
2245 CardDAVHeader.Data = this;
\r
2246 CardDAVHeader.HeaderMode = TRUE;
\r
2248 CardDAVFooter.Data = this;
\r
2249 CardDAVFooter.HeaderMode = FALSE;
\r
2254 ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/") + ServerPrefix + wxT("/");
\r
2255 ServerAddressSSL = wxT("https://") + ServerAddressURL;
\r
2256 ServerAddressNormal = wxT("http://") + ServerAddressURL;
\r
2258 ServerAuth = ServerUser + wxT(":") + ServerPass;
\r
2260 // Load the sync token file (if it exists).
\r
2262 wxCharBuffer SyncDataBuffer;
\r
2263 wxString SyncData;
\r
2267 SyncTokenInc.Trim();
\r
2269 if (!SyncTokenInc.IsEmpty()){
\r
2271 SyncData = wxT("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
\r
2272 SyncData.Append(wxT("<D:sync-collection xmlns:D=\"DAV:\"\n"));
\r
2273 SyncData.Append(wxT(" xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"));
\r
2274 SyncData.Append(wxT("<D:sync-token>"));
\r
2275 //SyncData.Trim();
\r
2276 //SyncData.Append(wxT("data:,00378c55-1f44-44a2-a255-84f6560b5cac_580"));
\r
2277 SyncData.Append(SyncTokenInc);
\r
2278 //SyncData.Trim();
\r
2279 SyncData.Append(wxT("</D:sync-token>\n"));
\r
2280 SyncData.Append(wxT("<D:sync-level>1</D:sync-level>\n"));
\r
2281 SyncData.Append(wxT("<D:prop>\n"));
\r
2282 SyncData.Append(wxT(" <D:getetag/>\n"));
\r
2283 SyncData.Append(wxT("</D:prop>\n"));
\r
2284 SyncData.Append(wxT("</D:sync-collection>"));
\r
2286 SyncDataBuffer = SyncData.ToUTF8();
\r
2290 SyncData = wxT("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
\r
2291 SyncData.Append(wxT("<D:sync-collection xmlns:D=\"DAV:\""));
\r
2292 SyncData.Append(wxT(" xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"));
\r
2293 SyncData.Append(wxT("<D:sync-token/>\n"));
\r
2294 SyncData.Append(wxT("<D:sync-level>1</D:sync-level>\n"));
\r
2295 SyncData.Append(wxT("<D:prop>\n"));
\r
2296 SyncData.Append(wxT(" <D:getetag/>\n"));
\r
2297 SyncData.Append(wxT("</D:prop>\n"));
\r
2298 SyncData.Append(wxT("</D:sync-collection>\n"));
\r
2300 SyncDataBuffer = SyncData.ToUTF8();
\r
2304 //static const char* query = SyncData.mb_str();
\r
2306 /*char *query = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\
\r
2307 <D:sync-collection xmlns:D=\"DAV:\"\n\
\r
2308 xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n\
\r
2309 <D:sync-token>data:,00378c55-1f44-44a2-a255-84f6560b5cac_580</D:sync-token>\n\
\r
2310 <D:sync-level>1</D:sync-level>\n\
\r
2314 </D:sync-collection>\n";*/
\r
2315 const char* query = SyncDataBuffer.data();
\r
2319 std::map<int,int>::iterator ActIter;
\r
2320 struct UploadDataStruc UploadData;
\r
2322 ActIter = ActivityListPtr->find((int)ItemIndex);
\r
2324 curl_slist *slist = NULL;
\r
2326 slist = curl_slist_append(slist, "Depth: 1");
\r
2330 wxString ServerCertFilename;
\r
2331 bool MatchingCert = FALSE;
\r
2333 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
2334 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
2335 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
\r
2336 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
2337 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
2338 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
2339 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
2340 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
2341 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
2342 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
2343 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
2344 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
2345 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");
\r
2346 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
2347 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, slist);
\r
2348 curl_easy_setopt(conn, CURLOPT_CERTINFO, 1);
\r
2350 ServerCertFilename = GetAccountDir(ServerAccount, TRUE);
\r
2352 if (wxFile::Exists(ServerCertFilename) == TRUE){
\r
2354 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 1);
\r
2355 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 2);
\r
2356 curl_easy_setopt(conn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8));
\r
2360 //UploadData.readptr = &CardDAVDataQuery;
\r
2361 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
2362 //curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
2363 //curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
2364 //curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
2366 //curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writefunc);
\r
2367 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
2368 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
2370 claconncode = (curl_easy_perform(conn));
\r
2372 // If CURLE_PEER_FAILED_VERIFICATION is returned, retry without
\r
2373 // the local certificate in use.
\r
2375 if (claconncode == CURLE_PEER_FAILED_VERIFICATION){
\r
2377 curl_easy_cleanup(conn);
\r
2378 conn = curl_easy_init();
\r
2380 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
2381 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
2382 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
\r
2383 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
2384 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
2385 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
2386 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
2387 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
2388 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
2389 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
2390 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
2391 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
2392 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");
\r
2393 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
2394 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, slist);
\r
2395 curl_easy_setopt(conn, CURLOPT_CERTINFO, 1);
\r
2396 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
2397 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
2399 claconncode = (curl_easy_perform(conn));
\r
2401 // If claconncode is CURLE_OK then delete the certificate file as that
\r
2402 // is no longer needed.
\r
2404 if (claconncode == CURLE_OK){
\r
2406 // Delete the certificate file.
\r
2408 wxRemoveFile(ServerCertFilename);
\r
2414 // Check if it fails with a CURLE_SSL_CACERT then compare
\r
2415 // the certificates as PEM files.
\r
2417 if (claconncode == CURLE_SSL_CACERT && wxFile::Exists(ServerCertFilename) == TRUE){
\r
2419 //curl_easy_cleanup(conn);
\r
2420 //conn = curl_easy_init();
\r
2423 sslerrconn = curl_easy_init();
\r
2424 CURLcode sslerrconncode;
\r
2426 //claconncode = (curl_easy_perform(conn));
\r
2428 wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
2430 curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));
\r
2431 curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0);
\r
2432 curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
2433 curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60);
\r
2434 curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE);
\r
2435 curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
2436 curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
2437 curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData);
\r
2438 curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader);
\r
2439 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this);
\r
2440 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
2441 curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);
\r
2442 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);
\r
2443 curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);
\r
2445 wxString SSLLocalData;
\r
2446 wxString SSLServerData;
\r
2448 sslerrconncode = (curl_easy_perform(sslerrconn));
\r
2450 SSLCertCol = BuildSSLCollection(sslerrconn);
\r
2451 std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertCol.SSLCollection.find(0);
\r
2452 std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
\r
2454 wxFFile SSLLocalFile;
\r
2456 #if wxABI_VERSION < 20900
\r
2457 SSLLocalFile.Open(ServerCertFilename.c_str(), wxT("r"));
\r
2459 SSLLocalFile.Open(ServerCertFilename, wxT("r"));
\r
2462 // Load the recovery database for tasks not done.
\r
2464 if (SSLLocalFile.IsOpened() == TRUE){
\r
2466 // Check if we are using wxWidgets version 2.8 or less and
\r
2467 // execute the required command accordingly.
\r
2469 SSLLocalFile.ReadAll(&SSLLocalData, wxConvAuto());
\r
2474 SSLServerData = SSLDataIter->second;
\r
2476 if (SSLLocalData == SSLServerData){
\r
2478 // Server key matches with local key so retry with CURLOPT_SSL_VERIFYPEER
\r
2479 // and CURLOPT_SSL_VERIFYHOST off.
\r
2481 curl_easy_cleanup(conn);
\r
2482 conn = curl_easy_init();
\r
2484 PageHeader.clear();
\r
2487 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
2488 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
2489 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
2490 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
2491 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
2492 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
2493 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
2494 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
2495 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
2496 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
2497 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
2498 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
2499 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");
\r
2500 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
2501 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, slist);
\r
2502 curl_easy_setopt(conn, CURLOPT_CERTINFO, 1);
\r
2503 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
2504 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
2505 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0);
\r
2506 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0);
\r
2508 claconncode = (curl_easy_perform(conn));
\r
2510 MatchingCert = TRUE;
\r
2514 if (MatchingCert == FALSE){
\r
2516 claconncode = CURLE_SSL_CACERT;
\r
2517 return ContactListFinal;
\r
2521 curl_easy_cleanup(sslerrconn);
\r
2525 // Sort out SSL error.
\r
2527 // When SSL cert error occurs, connect again and fetch certificates.
\r
2528 // Display a message to the user explaining that an invalid
\r
2529 // certificate has been given and let the user decide what
\r
2532 if (claconncode == CURLE_OK){
\r
2534 } else if (claconncode == CURLE_SSL_CACERT || claconncode == CURLE_PEER_FAILED_VERIFICATION){
\r
2537 sslerrconn = curl_easy_init();
\r
2538 CURLcode sslerrconncode;
\r
2540 wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
2542 // Replace conn with sslerrconn!
\r
2544 curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));
\r
2545 curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0);
\r
2546 curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
2547 curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60);
\r
2548 curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE);
\r
2549 curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
2550 curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
2551 curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData);
\r
2552 curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader);
\r
2553 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this);
\r
2554 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
2555 curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);
\r
2556 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);
\r
2557 curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);
\r
2559 sslerrconncode = (curl_easy_perform(sslerrconn));
\r
2561 SSLCertCol = BuildSSLCollection(sslerrconn);
\r
2562 SSLCertCol.SuccessCode = 1;
\r
2564 return ContactListFinal;
\r
2566 } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){
\r
2568 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
2569 curl_easy_strerror(claconncode));
\r
2570 int http_code = 0;
\r
2571 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
2572 fprintf(stderr, "Error code was: %d\n", http_code);
\r
2574 return ContactListFinal;
\r
2578 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
2579 curl_easy_strerror(claconncode));
\r
2580 int http_code = 0;
\r
2581 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
2582 fprintf(stderr, "Error code was: %d\n", http_code);
\r
2584 return ContactListFinal;
\r
2588 SSLCertCol = BuildSSLCollection(conn);
\r
2594 wxString EmptyString;
\r
2596 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressNormal.mb_str(wxConvUTF8));
\r
2597 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
2598 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
2599 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
2600 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
2601 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
2602 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
2603 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
2604 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
2605 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
2606 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
2607 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
2608 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");
\r
2609 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
2610 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, slist);
\r
2612 //UploadData.readptr = &CardDAVDataQuery;
\r
2613 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
2614 //curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
2615 //curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
2616 //curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
2618 //curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writefunc);
\r
2619 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
2620 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
2623 PageHeader.Clear();
\r
2625 claconncode = (curl_easy_perform(conn));
\r
2627 if (claconncode == CURLE_OK){
\r
2631 } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){
\r
2633 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
2634 curl_easy_strerror(claconncode));
\r
2635 int http_code = 0;
\r
2636 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
2637 fprintf(stderr, "Error code was: %i\n", http_code);
\r
2639 return ContactListFinal;
\r
2643 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
2644 curl_easy_strerror(claconncode));
\r
2645 int http_code = 0;
\r
2646 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
2647 fprintf(stderr, "Error code was: %i\n", http_code);
\r
2649 return ContactListFinal;
\r
2655 xmlDocPtr xmlCardDAVDoc;
\r
2656 xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
\r
2658 xmlNodePtr nodeLevel1;
\r
2659 xmlNodePtr nodeLevel2;
\r
2660 xmlNodePtr nodeLevel3;
\r
2661 xmlNodePtr nodeLevel4;
\r
2662 xmlNodePtr nodeLevel5;
\r
2663 xmlNodePtr nodeLevel6;
\r
2665 xmlNodePtr nodeStatusLv1;
\r
2666 xmlNodePtr nodeStatusLv2;
\r
2668 std::map<wxString,wxString> xmlDataMap;
\r
2669 std::map<wxString,wxString> ServerETagData;
\r
2671 wxString DataFilename;
\r
2672 wxString DataSyncToken;
\r
2673 int DataFileStatus;
\r
2674 wxString ETagData;
\r
2675 bool SyncTokenFound = FALSE;
\r
2677 std::string xmlStringSafe;
\r
2679 // Tranverse through the catacombs of the response to get our ETag for the file and
\r
2680 // the server syncronisation token.
\r
2682 // Start by getting all the server ETag data.
\r
2684 for (nodeLevel1 = xmlCardDAVDoc->children;
\r
2685 nodeLevel1 != NULL;
\r
2686 nodeLevel1 = nodeLevel1->next)
\r
2689 for (nodeLevel2 = nodeLevel1->children;
\r
2690 nodeLevel2 != NULL;
\r
2691 nodeLevel2 = nodeLevel2->next)
\r
2694 for (nodeLevel3 = nodeLevel2->children;
\r
2695 nodeLevel3 != NULL;
\r
2696 nodeLevel3 = nodeLevel3->next)
\r
2699 DataFileStatus = 0;
\r
2700 bool HREFFound = FALSE;
\r
2701 bool ETagFound = FALSE;
\r
2702 bool HTTPStatus = FALSE;
\r
2704 if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"href") ||
\r
2705 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:href") ||
\r
2706 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:href")
\r
2709 // Get the filename.
\r
2711 for (nodeLevel4 = nodeLevel3->children;
\r
2712 nodeLevel4 != NULL;
\r
2713 nodeLevel4 = nodeLevel4->next)
\r
2716 if (!xmlStrcmp(nodeLevel4->name, (const xmlChar *)"text") ||
\r
2717 !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"d:text") ||
\r
2718 !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"D:text")
\r
2721 DataFilename = wxString::FromUTF8((const char*)nodeLevel4->content);
\r
2722 wxStringTokenizer wSTDFilename(DataFilename, wxT("/"));
\r
2724 while (wSTDFilename.HasMoreTokens()){
\r
2726 DataFilename = wSTDFilename.GetNextToken();
\r
2741 for (nodeLevel4 = nodeLevel3->children;
\r
2742 nodeLevel4 != NULL;
\r
2743 nodeLevel4 = nodeLevel4->next)
\r
2746 for (nodeStatusLv1 = nodeLevel3->children;
\r
2747 nodeStatusLv1 != NULL;
\r
2748 nodeStatusLv1 = nodeStatusLv1->next)
\r
2751 if (wxString::FromUTF8((const char*)nodeStatusLv1->content) == wxT("HTTP/1.1 404 Not Found")){
\r
2753 DataFileStatus = 2;
\r
2755 HTTPStatus = TRUE;
\r
2759 if ((!xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"status") ||
\r
2760 !xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"d:status") ||
\r
2761 !xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"D:status")) && HTTPStatus == FALSE)
\r
2764 // Get the filename.
\r
2766 for (nodeStatusLv2 = nodeStatusLv1->children;
\r
2767 nodeStatusLv2 != NULL;
\r
2768 nodeStatusLv2 = nodeStatusLv2->next)
\r
2771 if (!xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"text") ||
\r
2772 !xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"d:text") ||
\r
2773 !xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"D:text")
\r
2776 if (wxString::FromUTF8((const char*)nodeStatusLv2->content) == wxT("HTTP/1.1 200 OK")){
\r
2778 DataFileStatus = 1;
\r
2780 HTTPStatus = TRUE;
\r
2782 // This is currently in a WebDAV draft and may hopefully be enabled when this changes.
\r
2784 //} else if (wxString::FromUTF8((const char*)nodeStatusLv2->content) == wxT("HTTP/1.1 201 Created")){
\r
2786 // DataFileStatus = 0;
\r
2801 for (nodeLevel5 = nodeLevel4->children;
\r
2802 nodeLevel5 != NULL;
\r
2803 nodeLevel5 = nodeLevel5->next)
\r
2806 if (!xmlStrcmp(nodeLevel5->name, (const xmlChar *)"getetag") ||
\r
2807 !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"d:getetag") ||
\r
2808 !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"D:getetag")
\r
2811 for (nodeLevel6 = nodeLevel5->children;
\r
2812 nodeLevel6 != NULL;
\r
2813 nodeLevel6 = nodeLevel6->next)
\r
2816 // Strip the quotes from the ETag.
\r
2818 ETagData = wxString::FromUTF8((const char*)nodeLevel6->content);
\r
2819 if (ETagData.Mid(0, 1) == wxT("\"") && ETagData.Mid((ETagData.Len() - 1), 1) == wxT("\"")){
\r
2821 ETagData.Remove(0, 1);
\r
2822 ETagData.RemoveLast();
\r
2838 if (HREFFound == TRUE && ETagFound == TRUE && HTTPStatus == TRUE){
\r
2840 // Add to the map data.
\r
2842 FileSyncData SData;
\r
2844 SData.ETagData = ETagData;
\r
2845 SData.DataFlag = DataFileStatus;
\r
2847 ContactListFinal.ListData.insert(std::make_pair(DataFilename, SData));
\r
2851 // Reset the values.
\r
2853 HREFFound = FALSE;
\r
2854 ETagFound = FALSE;
\r
2855 HTTPStatus = FALSE;
\r
2859 if ((!xmlStrcmp(nodeLevel2->name, (const xmlChar *)"sync-token") ||
\r
2860 !xmlStrcmp(nodeLevel2->name, (const xmlChar *)"d:sync-token") ||
\r
2861 !xmlStrcmp(nodeLevel2->name, (const xmlChar *)"D:sync-token")) &&
\r
2862 SyncTokenFound == FALSE
\r
2865 for (nodeLevel3 = nodeLevel2->children;
\r
2866 nodeLevel3 != NULL;
\r
2867 nodeLevel3 = nodeLevel3->next)
\r
2870 if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"text") ||
\r
2871 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:text") ||
\r
2872 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:text")
\r
2875 DataSyncToken = wxString::FromUTF8((const char*)nodeLevel3->content);
\r
2877 SyncTokenFound = TRUE;
\r
2889 for (nodeLevel1 = xmlCardDAVDoc->children;
\r
2890 nodeLevel1 != NULL;
\r
2891 nodeLevel1 = nodeLevel1->next)
\r
2894 for (nodeLevel2 = nodeLevel1->children;
\r
2895 nodeLevel2 != NULL;
\r
2896 nodeLevel2 = nodeLevel2->next)
\r
2899 DataFileStatus = 0;
\r
2900 bool HREFFound = FALSE;
\r
2901 bool ETagFound = FALSE;
\r
2902 bool HTTPStatus = FALSE;
\r
2904 for (nodeLevel3 = nodeLevel2->children;
\r
2905 nodeLevel3 != NULL;
\r
2906 nodeLevel3 = nodeLevel3->next)
\r
2909 if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"href") ||
\r
2910 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:href") ||
\r
2911 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:href")
\r
2914 // Get the filename.
\r
2916 for (nodeLevel4 = nodeLevel3->children;
\r
2917 nodeLevel4 != NULL;
\r
2918 nodeLevel4 = nodeLevel4->next)
\r
2921 if (!xmlStrcmp(nodeLevel4->name, (const xmlChar *)"text") ||
\r
2922 !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"d:text") ||
\r
2923 !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"D:text")
\r
2926 DataFilename = wxString::FromUTF8((const char*)nodeLevel4->content);
\r
2927 wxStringTokenizer wSTDFilename(DataFilename, wxT("/"));
\r
2929 while (wSTDFilename.HasMoreTokens()){
\r
2931 DataFilename = wSTDFilename.GetNextToken();
\r
2946 for (nodeLevel4 = nodeLevel3->children;
\r
2947 nodeLevel4 != NULL;
\r
2948 nodeLevel4 = nodeLevel4->next)
\r
2951 for (nodeStatusLv1 = nodeLevel3->children;
\r
2952 nodeStatusLv1 != NULL;
\r
2953 nodeStatusLv1 = nodeStatusLv1->next)
\r
2956 if (wxString::FromUTF8((const char*)nodeStatusLv1->content) == wxT("HTTP/1.1 404 Not Found")){
\r
2958 DataFileStatus = 2;
\r
2960 HTTPStatus = TRUE;
\r
2964 if ((!xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"status") ||
\r
2965 !xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"d:status") ||
\r
2966 !xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"D:status")) && HTTPStatus == FALSE)
\r
2969 // Get the filename.
\r
2971 for (nodeStatusLv2 = nodeStatusLv1->children;
\r
2972 nodeStatusLv2 != NULL;
\r
2973 nodeStatusLv2 = nodeStatusLv2->next)
\r
2976 if (!xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"text") ||
\r
2977 !xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"d:text") ||
\r
2978 !xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"D:text")
\r
2981 if (wxString::FromUTF8((const char*)nodeStatusLv2->content) == wxT("HTTP/1.1 200 OK")){
\r
2983 DataFileStatus = 1;
\r
2985 HTTPStatus = TRUE;
\r
2987 // This is currently in a WebDAV draft and may hopefully be enabled when this changes.
\r
2989 //} else if (wxString::FromUTF8((const char*)nodeStatusLv2->content) == wxT("HTTP/1.1 201 Created")){
\r
2991 // DataFileStatus = 0;
\r
3006 for (nodeLevel5 = nodeLevel4->children;
\r
3007 nodeLevel5 != NULL;
\r
3008 nodeLevel5 = nodeLevel5->next)
\r
3011 if (!xmlStrcmp(nodeLevel5->name, (const xmlChar *)"getetag") ||
\r
3012 !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"d:getetag") ||
\r
3013 !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"D:getetag")
\r
3016 for (nodeLevel6 = nodeLevel5->children;
\r
3017 nodeLevel6 != NULL;
\r
3018 nodeLevel6 = nodeLevel6->next)
\r
3021 // Strip the quotes from the ETag.
\r
3023 ETagData = wxString::FromUTF8((const char*)nodeLevel6->content);
\r
3024 if (ETagData.Mid(0, 1) == wxT("\"") && ETagData.Mid((ETagData.Len() - 1), 1) == wxT("\"")){
\r
3026 ETagData.Remove(0, 1);
\r
3027 ETagData.RemoveLast();
\r
3045 if (HREFFound == TRUE && HTTPStatus == TRUE && DataFileStatus == 2){
\r
3047 FileSyncData SData;
\r
3049 SData.ETagData = wxT("");
\r
3050 SData.DataFlag = DataFileStatus;
\r
3052 ContactListFinal.ListData.insert(std::make_pair(DataFilename, SData));
\r
3056 if (HREFFound == TRUE && ETagFound == TRUE && HTTPStatus == TRUE){
\r
3058 // Add to the map data.
\r
3060 FileSyncData SData;
\r
3062 SData.ETagData = ETagData;
\r
3063 SData.DataFlag = DataFileStatus;
\r
3065 ContactListFinal.ListData.insert(std::make_pair(DataFilename, SData));
\r
3069 // Reset the values.
\r
3071 HREFFound = FALSE;
\r
3072 ETagFound = FALSE;
\r
3073 HTTPStatus = FALSE;
\r
3074 DataFilename.Clear();
\r
3076 if ((!xmlStrcmp(nodeLevel2->name, (const xmlChar *)"sync-token") ||
\r
3077 !xmlStrcmp(nodeLevel2->name, (const xmlChar *)"d:sync-token") ||
\r
3078 !xmlStrcmp(nodeLevel2->name, (const xmlChar *)"D:sync-token")) &&
\r
3079 SyncTokenFound == FALSE
\r
3082 for (nodeLevel3 = nodeLevel2->children;
\r
3083 nodeLevel3 != NULL;
\r
3084 nodeLevel3 = nodeLevel3->next)
\r
3087 if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"text") ||
\r
3088 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:text") ||
\r
3089 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:text")
\r
3092 DataSyncToken = wxString::FromUTF8((const char*)nodeLevel3->content);
\r
3094 SyncTokenFound = TRUE;
\r
3106 // Get the sync token.
\r
3108 if (SyncTokenFound == TRUE){
\r
3110 ContactListFinal.SyncToken = DataSyncToken;
\r
3116 SleepFor(2000000000);
\r
3118 /*timespec n1, n2;
\r
3121 n1.tv_nsec = 2000000000L;
\r
3123 nanosleep(&n1, &n2);*/
\r
3125 xmlFreeDoc(xmlCardDAVDoc);
\r
3126 curl_easy_cleanup(conn);
\r
3128 SyncDataBuffer.reset();
\r
3130 // Get the first result.
\r
3132 return ContactListFinal;
\r
3136 int CardDAV::GetResultCode(){
\r
3138 return (int)claconncode;
\r
3142 int CardDAV::GetHTTPCode(){
\r
3144 return HTTPErrorCode;
\r
3148 wxString CardDAV::GetErrorBuffer(){
\r
3150 wxString ErrorBuffer = wxString::FromUTF8(curlerrbuffer);
\r
3152 return ErrorBuffer;
\r
3156 wxString CardDAV::GetDefaultAddressBookURL(){
\r
3158 // First: Get the principal UID address.
\r
3161 PageHeader.Clear();
\r
3164 AuthPassed = TRUE;
\r
3165 AbortConnection = FALSE;
\r
3168 CURLcode conncode;
\r
3169 wxString ServerAddressURL;
\r
3170 wxString ServerAuth;
\r
3171 wxString ServerAddressSSL;
\r
3172 wxString ServerAddressNormal;
\r
3174 conn = curl_easy_init();
\r
3176 struct curl_slist *connhd = NULL;
\r
3177 struct curl_slist *connhd2 = NULL;
\r
3178 struct curl_slist *connhd3 = NULL;
\r
3180 connhd = curl_slist_append(connhd, "Depth: 0");
\r
3181 connhd = curl_slist_append(connhd, "Prefer: return-minimal");
\r
3182 connhd = curl_slist_append(connhd, "Content-Type: application/xml; charset=utf-8");
\r
3184 connhd2 = curl_slist_append(connhd2, "Depth: 0");
\r
3185 connhd2 = curl_slist_append(connhd2, "Prefer: return-minimal");
\r
3186 connhd2 = curl_slist_append(connhd2, "Content-Type: application/xml; charset=utf-8");
\r
3188 connhd3 = curl_slist_append(connhd3, "Depth: 1");
\r
3189 connhd3 = curl_slist_append(connhd3, "Prefer: return-minimal");
\r
3190 connhd3 = curl_slist_append(connhd3, "Content-Type: application/xml; charset=utf-8");
\r
3192 struct CardDAVCURLPasser {
\r
3195 bool HeaderMode = TRUE;
\r
3197 } CardDAVHeader, CardDAVFooter;
\r
3199 CardDAVHeader.Data = this;
\r
3200 CardDAVHeader.HeaderMode = TRUE;
\r
3202 CardDAVFooter.Data = this;
\r
3203 CardDAVFooter.HeaderMode = FALSE;
\r
3209 wxString ETagOriginal;
\r
3210 wxString ETagServer;
\r
3212 ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
3213 ServerAddressSSL = wxT("https://") + ServerAddressURL;
\r
3214 ServerAddressNormal = wxT("http://") + ServerAddressURL;
\r
3216 ServerAuth = ServerUser + wxT(":") + ServerPass;
\r
3218 wxString SAURLPrincipals;
\r
3219 wxString SAURLPrincipalURL;
\r
3220 wxString SAURLAddressURL;
\r
3224 SAURLPrincipals = ServerAddressSSL + wxT("principals/");
\r
3225 SAURLPrincipalURL = ServerAddressSSL;
\r
3226 SAURLAddressURL = ServerAddressSSL;
\r
3230 SAURLPrincipals = ServerAddressNormal + wxT("principals/");
\r
3231 SAURLPrincipalURL = ServerAddressNormal;
\r
3232 SAURLAddressURL = ServerAddressNormal;
\r
3236 wxString FinalPrefix;
\r
3238 struct UploadDataStruc UploadData;
\r
3240 // Setup the first query finding out where the principal URL is.
\r
3242 const char* query = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
\r
3243 "<D:propfind xmlns:D=\"DAV:\">\n"
\r
3245 " <D:current-user-principal/>\n"
\r
3249 // Setup the second query finding out where the address book home URL is.
\r
3251 const char* query2 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
\r
3252 "<D:propfind xmlns:D=\"DAV:\""
\r
3253 " xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"
\r
3255 " <C:addressbook-home-set/>\n"
\r
3259 // Setup the third query finding out where the default address book URL is.
\r
3261 const char* query3 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
\r
3262 "<D:propfind xmlns:D=\"DAV:\""
\r
3263 " xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"
\r
3265 " <C:default-addressbook-URL/>\n"
\r
3271 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipals.mb_str(wxConvUTF8));
\r
3272 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
3273 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
3274 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
3275 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
3276 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
3277 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
3278 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
3279 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
3280 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
3281 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
3282 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
\r
3283 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
3284 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
3285 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd);
\r
3287 if (AllowSelfSign == TRUE){
\r
3288 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);
\r
3289 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);
\r
3292 conncode = (curl_easy_perform(conn));
\r
3294 if (conncode == CURLE_OK){
\r
3296 *ServerResult = TRUE;
\r
3297 AuthPassed = TRUE;
\r
3298 ValidResponse = TRUE;
\r
3303 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3304 curl_easy_strerror(conncode));
\r
3306 *ServerResult = FALSE;
\r
3308 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
\r
3318 // Do an initial connection (incase of Digest authentication).
\r
3321 PageHeader.Clear();
\r
3323 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipals.mb_str(wxConvUTF8));
\r
3324 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
3325 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
\r
3326 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
3327 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
\r
3328 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
3329 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
3330 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
3331 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
3332 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
3333 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
3334 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
3335 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
3336 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
\r
3337 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
3338 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
3339 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd);
\r
3341 conncode = (curl_easy_perform(conn));
\r
3343 // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG,
\r
3344 // then bring up the conflict resolution form.
\r
3346 if (EditMode == TRUE){
\r
3350 if (conncode == CURLE_OK){
\r
3352 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
\r
3354 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
\r
3356 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3357 curl_easy_strerror(conncode));
\r
3359 fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
\r
3366 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3367 curl_easy_strerror(conncode));
\r
3374 // Process the XML data from the application.
\r
3376 xmlDocPtr xmlCardDAVDoc;
\r
3377 xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
\r
3379 xmlNodePtr nodeLevel1;
\r
3380 xmlNodePtr nodeLevel2;
\r
3381 xmlNodePtr nodeLevel3;
\r
3382 xmlNodePtr nodeLevel4;
\r
3383 xmlNodePtr nodeLevel5;
\r
3384 xmlNodePtr nodeLevel6;
\r
3385 xmlNodePtr nodeLevel7;
\r
3387 for (nodeLevel1 = xmlCardDAVDoc->children;
\r
3388 nodeLevel1 != NULL;
\r
3389 nodeLevel1 = nodeLevel1->next)
\r
3392 for (nodeLevel2 = nodeLevel1->children;
\r
3393 nodeLevel2 != NULL;
\r
3394 nodeLevel2 = nodeLevel2->next)
\r
3398 for (nodeLevel3 = nodeLevel2->children;
\r
3399 nodeLevel3 != NULL;
\r
3400 nodeLevel3 = nodeLevel3->next)
\r
3403 for (nodeLevel4 = nodeLevel3->children;
\r
3404 nodeLevel4 != NULL;
\r
3405 nodeLevel4 = nodeLevel4->next)
\r
3408 for (nodeLevel5 = nodeLevel4->children;
\r
3409 nodeLevel5 != NULL;
\r
3410 nodeLevel5 = nodeLevel5->next)
\r
3413 for (nodeLevel6 = nodeLevel5->children;
\r
3414 nodeLevel6 != NULL;
\r
3415 nodeLevel6 = nodeLevel6->next)
\r
3418 if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") ||
\r
3419 !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") ||
\r
3420 !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href")
\r
3423 // Found the <href> part so extract the principal URL address.
\r
3425 for (nodeLevel7 = nodeLevel6->children;
\r
3426 nodeLevel7 != NULL;
\r
3427 nodeLevel7 = nodeLevel7->next)
\r
3430 SAURLPrincipalURL.Append(wxString::FromUTF8((const char*)nodeLevel7->content));
\r
3448 xmlFreeDoc(xmlCardDAVDoc);
\r
3450 PageHeader.Clear();
\r
3452 // Second: Get the addressbook-home-set
\r
3454 curl_easy_reset(conn);
\r
3458 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipalURL.mb_str(wxConvUTF8));
\r
3459 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
3460 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
\r
3461 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
3462 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
\r
3463 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
3464 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
3465 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
3466 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
3467 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
3468 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
3469 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
\r
3470 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query2);
\r
3471 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query2));
\r
3472 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd2);
\r
3474 if (AllowSelfSign == TRUE){
\r
3475 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);
\r
3476 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);
\r
3479 conncode = (curl_easy_perform(conn));
\r
3481 if (conncode == CURLE_OK){
\r
3483 *ServerResult = TRUE;
\r
3484 AuthPassed = TRUE;
\r
3489 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3490 curl_easy_strerror(conncode));
\r
3492 *ServerResult = FALSE;
\r
3493 ValidResponse = FALSE;
\r
3495 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
\r
3505 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipalURL.mb_str(wxConvUTF8));
\r
3506 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
3507 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
\r
3508 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
3509 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
\r
3510 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
3511 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
3512 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
3513 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
3514 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
3515 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
3516 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
3517 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
3518 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
\r
3519 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query2);
\r
3520 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query2));
\r
3521 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd2);
\r
3523 conncode = (curl_easy_perform(conn));
\r
3525 // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG,
\r
3526 // then bring up the conflict resolution form.
\r
3528 if (EditMode == TRUE){
\r
3532 if (conncode == CURLE_OK){
\r
3534 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
\r
3536 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
\r
3538 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3539 curl_easy_strerror(conncode));
\r
3541 fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
\r
3544 ValidResponse = FALSE;
\r
3550 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3551 curl_easy_strerror(conncode));
\r
3553 ValidResponse = FALSE;
\r
3561 xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
\r
3563 for (nodeLevel1 = xmlCardDAVDoc->children;
\r
3564 nodeLevel1 != NULL;
\r
3565 nodeLevel1 = nodeLevel1->next)
\r
3568 for (nodeLevel2 = nodeLevel1->children;
\r
3569 nodeLevel2 != NULL;
\r
3570 nodeLevel2 = nodeLevel2->next)
\r
3574 for (nodeLevel3 = nodeLevel2->children;
\r
3575 nodeLevel3 != NULL;
\r
3576 nodeLevel3 = nodeLevel3->next)
\r
3579 for (nodeLevel4 = nodeLevel3->children;
\r
3580 nodeLevel4 != NULL;
\r
3581 nodeLevel4 = nodeLevel4->next)
\r
3584 for (nodeLevel5 = nodeLevel4->children;
\r
3585 nodeLevel5 != NULL;
\r
3586 nodeLevel5 = nodeLevel5->next)
\r
3589 for (nodeLevel6 = nodeLevel5->children;
\r
3590 nodeLevel6 != NULL;
\r
3591 nodeLevel6 = nodeLevel6->next)
\r
3594 if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") ||
\r
3595 !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") ||
\r
3596 !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href")
\r
3599 // Found the <href> part so extract the principal URL address.
\r
3601 for (nodeLevel7 = nodeLevel6->children;
\r
3602 nodeLevel7 != NULL;
\r
3603 nodeLevel7 = nodeLevel7->next)
\r
3606 SAURLAddressURL.Append(wxString::FromUTF8((const char*)nodeLevel7->content));
\r
3624 xmlFreeDoc(xmlCardDAVDoc);
\r
3626 PageHeader.Clear();
\r
3628 // Finally: Get the default-addressbook-URL from the addressbook-home-set address.
\r
3630 curl_easy_reset(conn);
\r
3634 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLAddressURL.mb_str(wxConvUTF8));
\r
3635 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
3636 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
\r
3637 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
3638 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
\r
3639 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
3640 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
3641 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
3642 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
3643 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
3644 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
3645 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
\r
3646 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query3);
\r
3647 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query3));
\r
3648 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd3);
\r
3650 if (AllowSelfSign == TRUE){
\r
3651 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);
\r
3652 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);
\r
3655 conncode = (curl_easy_perform(conn));
\r
3657 if (conncode == CURLE_OK){
\r
3659 *ServerResult = TRUE;
\r
3660 AuthPassed = TRUE;
\r
3665 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3666 curl_easy_strerror(conncode));
\r
3668 *ServerResult = FALSE;
\r
3669 ValidResponse = FALSE;
\r
3671 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
\r
3681 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLAddressURL.mb_str(wxConvUTF8));
\r
3682 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
3683 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
\r
3684 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
3685 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
\r
3686 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
3687 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
3688 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
3689 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
3690 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
3691 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
3692 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
3693 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
3694 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
\r
3695 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query3);
\r
3696 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query3));
\r
3697 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd3);
\r
3699 conncode = (curl_easy_perform(conn));
\r
3701 // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG,
\r
3702 // then bring up the conflict resolution form.
\r
3704 if (EditMode == TRUE){
\r
3708 if (conncode == CURLE_OK){
\r
3710 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
\r
3712 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
\r
3714 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3715 curl_easy_strerror(conncode));
\r
3717 fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
\r
3720 ValidResponse = FALSE;
\r
3726 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3727 curl_easy_strerror(conncode));
\r
3729 ValidResponse = FALSE;
\r
3737 xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
\r
3739 for (nodeLevel1 = xmlCardDAVDoc->children;
\r
3740 nodeLevel1 != NULL;
\r
3741 nodeLevel1 = nodeLevel1->next)
\r
3744 for (nodeLevel2 = nodeLevel1->children;
\r
3745 nodeLevel2 != NULL;
\r
3746 nodeLevel2 = nodeLevel2->next)
\r
3750 for (nodeLevel3 = nodeLevel2->children;
\r
3751 nodeLevel3 != NULL;
\r
3752 nodeLevel3 = nodeLevel3->next)
\r
3755 for (nodeLevel4 = nodeLevel3->children;
\r
3756 nodeLevel4 != NULL;
\r
3757 nodeLevel4 = nodeLevel4->next)
\r
3760 for (nodeLevel5 = nodeLevel4->children;
\r
3761 nodeLevel5 != NULL;
\r
3762 nodeLevel5 = nodeLevel5->next)
\r
3765 for (nodeLevel6 = nodeLevel5->children;
\r
3766 nodeLevel6 != NULL;
\r
3767 nodeLevel6 = nodeLevel6->next)
\r
3770 if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") ||
\r
3771 !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") ||
\r
3772 !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href")
\r
3775 // Found the <href> part so extract the principal URL address.
\r
3777 for (nodeLevel7 = nodeLevel6->children;
\r
3778 nodeLevel7 != NULL;
\r
3779 nodeLevel7 = nodeLevel7->next)
\r
3782 FinalPrefix = wxString::FromUTF8((const char*)nodeLevel7->content);
\r
3800 xmlFreeDoc(xmlCardDAVDoc);
\r
3802 PageHeader.Clear();
\r
3804 return FinalPrefix;
\r
3808 SSLCertCollection CardDAV::BuildSSLCollection(CURL *conn){
\r
3810 SSLCertCollection SSLCertInfo;
\r
3812 // Grab the certificate data.
\r
3815 struct curl_slist *certdata;
\r
3816 struct curl_certinfo *certinfo;
\r
3819 certptr.certdata = NULL;
\r
3821 curl_easy_getinfo(conn, CURLINFO_CERTINFO, &certptr.certinfo);
\r
3823 wxString CertPropName;
\r
3824 wxString CertPropValue;
\r
3826 for (int i = 0; i < certptr.certinfo->num_of_certs; i++){
\r
3828 struct curl_slist *slist;
\r
3829 SSLCertData SSLCertDataInc;
\r
3831 for (slist = certptr.certinfo->certinfo[i]; slist; slist = slist->next){
\r
3833 wxStringTokenizer CertDataInc(wxString::FromUTF8(slist->data), ":");
\r
3835 // Get first token as the property name.
\r
3837 CertPropName = CertDataInc.GetNextToken();
\r
3839 // Get remaining tokens as the property value.
\r
3841 while(CertDataInc.HasMoreTokens()){
\r
3843 CertPropValue.Append(CertDataInc.GetNextToken());
\r
3847 SSLCertDataInc.CertData.insert(std::make_pair(CertPropName, CertPropValue));
\r
3848 CertPropName.clear();
\r
3849 CertPropValue.clear();
\r
3853 SSLCertInfo.SSLCollection.insert(std::make_pair(i, SSLCertDataInc));
\r
3857 return SSLCertInfo;
\r
3861 SSLCertCollection CardDAV::GetCertificateData(){
\r
3863 // Pass on the collected certificate data.
\r
3865 return SSLCertCol;
\r
3869 wxString CardDAV::GetErrorMessage(){
\r
3871 return ErrorMessage;
\r