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
82 SSLVerified = FALSE;
\r
84 ValidResponse = FALSE;
\r
85 HasCalDAVSupport = FALSE;
\r
86 SSLCertCol.SuccessCode = 0;
\r
88 AbortConnection = FALSE;
\r
94 CardDAV::~CardDAV(){
\r
98 size_t UploadReadFunc(void *ptr, size_t size, size_t nmemb, void *userdata){
\r
100 struct UploadDataStruc *UploadPtr = (struct UploadDataStruc *)userdata;
\r
102 if (UploadPtr->sizeleft){
\r
104 //MeepMoop->sizeleft--;
\r
107 UploadPtr->sizeleft--;
\r
110 wxSChar = UploadPtr->readptr->Mid(UploadPtr->seek,1);
\r
112 //*(char *)ptr = (char)wxSChar.mb_str();
\r
114 strncpy((char *)ptr, (const char*)wxSChar.mb_str(wxConvUTF8), 1);
\r
126 bool CardDAV::SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL){
\r
128 ServerAddress = SvrAddress;
\r
129 ServerPort = SvrPort;
\r
130 ServerUser = SvrUser;
\r
131 ServerPass = SvrPass;
\r
132 ServerSSL = SvrSSL;
\r
138 bool CardDAV::SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL, wxString SvrPrefix, wxString SvrAccount){
\r
140 ServerAddress = SvrAddress;
\r
141 ServerPort = SvrPort;
\r
142 ServerUser = SvrUser;
\r
143 ServerPass = SvrPass;
\r
144 ServerSSL = SvrSSL;
\r
145 ServerPrefix = SvrPrefix;
\r
146 ServerAccount = SvrAccount;
\r
152 bool CardDAV::SetupResultBools(bool *SvrResult, bool *SvrMonitor){
\r
154 ServerResult = SvrResult;
\r
155 ServerMonitor = SvrMonitor;
\r
161 bool CardDAV::HasValidResponse(){
\r
163 return ValidResponse;
\r
167 bool CardDAV::CanDoCardDAV(){
\r
169 return HasCalDAVSupport;
\r
173 bool CardDAV::CanDoSSL(){
\r
179 bool CardDAV::SSLVerify(){
\r
181 return SSLVerified;
\r
185 bool CardDAV::AbleToLogin(){
\r
193 size_t CardDAV::WritebackFunc(char *ptr, size_t size, size_t nmemb, FILE *stream){
\r
196 Data = wxString::FromUTF8((char *)ptr);
\r
197 if ((bool)stream == TRUE){
\r
198 PageHeader.Append(Data);
\r
200 PageData.Append(Data);
\r
202 return size * nmemb;
\r
208 int CardDAV::ProgressFuncProc(void *clientdata, double TTUp, double NUp, double TTDown, double NDown){
\r
210 if (AbortConnection == TRUE){
\r
222 void CardDAV::Abort(){
\r
224 AbortConnection = TRUE;
\r
228 CURLcode CardDAV::SSLVerifyTest(){
\r
231 PageHeader.Clear();
\r
235 AbortConnection = FALSE;
\r
240 wxString ServerAddressURL;
\r
241 wxString ServerAuth;
\r
242 wxString ServerAddressSSL;
\r
243 wxString ServerAddressNormal;
\r
245 conn = curl_easy_init();
\r
247 /*struct CardDAVCURLPasser {
\r
250 bool HeaderMode = TRUE;
\r
252 } CardDAVHeader, CardDAVFooter;
\r
254 CardDAVHeader.Data = this;
\r
255 CardDAVHeader.HeaderMode = TRUE;
\r
257 CardDAVFooter.Data = this;
\r
258 CardDAVFooter.HeaderMode = FALSE;*/
\r
263 ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
264 ServerAddressSSL = wxT("https://") + ServerAddressURL;
\r
269 struct curl_slist *certdata;
\r
270 struct curl_certinfo *certinfo;
\r
273 ptr.certdata = NULL;
\r
275 // Setup two initial connections and attempt to get the certificate data.
\r
277 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
278 curl_easy_setopt(conn, CURLOPT_CERTINFO, 1);
\r
279 curl_easy_setopt(conn, CURLOPT_VERBOSE, 1L);
\r
280 //curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, FALSE);
\r
281 //curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, FALSE);
\r
282 curl_easy_setopt(conn, CURLOPT_ERRORBUFFER, curlerrbuffer);
\r
283 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
284 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
285 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
287 conncode = (curl_easy_perform(conn));
\r
289 // Check if the SSL certificate is valid or self-signed or some other
\r
292 if (conncode == CURLE_OK){
\r
294 // Connection is OK. Do nothing.
\r
296 *ServerResult = TRUE;
\r
298 } else if (conncode == CURLE_SSL_CACERT || conncode == CURLE_SSL_CONNECT_ERROR){
\r
300 connssldata = curl_easy_init();
\r
302 // Retry but get the certificates without peer/host verification.
\r
304 curl_easy_setopt(connssldata, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
305 curl_easy_setopt(connssldata, CURLOPT_CERTINFO, 1);
\r
306 curl_easy_setopt(connssldata, CURLOPT_VERBOSE, 1L);
\r
307 //curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, FALSE);
\r
308 //curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, FALSE);
\r
309 curl_easy_setopt(connssldata, CURLOPT_ERRORBUFFER, curlerrbuffer);
\r
310 curl_easy_setopt(connssldata, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
311 curl_easy_setopt(connssldata, CURLOPT_WRITEDATA, &PageData);
\r
312 curl_easy_setopt(connssldata, CURLOPT_WRITEHEADER, &PageHeader);
\r
313 //curl_easy_setopt(connssldata, CURLOPT_SSL_VERIFYPEER, FALSE);
\r
314 //curl_easy_setopt(connssldata, CURLOPT_SSL_VERIFYHOST, FALSE);
\r
316 CURLcode certfetchcode;
\r
318 certfetchcode = (curl_easy_perform(connssldata));
\r
320 VerifyCertCollection = BuildSSLCollection(connssldata);
\r
322 if (certfetchcode == CURLE_OK){
\r
324 curl_easy_getinfo(connssldata, CURLINFO_CERTINFO, &ptr.certdata);
\r
326 VerifyCertCollection = BuildSSLCollection(connssldata);
\r
330 conncode = certfetchcode;
\r
334 *ServerResult = FALSE;
\r
338 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
339 curl_easy_strerror(conncode));
\r
341 ErrorMessage = wxString::Format(wxT("%s"), curl_easy_strerror(conncode));
\r
343 *ServerResult = FALSE;
\r
349 curl_easy_cleanup(conn);
\r
355 SSLCertCollection CardDAV::GetSSLVerifyResults(){
\r
356 return VerifyCertCollection;
\r
359 bool CardDAV::Connect(){
\r
362 PageHeader.Clear();
\r
366 AbortConnection = FALSE;
\r
370 wxString ServerAddressURL;
\r
371 wxString ServerAuth;
\r
372 wxString ServerAddressSSL;
\r
373 wxString ServerAddressNormal;
\r
375 conn = curl_easy_init();
\r
377 struct CardDAVCURLPasser {
\r
380 bool HeaderMode = TRUE;
\r
382 } CardDAVHeader, CardDAVFooter;
\r
384 CardDAVHeader.Data = this;
\r
385 CardDAVHeader.HeaderMode = TRUE;
\r
387 CardDAVFooter.Data = this;
\r
388 CardDAVFooter.HeaderMode = FALSE;
\r
393 ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
394 ServerAddressSSL = wxT("https://") + ServerAddressURL;
\r
395 ServerAddressNormal = wxT("http://") + ServerAddressURL;
\r
397 ServerAuth = ServerUser + wxT(":") + ServerPass;
\r
403 char *ServerAdrSSLChar = new char[(ServerAddressSSL.Length() - 1)];
\r
404 //memset(ServerAdrSSLChar, 0, ServerAddressSSL.Length());
\r
405 strncpy(ServerAdrSSLChar, (const char*)ServerAddressSSL.mb_str(wxConvUTF8), (ServerAddressSSL.Length() - 1));
\r
407 char *ServerAdrNorChar = new char[(ServerAddressNormal.Length() - 1)];
\r
408 //memset(ServerAdrNorChar, 0, ServerAddressSSL.Length());
\r
409 strncpy(ServerAdrNorChar, (const char*)ServerAddressNormal.mb_str(wxConvUTF8), (ServerAddressNormal.Length() - 1));
\r
411 char *ServerAuthChar = new char[(ServerAuth.Length() - 1)];
\r
412 //memset(ServerAuthChar, 0, ServerAddressSSL.Length());
\r
413 strncpy(ServerAuthChar, (const char*)ServerAuth.mb_str(wxConvUTF8), (ServerAuth.Length() - 1));
\r
420 struct curl_slist *certdata;
\r
421 struct curl_certinfo *certinfo;
\r
424 ptr.certdata = NULL;
\r
426 // Setup two initial connections and attempt to get the certificate data.
\r
428 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
429 curl_easy_setopt(conn, CURLOPT_CERTINFO, 1);
\r
431 conncode = (curl_easy_perform(conn));
\r
433 // Check if the SSL certificate is valid or self-signed or some other
\r
436 if (conncode == CURLE_OK){
\r
438 // Connection is OK. Do nothing.
\r
440 } else if (conncode == CURLE_SSL_CACERT){
\r
442 // Post message saying SSL certificate is invalid and
\r
445 curl_easy_getinfo(conn, CURLINFO_CERTINFO, &ptr.certdata);
\r
449 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
450 curl_easy_strerror(conncode));
\r
452 ErrorMessage = wxString::Format(wxT("%s"), curl_easy_strerror(conncode));
\r
454 *ServerResult = FALSE;
\r
459 /*curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
460 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
461 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
462 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
463 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
464 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
465 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
466 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
467 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
468 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
469 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
470 curl_easy_setopt(conn, CURLOPT_CERTINFO, 1);
\r
472 conncode = (curl_easy_perform(conn));
\r
475 struct curl_slist *certdata;
\r
476 struct curl_certinfo *certinfo;
\r
479 ptr.certdata = NULL;
\r
481 curl_easy_getinfo(conn, CURLINFO_CERTINFO, &ptr.certdata);
\r
483 if (conncode == CURLE_OK){
\r
485 // Process the server header response and look for
\r
486 // 'addressbook' within the DAV header.
\r
488 wxStringTokenizer wxSHeaderLines(PageHeader, wxT("\r\n"));
\r
489 wxString wxSHeaderLine;
\r
490 std::map<int, wxString> DAVHeaderLines;
\r
492 while (wxSHeaderLines.HasMoreTokens()){
\r
494 wxSHeaderLine = wxSHeaderLines.GetNextToken();
\r
496 if (wxSHeaderLine.Mid(0, 4) == wxT("DAV:")){
\r
498 // Look for address book in the line.
\r
500 if (wxSHeaderLine.Find(wxT("addressbook")) != wxNOT_FOUND){
\r
502 HasCalDAVSupport = TRUE;
\r
510 *ServerResult = TRUE;
\r
515 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
\r
517 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
518 curl_easy_strerror(conncode));
\r
520 ErrorMessage = wxString::Format(wxT("%s"), curl_easy_strerror(conncode));
\r
522 *ServerResult = TRUE;
\r
523 ValidResponse = FALSE;
\r
524 AuthPassed = FALSE;
\r
530 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
531 curl_easy_strerror(conncode));
\r
533 ErrorMessage = wxString::Format(wxT("%s"), curl_easy_strerror(conncode));
\r
535 *ServerResult = FALSE;
\r
544 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressNormal.mb_str(wxConvUTF8));
\r
545 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
546 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
547 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
548 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
549 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
550 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
551 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
552 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
553 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
554 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
556 conncode = (curl_easy_perform(conn));
\r
558 if (conncode == CURLE_OK){
\r
560 // Process the server header response and look for
\r
561 // 'addressbook' within the DAV header.
\r
563 wxStringTokenizer wxSHeaderLines(PageHeader, wxT("\r\n"));
\r
564 wxString wxSHeaderLine;
\r
565 std::map<int, wxString> DAVHeaderLines;
\r
567 while (wxSHeaderLines.HasMoreTokens()){
\r
569 wxSHeaderLine = wxSHeaderLines.GetNextToken();
\r
571 if (wxSHeaderLine.Mid(0, 4) == wxT("DAV:")){
\r
573 // Look for address book in the line.
\r
575 if (wxSHeaderLine.Find(wxT("addressbook")) != wxNOT_FOUND){
\r
577 HasCalDAVSupport = TRUE;
\r
585 *ServerResult = TRUE;
\r
586 ValidResponse = TRUE;
\r
591 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
\r
593 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
594 curl_easy_strerror(conncode));
\r
596 *ServerResult = TRUE;
\r
597 ValidResponse = FALSE;
\r
598 AuthPassed = FALSE;
\r
604 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
605 curl_easy_strerror(conncode));
\r
607 *ServerResult = FALSE;
\r
612 // TODO: Double check and make sure HTTP Authentication is possible.
\r
616 *ServerResult = TRUE;
\r
621 void CardDAV::GetSSLResults(){
\r
627 void CardDAV::ProcessDataThread(){
\r
630 PageHeader.Clear();
\r
634 AbortConnection = FALSE;
\r
638 wxString ServerAddressURL;
\r
639 wxString ServerAuth;
\r
640 wxString ServerAddressSSL;
\r
641 wxString ServerAddressNormal;
\r
643 conn = curl_easy_init();
\r
645 struct CardDAVCURLPasser {
\r
648 bool HeaderMode = TRUE;
\r
650 } CardDAVHeader, CardDAVFooter;
\r
652 CardDAVHeader.Data = this;
\r
653 CardDAVHeader.HeaderMode = TRUE;
\r
655 CardDAVFooter.Data = this;
\r
656 CardDAVFooter.HeaderMode = FALSE;
\r
662 wxString ETagOriginal;
\r
663 wxString ETagServer;
\r
665 ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/") + ServerPrefix + ServerFilenameLocation;
\r
666 ServerAddressSSL = wxT("https://") + ServerAddressURL;
\r
667 ServerAddressNormal = wxT("http://") + ServerAddressURL;
\r
669 ServerAuth = ServerUser + wxT(":") + ServerPass;
\r
675 char *ServerAdrSSLChar = new char[(ServerAddressSSL.Length() - 1)];
\r
676 //memset(ServerAdrSSLChar, 0, ServerAddressSSL.Length());
\r
677 strncpy(ServerAdrSSLChar, (const char*)ServerAddressSSL.mb_str(wxConvUTF8), (ServerAddressSSL.Length() - 1));
\r
679 char *ServerAdrNorChar = new char[(ServerAddressNormal.Length() - 1)];
\r
680 //memset(ServerAdrNorChar, 0, ServerAddressSSL.Length());
\r
681 strncpy(ServerAdrNorChar, (const char*)ServerAddressNormal.mb_str(wxConvUTF8), (ServerAddressNormal.Length() - 1));
\r
683 char *ServerAuthChar = new char[(ServerAuth.Length() - 1)];
\r
684 //memset(ServerAuthChar, 0, ServerAddressSSL.Length());
\r
685 strncpy(ServerAuthChar, (const char*)ServerAuth.mb_str(wxConvUTF8), (ServerAuth.Length() - 1));
\r
689 //std::string WriteDataString = std::string(ServerUploadData.mb_str());
\r
691 std::map<int,int>::iterator ActIter;
\r
692 struct UploadDataStruc UploadData;
\r
695 ActIter = ActivityListPtr->find((int)ItemIndex);
\r
697 // Update result flag.
\r
699 ActIter->second = 1;
\r
701 // Setup the request mode if it is not empty.
\r
703 if (!ServerMethod.IsEmpty()){
\r
705 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, (const char*)ServerMethod.mb_str(wxConvUTF8));
\r
711 wxString ServerCertFilename;
\r
712 bool MatchingCert = FALSE;
\r
714 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
715 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
716 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
717 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
718 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
719 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
720 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
721 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
722 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
723 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
724 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
725 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
726 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
728 if (UploadMode == TRUE){
\r
730 UploadData.readptr = &ServerUploadData;
\r
731 UploadData.sizeleft = ServerUploadData.Len();
\r
732 curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
733 curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
734 curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
738 ServerCertFilename = GetAccountDir(ServerAccount, TRUE);
\r
740 if (wxFile::Exists(ServerCertFilename) == TRUE){
\r
742 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 1);
\r
743 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 2);
\r
744 curl_easy_setopt(conn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8));
\r
748 //UploadData.readptr = &CardDAVDataQuery;
\r
749 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
750 //curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
751 //curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
752 //curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
754 //curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writefunc);
\r
756 claconncode = (curl_easy_perform(conn));
\r
758 // If CURLE_PEER_FAILED_VERIFICATION is returned, retry without
\r
759 // the local certificate in use.
\r
761 if (claconncode == CURLE_PEER_FAILED_VERIFICATION){
\r
763 curl_easy_cleanup(conn);
\r
764 conn = curl_easy_init();
\r
766 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
767 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
768 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
769 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
770 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
771 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
772 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
773 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
774 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
775 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
776 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
777 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
778 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
780 if (UploadMode == TRUE){
\r
782 UploadData.readptr = &ServerUploadData;
\r
783 UploadData.sizeleft = ServerUploadData.Len();
\r
784 curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
785 curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
786 curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
790 claconncode = (curl_easy_perform(conn));
\r
792 // If claconncode is CURLE_OK then delete the certificate file as that
\r
793 // is no longer needed.
\r
795 if (claconncode == CURLE_OK){
\r
797 // Delete the certificate file.
\r
799 wxRemoveFile(ServerCertFilename);
\r
805 // Check if it fails with a CURLE_SSL_CACERT then compare
\r
806 // the certificates as PEM files.
\r
808 if (claconncode == CURLE_SSL_CACERT && wxFile::Exists(ServerCertFilename) == TRUE){
\r
810 //curl_easy_cleanup(conn);
\r
811 //conn = curl_easy_init();
\r
814 sslerrconn = curl_easy_init();
\r
815 CURLcode sslerrconncode;
\r
817 //claconncode = (curl_easy_perform(conn));
\r
819 wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
821 curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));
\r
822 curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0);
\r
823 curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
824 curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60);
\r
825 curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE);
\r
826 curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
827 curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
828 curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData);
\r
829 curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader);
\r
830 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this);
\r
831 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
832 curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);
\r
833 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);
\r
834 curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);
\r
836 wxString SSLLocalData;
\r
837 wxString SSLServerData;
\r
839 sslerrconncode = (curl_easy_perform(sslerrconn));
\r
841 SSLCertCol = BuildSSLCollection(sslerrconn);
\r
842 std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertCol.SSLCollection.find(0);
\r
843 std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
\r
845 wxFFile SSLLocalFile;
\r
847 #if wxABI_VERSION < 20900
\r
848 SSLLocalFile.Open(ServerCertFilename.c_str(), wxT("r"));
\r
850 SSLLocalFile.Open(ServerCertFilename, wxT("r"));
\r
853 // Load the recovery database for tasks not done.
\r
855 if (SSLLocalFile.IsOpened() == TRUE){
\r
857 // Check if we are using wxWidgets version 2.8 or less and
\r
858 // execute the required command accordingly.
\r
860 SSLLocalFile.ReadAll(&SSLLocalData, wxConvAuto());
\r
865 SSLServerData = SSLDataIter->second;
\r
867 if (SSLLocalData == SSLServerData){
\r
869 // Server key matches with local key so retry with CURLOPT_SSL_VERIFYPEER
\r
870 // and CURLOPT_SSL_VERIFYHOST off.
\r
872 curl_easy_cleanup(conn);
\r
873 conn = curl_easy_init();
\r
876 PageHeader.clear();
\r
878 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
879 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
880 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
881 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
882 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
883 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
884 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
885 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
886 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
887 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
888 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
889 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
890 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
892 if (UploadMode == TRUE){
\r
894 UploadData.readptr = &ServerUploadData;
\r
895 UploadData.sizeleft = ServerUploadData.Len();
\r
896 curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
897 curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
898 curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
902 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0);
\r
903 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0);
\r
905 claconncode = (curl_easy_perform(conn));
\r
907 MatchingCert = TRUE;
\r
911 if (MatchingCert == FALSE){
\r
913 claconncode = CURLE_SSL_CACERT;
\r
918 curl_easy_cleanup(sslerrconn);
\r
922 // Sort out SSL error.
\r
924 // When SSL cert error occurs, connect again and fetch certificates.
\r
925 // Display a message to the user explaining that an invalid
\r
926 // certificate has been given and let the user decide what
\r
929 if (claconncode == CURLE_OK){
\r
931 } else if (claconncode == CURLE_SSL_CACERT || claconncode == CURLE_PEER_FAILED_VERIFICATION){
\r
934 sslerrconn = curl_easy_init();
\r
935 CURLcode sslerrconncode;
\r
937 wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
939 // Replace conn with sslerrconn!
\r
941 curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));
\r
942 curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0);
\r
943 curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
944 curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60);
\r
945 curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE);
\r
946 curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
947 curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
948 curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData);
\r
949 curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader);
\r
950 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this);
\r
951 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
952 curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);
\r
953 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);
\r
954 curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);
\r
956 sslerrconncode = (curl_easy_perform(sslerrconn));
\r
958 SSLCertCol = BuildSSLCollection(sslerrconn);
\r
959 SSLCertCol.SuccessCode = 1;
\r
963 } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){
\r
965 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
966 curl_easy_strerror(claconncode));
\r
968 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
969 fprintf(stderr, "Error code was: %d\n", http_code);
\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
989 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressNormal.mb_str(wxConvUTF8));
\r
990 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
991 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
992 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
993 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
994 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
995 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
996 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
997 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
998 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
999 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
1000 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
1001 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1003 if (UploadMode == TRUE){
\r
1005 UploadData.readptr = &ServerUploadData;
\r
1006 UploadData.sizeleft = ServerUploadData.Len();
\r
1007 curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
1008 curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
1009 curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
1013 conncode = (curl_easy_perform(conn));
\r
1015 if (conncode == CURLE_OK){
\r
1017 // Process the server header response and look for
\r
1018 // 'addressbook' within the DAV header.
\r
1020 wxStringTokenizer wxSHeaderLines(PageHeader, wxT("\r\n"));
\r
1021 wxString wxSHeaderLine;
\r
1022 std::map<int, wxString> DAVHeaderLines;
\r
1024 while (wxSHeaderLines.HasMoreTokens()){
\r
1026 wxSHeaderLine = wxSHeaderLines.GetNextToken();
\r
1028 if (wxSHeaderLine.Mid(0, 5) == wxT("ETag:")){
\r
1030 ETagData = wxSHeaderLine.Mid(5);
\r
1032 ETagData.Trim(FALSE);
\r
1034 // Check for commas.
\r
1036 if (ETagData.Mid(0, 1) == wxT("\"") && ETagData.Mid((ETagData.Len() - 1), 1) == wxT("\"")){
\r
1038 ETagData.Remove(0, 1);
\r
1039 ETagData.RemoveLast();
\r
1045 if (wxSHeaderLine.Mid(0, 4) == wxT("DAV:")){
\r
1047 // Look for address book in the line.
\r
1049 if (wxSHeaderLine.Find(wxT("addressbook")) != wxNOT_FOUND){
\r
1051 HasCalDAVSupport = TRUE;
\r
1059 // Get the ETag from the header.
\r
1061 if (UploadMode == TRUE){
\r
1063 wxString PageHeaderLine;
\r
1065 wxStringTokenizer PageHeaderSplit(PageHeader, wxT("\r\n"));
\r
1067 if (PageHeaderSplit.HasMoreTokens()){
\r
1069 PageHeaderLine = PageHeaderSplit.GetNextToken();
\r
1075 ActIter->second = 4;
\r
1078 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
\r
1080 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
\r
1082 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1083 curl_easy_strerror(conncode));
\r
1085 fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
\r
1088 ActIter->second = 2;
\r
1093 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1094 curl_easy_strerror(conncode));
\r
1096 ActIter->second = 2;
\r
1109 // Connection was successful
\r
1114 wxString ServerAddressURL;
\r
1116 // Try secure connection first.
\r
1121 ServerAddressURL = wxT("http://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
1123 ServerAddressURL.Trim();
\r
1125 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressURL.mb_str(wxConvUTF8));
\r
1126 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1127 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, NULL);
\r
1128 curl_easy_setopt(conn, CURLOPT_WRITEDATA, NULL);
\r
1131 conncode = (curl_easy_perform(conn));
\r
1133 if (conncode == CURLE_OK){
\r
1134 *ServerResult = TRUE;
\r
1139 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1140 curl_easy_strerror(conncode));
\r
1142 *ServerResult = FALSE;
\r
1146 // Failed. So use unsecure connection.
\r
1149 ServerAddress = wxT("http://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort);
\r
1151 curl_easy_setopt(conn, CURLOPT_URL, ServerAddress.c_str());
\r
1153 conncode = (curl_easy_perform(conn));
\r
1155 if (conncode != CURLE_OK){
\r
1156 *ServerResult = FALSE;
\r
1159 *ServerResult = TRUE;
\r
1165 *ServerResult = FALSE;
\r
1174 ActIter->second = 1;
\r
1175 *ServerResult = TRUE;
\r
1180 void CardDAV::ProcessData(){
\r
1182 std::thread ConnectThread(&CardDAV::ProcessDataThread, this);
\r
1183 ConnectThread.detach();
\r
1187 void CardDAV::SetServerFilename(wxString Filename){
\r
1189 ServerFilenameLocation = Filename;
\r
1193 void CardDAV::GetServerContactData()
\r
1197 PageHeader.Clear();
\r
1200 AuthPassed = TRUE;
\r
1201 AbortConnection = FALSE;
\r
1203 wxString ServerCertFilename;
\r
1204 bool MatchingCert = FALSE;
\r
1207 CURLcode conncode;
\r
1208 wxString ServerAddressURL;
\r
1209 wxString ServerAuth;
\r
1210 wxString ServerAddressSSL;
\r
1211 wxString ServerAddressNormal;
\r
1213 conn = curl_easy_init();
\r
1215 struct CardDAVCURLPasser {
\r
1218 bool HeaderMode = TRUE;
\r
1220 } CardDAVHeader, CardDAVFooter;
\r
1222 CardDAVHeader.Data = this;
\r
1223 CardDAVHeader.HeaderMode = TRUE;
\r
1225 CardDAVFooter.Data = this;
\r
1226 CardDAVFooter.HeaderMode = FALSE;
\r
1231 ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/") + ServerPrefix + ServerFilenameLocation;
\r
1232 ServerAddressSSL = wxT("https://") + ServerAddressURL;
\r
1233 ServerAddressNormal = wxT("http://") + ServerAddressURL;
\r
1235 ServerAuth = ServerUser + wxT(":") + ServerPass;
\r
1241 char *ServerAdrSSLChar = new char[(ServerAddressSSL.Length() - 1)];
\r
1242 //memset(ServerAdrSSLChar, 0, ServerAddressSSL.Length());
\r
1243 strncpy(ServerAdrSSLChar, (const char*)ServerAddressSSL.mb_str(wxConvUTF8), (ServerAddressSSL.Length() - 1));
\r
1245 char *ServerAdrNorChar = new char[(ServerAddressNormal.Length() - 1)];
\r
1246 //memset(ServerAdrNorChar, 0, ServerAddressSSL.Length());
\r
1247 strncpy(ServerAdrNorChar, (const char*)ServerAddressNormal.mb_str(wxConvUTF8), (ServerAddressNormal.Length() - 1));
\r
1249 char *ServerAuthChar = new char[(ServerAuth.Length() - 1)];
\r
1250 //memset(ServerAuthChar, 0, ServerAddressSSL.Length());
\r
1251 strncpy(ServerAuthChar, (const char*)ServerAuth.mb_str(wxConvUTF8), (ServerAuth.Length() - 1));
\r
1255 //std::string WriteDataString = std::string(ServerUploadData.mb_str());
\r
1257 std::map<int,int>::iterator ActIter;
\r
1258 struct UploadDataStruc UploadData;
\r
1261 ActIter = ActivityListPtr->find((int)ItemIndex);
\r
1263 //ActIter->second = 1;
\r
1265 /*wxString CardDAVDataQuery = wxT("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n");
\r
1266 CardDAVDataQuery.Append(wxT("<C:addressbook-multiget xmlns:D=\"DAV:\"\r\n"));
\r
1267 CardDAVDataQuery.Append(wxT(" xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\r\n"));
\r
1268 CardDAVDataQuery.Append(wxT("<D:prop><D:getetag/>\r\n"));
\r
1269 CardDAVDataQuery.Append(wxT("<C:address-data>\r\n"));
\r
1270 CardDAVDataQuery.Append(wxT(" <C:allprop/>\r\n"));
\r
1271 CardDAVDataQuery.Append(wxT("</C:address-data></D:prop>\r\n"));
\r
1272 CardDAVDataQuery.Append(wxT("</C:addressbook-multiget>"));*/
\r
1276 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
1277 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
1278 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1279 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1280 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1281 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1282 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1283 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1284 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1285 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1286 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1288 //UploadData.readptr = &CardDAVDataQuery;
\r
1289 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
1290 //curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
1291 //curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
1292 //curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
1294 ServerCertFilename = GetAccountDir(ServerAccount, TRUE);
\r
1296 if (wxFile::Exists(ServerCertFilename) == TRUE){
\r
1298 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 1);
\r
1299 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 2);
\r
1300 curl_easy_setopt(conn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8));
\r
1304 claconncode = (curl_easy_perform(conn));
\r
1306 // If CURLE_PEER_FAILED_VERIFICATION is returned, retry without
\r
1307 // the local certificate in use.
\r
1309 if (claconncode == CURLE_PEER_FAILED_VERIFICATION){
\r
1311 curl_easy_cleanup(conn);
\r
1312 conn = curl_easy_init();
\r
1314 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
1315 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
1316 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1317 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1318 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1319 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1320 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1321 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1322 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1323 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1324 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1326 //UploadData.readptr = &CardDAVDataQuery;
\r
1327 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
1329 claconncode = (curl_easy_perform(conn));
\r
1331 // If claconncode is CURLE_OK then delete the certificate file as that
\r
1332 // is no longer needed.
\r
1334 if (claconncode == CURLE_OK){
\r
1336 // Delete the certificate file.
\r
1338 wxRemoveFile(ServerCertFilename);
\r
1344 // Check if it fails with a CURLE_SSL_CACERT then compare
\r
1345 // the certificates as PEM files.
\r
1347 if (claconncode == CURLE_SSL_CACERT && wxFile::Exists(ServerCertFilename) == TRUE){
\r
1349 //curl_easy_cleanup(conn);
\r
1350 //conn = curl_easy_init();
\r
1353 sslerrconn = curl_easy_init();
\r
1354 CURLcode sslerrconncode;
\r
1356 //claconncode = (curl_easy_perform(conn));
\r
1358 wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
1360 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
1361 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
1362 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1363 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1364 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1365 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1366 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1367 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1368 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1369 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1370 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1372 //UploadData.readptr = &CardDAVDataQuery;
\r
1373 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
1374 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);
\r
1375 curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);
\r
1377 wxString SSLLocalData;
\r
1378 wxString SSLServerData;
\r
1380 sslerrconncode = (curl_easy_perform(sslerrconn));
\r
1382 SSLCertCol = BuildSSLCollection(sslerrconn);
\r
1383 std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertCol.SSLCollection.find(0);
\r
1384 std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
\r
1386 wxFFile SSLLocalFile;
\r
1388 #if wxABI_VERSION < 20900
\r
1389 SSLLocalFile.Open(ServerCertFilename.c_str(), wxT("r"));
\r
1391 SSLLocalFile.Open(ServerCertFilename, wxT("r"));
\r
1394 // Load the recovery database for tasks not done.
\r
1396 if (SSLLocalFile.IsOpened() == TRUE){
\r
1398 // Check if we are using wxWidgets version 2.8 or less and
\r
1399 // execute the required command accordingly.
\r
1401 SSLLocalFile.ReadAll(&SSLLocalData, wxConvAuto());
\r
1406 SSLServerData = SSLDataIter->second;
\r
1408 if (SSLLocalData == SSLServerData){
\r
1410 // Server key matches with local key so retry with CURLOPT_SSL_VERIFYPEER
\r
1411 // and CURLOPT_SSL_VERIFYHOST off.
\r
1413 curl_easy_cleanup(conn);
\r
1414 conn = curl_easy_init();
\r
1417 PageHeader.clear();
\r
1419 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
1420 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
1421 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1422 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1423 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1424 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1425 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1426 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1427 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1428 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1429 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1431 //UploadData.readptr = &CardDAVDataQuery;
\r
1432 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
1433 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0);
\r
1434 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0);
\r
1436 claconncode = (curl_easy_perform(conn));
\r
1438 MatchingCert = TRUE;
\r
1442 if (MatchingCert == FALSE){
\r
1444 claconncode = CURLE_SSL_CACERT;
\r
1449 curl_easy_cleanup(sslerrconn);
\r
1453 // Sort out SSL error.
\r
1455 // When SSL cert error occurs, connect again and fetch certificates.
\r
1456 // Display a message to the user explaining that an invalid
\r
1457 // certificate has been given and let the user decide what
\r
1460 if (claconncode == CURLE_OK){
\r
1462 } else if (claconncode == CURLE_SSL_CACERT || claconncode == CURLE_PEER_FAILED_VERIFICATION){
\r
1465 sslerrconn = curl_easy_init();
\r
1466 CURLcode sslerrconncode;
\r
1468 wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
1470 // Replace conn with sslerrconn!
\r
1472 curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));
\r
1473 curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0);
\r
1474 curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1475 curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60);
\r
1476 curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE);
\r
1477 curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1478 curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1479 curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData);
\r
1480 curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1481 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this);
\r
1482 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
1483 curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);
\r
1484 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);
\r
1485 curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);
\r
1487 sslerrconncode = (curl_easy_perform(sslerrconn));
\r
1489 SSLCertCol = BuildSSLCollection(sslerrconn);
\r
1490 SSLCertCol.SuccessCode = 1;
\r
1494 } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){
\r
1496 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1497 curl_easy_strerror(claconncode));
\r
1498 int http_code = 0;
\r
1499 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
1500 fprintf(stderr, "Error code was: %d\n", http_code);
\r
1506 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1507 curl_easy_strerror(claconncode));
\r
1508 int http_code = 0;
\r
1509 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
1510 fprintf(stderr, "Error code was: %d\n", http_code);
\r
1519 wxString EmptyString;
\r
1521 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressNormal.mb_str(wxConvUTF8));
\r
1522 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
1523 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1524 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1525 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1526 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1527 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1528 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1529 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1530 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1531 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1533 //UploadData.readptr = &CardDAVDataQuery;
\r
1534 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
1535 //curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
1536 //curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
1537 //curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
1539 //UploadData.readptr = &CardDAVDataQuery;
\r
1540 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
1541 //curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
1542 //curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
1543 //curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
1545 //curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writefunc);
\r
1548 PageHeader.Clear();
\r
1550 conncode = (curl_easy_perform(conn));
\r
1552 if (conncode == CURLE_OK){
\r
1554 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
\r
1556 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1557 curl_easy_strerror(conncode));
\r
1559 fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
\r
1566 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1567 curl_easy_strerror(conncode));
\r
1579 wxString CardDAV::GetPageData()
\r
1586 void CardDAV::GetServerETagValueThread()
\r
1590 PageHeader.Clear();
\r
1593 AuthPassed = TRUE;
\r
1594 AbortConnection = FALSE;
\r
1597 CURLcode conncode;
\r
1598 wxString ServerAddressURL;
\r
1599 wxString ServerAuth;
\r
1600 wxString ServerAddressSSL;
\r
1601 wxString ServerAddressNormal;
\r
1603 conn = curl_easy_init();
\r
1605 struct CardDAVCURLPasser {
\r
1608 bool HeaderMode = TRUE;
\r
1610 } CardDAVHeader, CardDAVFooter;
\r
1612 CardDAVHeader.Data = this;
\r
1613 CardDAVHeader.HeaderMode = TRUE;
\r
1615 CardDAVFooter.Data = this;
\r
1616 CardDAVFooter.HeaderMode = FALSE;
\r
1621 ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/") + ServerPrefix + ServerFilenameLocation;
\r
1622 ServerAddressSSL = wxT("https://") + ServerAddressURL;
\r
1623 ServerAddressNormal = wxT("http://") + ServerAddressURL;
\r
1625 ServerAuth = ServerUser + wxT(":") + ServerPass;
\r
1631 char *ServerAdrSSLChar = new char[(ServerAddressSSL.Length() - 1)];
\r
1632 //memset(ServerAdrSSLChar, 0, ServerAddressSSL.Length());
\r
1633 strncpy(ServerAdrSSLChar, (const char*)ServerAddressSSL.mb_str(wxConvUTF8), (ServerAddressSSL.Length() - 1));
\r
1635 char *ServerAdrNorChar = new char[(ServerAddressNormal.Length() - 1)];
\r
1636 //memset(ServerAdrNorChar, 0, ServerAddressSSL.Length());
\r
1637 strncpy(ServerAdrNorChar, (const char*)ServerAddressNormal.mb_str(wxConvUTF8), (ServerAddressNormal.Length() - 1));
\r
1639 char *ServerAuthChar = new char[(ServerAuth.Length() - 1)];
\r
1640 //memset(ServerAuthChar, 0, ServerAddressSSL.Length());
\r
1641 strncpy(ServerAuthChar, (const char*)ServerAuth.mb_str(wxConvUTF8), (ServerAuth.Length() - 1));
\r
1645 //std::string WriteDataString = std::string(ServerUploadData.mb_str());
\r
1647 std::map<int,int>::iterator ActIter;
\r
1648 struct UploadDataStruc UploadData;
\r
1651 ActIter = ActivityListPtr->find((int)ItemIndex);
\r
1653 static const char* query =
\r
1654 "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
\r
1655 "<C:addressbook-query xmlns:D=\"DAV:\""
\r
1656 " xmlns:C=\"urn:ietf:params:xml:ns:carddav\">"
\r
1657 "<D:prop><D:getetag/>"
\r
1658 //"<C:address-data>"
\r
1660 //"</C:address-data></D:prop>"
\r
1663 "</C:addressbook-query>";
\r
1667 wxString ServerCertFilename;
\r
1668 bool MatchingCert = FALSE;
\r
1670 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
1671 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
1672 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1673 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1674 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1675 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1676 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1677 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1678 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1679 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1680 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
1681 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
1682 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");
\r
1683 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1685 //UploadData.readptr = &CardDAVDataQuery;
\r
1686 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
1687 //curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
1688 //curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
1689 //curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
1691 //curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writefunc);
\r
1692 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
1693 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
1695 ServerCertFilename = GetAccountDir(ServerAccount, TRUE);
\r
1697 if (wxFile::Exists(ServerCertFilename) == TRUE){
\r
1699 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 1);
\r
1700 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 2);
\r
1701 curl_easy_setopt(conn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8));
\r
1705 claconncode = (curl_easy_perform(conn));
\r
1707 // If CURLE_PEER_FAILED_VERIFICATION is returned, retry without
\r
1708 // the local certificate in use.
\r
1710 if (claconncode == CURLE_PEER_FAILED_VERIFICATION){
\r
1712 curl_easy_cleanup(conn);
\r
1713 conn = curl_easy_init();
\r
1715 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
1716 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
1717 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1718 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1719 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1720 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1721 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1722 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1723 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1724 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1725 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
1726 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
1727 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");
\r
1728 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1729 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
1730 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
1732 claconncode = (curl_easy_perform(conn));
\r
1734 // If claconncode is CURLE_OK then delete the certificate file as that
\r
1735 // is no longer needed.
\r
1737 if (claconncode == CURLE_OK){
\r
1739 // Delete the certificate file.
\r
1741 wxRemoveFile(ServerCertFilename);
\r
1747 // Check if it fails with a CURLE_SSL_CACERT then compare
\r
1748 // the certificates as PEM files.
\r
1750 if (claconncode == CURLE_SSL_CACERT && wxFile::Exists(ServerCertFilename) == TRUE){
\r
1752 //curl_easy_cleanup(conn);
\r
1753 //conn = curl_easy_init();
\r
1756 sslerrconn = curl_easy_init();
\r
1757 CURLcode sslerrconncode;
\r
1759 //claconncode = (curl_easy_perform(conn));
\r
1761 wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
1763 curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));
\r
1764 curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0);
\r
1765 curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1766 curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60);
\r
1767 curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE);
\r
1768 curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1769 curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1770 curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData);
\r
1771 curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1772 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this);
\r
1773 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
1774 curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);
\r
1775 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);
\r
1776 curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);
\r
1778 wxString SSLLocalData;
\r
1779 wxString SSLServerData;
\r
1781 sslerrconncode = (curl_easy_perform(sslerrconn));
\r
1783 SSLCertCol = BuildSSLCollection(sslerrconn);
\r
1784 std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertCol.SSLCollection.find(0);
\r
1785 std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
\r
1787 wxFFile SSLLocalFile;
\r
1789 #if wxABI_VERSION < 20900
\r
1790 SSLLocalFile.Open(ServerCertFilename.c_str(), wxT("r"));
\r
1792 SSLLocalFile.Open(ServerCertFilename, wxT("r"));
\r
1795 // Load the recovery database for tasks not done.
\r
1797 if (SSLLocalFile.IsOpened() == TRUE){
\r
1799 // Check if we are using wxWidgets version 2.8 or less and
\r
1800 // execute the required command accordingly.
\r
1802 SSLLocalFile.ReadAll(&SSLLocalData, wxConvAuto());
\r
1807 SSLServerData = SSLDataIter->second;
\r
1809 if (SSLLocalData == SSLServerData){
\r
1811 // Server key matches with local key so retry with CURLOPT_SSL_VERIFYPEER
\r
1812 // and CURLOPT_SSL_VERIFYHOST off.
\r
1814 curl_easy_cleanup(conn);
\r
1815 conn = curl_easy_init();
\r
1818 PageHeader.clear();
\r
1820 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
1821 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
1822 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1823 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1824 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1825 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1826 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1827 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1828 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1829 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1830 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
1831 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
1832 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");
\r
1833 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1834 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
1835 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
1837 claconncode = (curl_easy_perform(conn));
\r
1839 MatchingCert = TRUE;
\r
1843 if (MatchingCert == FALSE){
\r
1845 claconncode = CURLE_SSL_CACERT;
\r
1850 curl_easy_cleanup(sslerrconn);
\r
1856 // Sort out SSL error.
\r
1858 // When SSL cert error occurs, connect again and fetch certificates.
\r
1859 // Display a message to the user explaining that an invalid
\r
1860 // certificate has been given and let the user decide what
\r
1863 if (claconncode == CURLE_OK){
\r
1865 } else if (claconncode == CURLE_SSL_CACERT || claconncode == CURLE_PEER_FAILED_VERIFICATION){
\r
1868 sslerrconn = curl_easy_init();
\r
1869 CURLcode sslerrconncode;
\r
1871 wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
1873 // Replace conn with sslerrconn!
\r
1875 curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));
\r
1876 curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0);
\r
1877 curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1878 curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60);
\r
1879 curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE);
\r
1880 curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1881 curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1882 curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData);
\r
1883 curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1884 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this);
\r
1885 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
1886 curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);
\r
1887 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);
\r
1888 curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);
\r
1890 sslerrconncode = (curl_easy_perform(sslerrconn));
\r
1892 SSLCertCol = BuildSSLCollection(sslerrconn);
\r
1893 SSLCertCol.SuccessCode = 1;
\r
1897 } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){
\r
1899 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1900 curl_easy_strerror(claconncode));
\r
1901 int http_code = 0;
\r
1902 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
1903 fprintf(stderr, "Error code was: %d\n", http_code);
\r
1909 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1910 curl_easy_strerror(claconncode));
\r
1911 int http_code = 0;
\r
1912 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
1913 fprintf(stderr, "Error code was: %d\n", http_code);
\r
1923 wxString EmptyString;
\r
1925 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressNormal.mb_str(wxConvUTF8));
\r
1926 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
1927 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
1928 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
1929 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
1930 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
1931 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
1932 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
1933 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
1934 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
1935 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
1936 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
1937 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");
\r
1938 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
1940 //UploadData.readptr = &CardDAVDataQuery;
\r
1941 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
1942 //curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
1943 //curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
1944 //curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
1946 //curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writefunc);
\r
1947 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
1948 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
1951 PageHeader.Clear();
\r
1953 conncode = (curl_easy_perform(conn));
\r
1955 if (conncode == CURLE_OK){
\r
1957 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
\r
1959 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1960 curl_easy_strerror(conncode));
\r
1966 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
1967 curl_easy_strerror(conncode));
\r
1975 xmlDocPtr xmlCardDAVDoc;
\r
1977 xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
\r
1979 xmlNodePtr nodeLevel1;
\r
1980 xmlNodePtr nodeLevel2;
\r
1981 xmlNodePtr nodeLevel3;
\r
1982 xmlNodePtr nodeLevel4;
\r
1983 xmlNodePtr nodeLevel5;
\r
1984 xmlNodePtr nodeLevel6;
\r
1986 std::map<wxString,wxString> xmlDataMap;
\r
1988 wxString DataFilename;
\r
1989 wxString ETagData;
\r
1991 std::string xmlStringSafe;
\r
1993 // Tranverse through the catacombs of the response to get our ETag for the file.
\r
1995 for (nodeLevel1 = xmlCardDAVDoc->children;
\r
1996 nodeLevel1 != NULL;
\r
1997 nodeLevel1 = nodeLevel1->next)
\r
2000 for (nodeLevel2 = nodeLevel1->children;
\r
2001 nodeLevel2 != NULL;
\r
2002 nodeLevel2 = nodeLevel2->next)
\r
2005 for (nodeLevel3 = nodeLevel2->children;
\r
2006 nodeLevel3 != NULL;
\r
2007 nodeLevel3 = nodeLevel3->next)
\r
2010 bool HREFFound = FALSE;
\r
2011 bool ETagFound = FALSE;
\r
2013 if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"href") ||
\r
2014 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:href") ||
\r
2015 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:href")
\r
2018 // Get the filename.
\r
2020 for (nodeLevel4 = nodeLevel3->children;
\r
2021 nodeLevel4 != NULL;
\r
2022 nodeLevel4 = nodeLevel4->next)
\r
2025 if (!xmlStrcmp(nodeLevel4->name, (const xmlChar *)"text") ||
\r
2026 !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"d:text") ||
\r
2027 !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"D:text")
\r
2030 DataFilename = wxString::FromUTF8((const char*)nodeLevel4->content);
\r
2031 wxStringTokenizer wSTDFilename(DataFilename, wxT("/"));
\r
2033 while (wSTDFilename.HasMoreTokens()){
\r
2035 DataFilename = wSTDFilename.GetNextToken();
\r
2049 for (nodeLevel4 = nodeLevel3->children;
\r
2050 nodeLevel4 != NULL;
\r
2051 nodeLevel4 = nodeLevel4->next)
\r
2054 for (nodeLevel5 = nodeLevel4->children;
\r
2055 nodeLevel5 != NULL;
\r
2056 nodeLevel5 = nodeLevel5->next)
\r
2059 if (!xmlStrcmp(nodeLevel5->name, (const xmlChar *)"getetag") ||
\r
2060 !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"d:getetag") ||
\r
2061 !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"D:getetag")
\r
2064 for (nodeLevel6 = nodeLevel5->children;
\r
2065 nodeLevel6 != NULL;
\r
2066 nodeLevel6 = nodeLevel6->next)
\r
2069 // Strip the quotes from the ETag.
\r
2071 ETagData = wxString::FromUTF8((const char*)nodeLevel6->content);
\r
2072 if (ETagData.Mid(0, 1) == wxT("\"") && ETagData.Mid((ETagData.Len() - 1), 1) == wxT("\"")){
\r
2074 ETagData.Remove(0, 1);
\r
2075 ETagData.RemoveLast();
\r
2091 if (HREFFound == TRUE && ETagFound == TRUE){
\r
2093 // Add to the map data.
\r
2095 xmlDataMap.insert(std::make_pair(DataFilename, ETagData));
\r
2099 // Reset the values.
\r
2101 HREFFound = FALSE;
\r
2102 ETagFound = FALSE;
\r
2111 xmlFreeDoc(xmlCardDAVDoc);
\r
2113 // Get the first result.
\r
2115 for (std::map<wxString,wxString>::iterator iter = xmlDataMap.begin();
\r
2116 iter != xmlDataMap.end(); ++iter){
\r
2118 ETagResult = iter->second;
\r
2123 if (ETagResult.IsEmpty()){
\r
2133 wxString CardDAV::ETagValueResult(){
\r
2135 return ETagResult;
\r
2139 void CardDAV::GetServerETagValue(){
\r
2141 std::thread ConnectThread(&CardDAV::GetServerETagValueThread, this);
\r
2142 ConnectThread.detach();
\r
2146 void CardDAV::SetupData(wxString Method, wxString FilenameLocation, wxString UploadData){
\r
2148 ServerMethod = Method;
\r
2149 ServerFilenameLocation = FilenameLocation;
\r
2150 ServerUploadData = UploadData;
\r
2152 // Check if ServerFilenameLocation has a / at
\r
2153 // the start and if not then append it.
\r
2155 if (ServerFilenameLocation.Left(1) != wxT("/")){
\r
2157 // Not there so insert.
\r
2159 ServerFilenameLocation = wxT("/") + ServerFilenameLocation;
\r
2165 void CardDAV::SetupVariables(std::map<int, int> *actlist, int actindex){
\r
2167 ActivityListPtr = actlist;
\r
2168 ItemIndex = actindex;
\r
2172 wxString CardDAV::GetETagData(){
\r
2178 void CardDAV::SetUploadMode(bool IncMode){
\r
2180 UploadMode = IncMode;
\r
2184 void CardDAV::SetEditMode(bool EditModeInc){
\r
2186 EditMode = EditModeInc;
\r
2190 ContactListData CardDAV::GetContactList(wxString SyncTokenInc){
\r
2192 ContactListData ContactListFinal;
\r
2193 std::map<wxString,FileSyncData> ContactList;
\r
2196 PageHeader.Clear();
\r
2199 AuthPassed = TRUE;
\r
2200 AbortConnection = FALSE;
\r
2203 wxString ServerAddressURL;
\r
2204 wxString ServerAuth;
\r
2205 wxString ServerAddressSSL;
\r
2206 wxString ServerAddressNormal;
\r
2208 conn = curl_easy_init();
\r
2210 struct CardDAVCURLPasser {
\r
2213 bool HeaderMode = TRUE;
\r
2215 } CardDAVHeader, CardDAVFooter;
\r
2217 CardDAVHeader.Data = this;
\r
2218 CardDAVHeader.HeaderMode = TRUE;
\r
2220 CardDAVFooter.Data = this;
\r
2221 CardDAVFooter.HeaderMode = FALSE;
\r
2226 ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/") + ServerPrefix + wxT("/");
\r
2227 ServerAddressSSL = wxT("https://") + ServerAddressURL;
\r
2228 ServerAddressNormal = wxT("http://") + ServerAddressURL;
\r
2230 ServerAuth = ServerUser + wxT(":") + ServerPass;
\r
2232 // Load the sync token file (if it exists).
\r
2234 wxCharBuffer SyncDataBuffer;
\r
2235 wxString SyncData;
\r
2239 SyncTokenInc.Trim();
\r
2241 if (!SyncTokenInc.IsEmpty()){
\r
2243 SyncData = wxT("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
\r
2244 SyncData.Append(wxT("<D:sync-collection xmlns:D=\"DAV:\"\n"));
\r
2245 SyncData.Append(wxT(" xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"));
\r
2246 SyncData.Append(wxT("<D:sync-token>"));
\r
2247 //SyncData.Trim();
\r
2248 //SyncData.Append(wxT("data:,00378c55-1f44-44a2-a255-84f6560b5cac_580"));
\r
2249 SyncData.Append(SyncTokenInc);
\r
2250 //SyncData.Trim();
\r
2251 SyncData.Append(wxT("</D:sync-token>\n"));
\r
2252 SyncData.Append(wxT("<D:sync-level>1</D:sync-level>\n"));
\r
2253 SyncData.Append(wxT("<D:prop>\n"));
\r
2254 SyncData.Append(wxT(" <D:getetag/>\n"));
\r
2255 SyncData.Append(wxT("</D:prop>\n"));
\r
2256 SyncData.Append(wxT("</D:sync-collection>"));
\r
2258 SyncDataBuffer = SyncData.ToUTF8();
\r
2262 SyncData = wxT("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
\r
2263 SyncData.Append(wxT("<D:sync-collection xmlns:D=\"DAV:\""));
\r
2264 SyncData.Append(wxT(" xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"));
\r
2265 SyncData.Append(wxT("<D:sync-token/>\n"));
\r
2266 SyncData.Append(wxT("<D:sync-level>1</D:sync-level>\n"));
\r
2267 SyncData.Append(wxT("<D:prop>\n"));
\r
2268 SyncData.Append(wxT(" <D:getetag/>\n"));
\r
2269 SyncData.Append(wxT("</D:prop>\n"));
\r
2270 SyncData.Append(wxT("</D:sync-collection>\n"));
\r
2272 SyncDataBuffer = SyncData.ToUTF8();
\r
2276 //static const char* query = SyncData.mb_str();
\r
2278 /*char *query = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\
\r
2279 <D:sync-collection xmlns:D=\"DAV:\"\n\
\r
2280 xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n\
\r
2281 <D:sync-token>data:,00378c55-1f44-44a2-a255-84f6560b5cac_580</D:sync-token>\n\
\r
2282 <D:sync-level>1</D:sync-level>\n\
\r
2286 </D:sync-collection>\n";*/
\r
2287 const char* query = SyncDataBuffer.data();
\r
2291 std::map<int,int>::iterator ActIter;
\r
2292 struct UploadDataStruc UploadData;
\r
2294 ActIter = ActivityListPtr->find((int)ItemIndex);
\r
2296 curl_slist *slist = NULL;
\r
2298 slist = curl_slist_append(slist, "Depth: 1");
\r
2302 wxString ServerCertFilename;
\r
2303 bool MatchingCert = FALSE;
\r
2305 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
2306 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
2307 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
\r
2308 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
2309 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
2310 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
2311 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
2312 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
2313 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
2314 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
2315 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
2316 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
2317 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");
\r
2318 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
2319 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, slist);
\r
2320 curl_easy_setopt(conn, CURLOPT_CERTINFO, 1);
\r
2322 ServerCertFilename = GetAccountDir(ServerAccount, TRUE);
\r
2324 if (wxFile::Exists(ServerCertFilename) == TRUE){
\r
2326 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 1);
\r
2327 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 2);
\r
2328 curl_easy_setopt(conn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8));
\r
2332 //UploadData.readptr = &CardDAVDataQuery;
\r
2333 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
2334 //curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
2335 //curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
2336 //curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
2338 //curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writefunc);
\r
2339 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
2340 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
2342 claconncode = (curl_easy_perform(conn));
\r
2344 // If CURLE_PEER_FAILED_VERIFICATION is returned, retry without
\r
2345 // the local certificate in use.
\r
2347 if (claconncode == CURLE_PEER_FAILED_VERIFICATION){
\r
2349 curl_easy_cleanup(conn);
\r
2350 conn = curl_easy_init();
\r
2352 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
2353 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
2354 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
\r
2355 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
2356 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
2357 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
2358 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
2359 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
2360 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
2361 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
2362 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
2363 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
2364 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");
\r
2365 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
2366 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, slist);
\r
2367 curl_easy_setopt(conn, CURLOPT_CERTINFO, 1);
\r
2368 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
2369 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
2371 claconncode = (curl_easy_perform(conn));
\r
2373 // If claconncode is CURLE_OK then delete the certificate file as that
\r
2374 // is no longer needed.
\r
2376 if (claconncode == CURLE_OK){
\r
2378 // Delete the certificate file.
\r
2380 wxRemoveFile(ServerCertFilename);
\r
2386 // Check if it fails with a CURLE_SSL_CACERT then compare
\r
2387 // the certificates as PEM files.
\r
2389 if (claconncode == CURLE_SSL_CACERT && wxFile::Exists(ServerCertFilename) == TRUE){
\r
2391 //curl_easy_cleanup(conn);
\r
2392 //conn = curl_easy_init();
\r
2395 sslerrconn = curl_easy_init();
\r
2396 CURLcode sslerrconncode;
\r
2398 //claconncode = (curl_easy_perform(conn));
\r
2400 wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
2402 curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));
\r
2403 curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0);
\r
2404 curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
2405 curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60);
\r
2406 curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE);
\r
2407 curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
2408 curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
2409 curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData);
\r
2410 curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader);
\r
2411 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this);
\r
2412 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
2413 curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);
\r
2414 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);
\r
2415 curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);
\r
2417 wxString SSLLocalData;
\r
2418 wxString SSLServerData;
\r
2420 sslerrconncode = (curl_easy_perform(sslerrconn));
\r
2422 SSLCertCol = BuildSSLCollection(sslerrconn);
\r
2423 std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertCol.SSLCollection.find(0);
\r
2424 std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
\r
2426 wxFFile SSLLocalFile;
\r
2428 #if wxABI_VERSION < 20900
\r
2429 SSLLocalFile.Open(ServerCertFilename.c_str(), wxT("r"));
\r
2431 SSLLocalFile.Open(ServerCertFilename, wxT("r"));
\r
2434 // Load the recovery database for tasks not done.
\r
2436 if (SSLLocalFile.IsOpened() == TRUE){
\r
2438 // Check if we are using wxWidgets version 2.8 or less and
\r
2439 // execute the required command accordingly.
\r
2441 SSLLocalFile.ReadAll(&SSLLocalData, wxConvAuto());
\r
2446 SSLServerData = SSLDataIter->second;
\r
2448 if (SSLLocalData == SSLServerData){
\r
2450 // Server key matches with local key so retry with CURLOPT_SSL_VERIFYPEER
\r
2451 // and CURLOPT_SSL_VERIFYHOST off.
\r
2453 curl_easy_cleanup(conn);
\r
2454 conn = curl_easy_init();
\r
2456 PageHeader.clear();
\r
2459 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
2460 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
2461 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
2462 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
2463 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
2464 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
2465 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
2466 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
2467 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
2468 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
2469 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
2470 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
2471 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");
\r
2472 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
2473 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, slist);
\r
2474 curl_easy_setopt(conn, CURLOPT_CERTINFO, 1);
\r
2475 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
2476 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
2477 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0);
\r
2478 curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0);
\r
2480 claconncode = (curl_easy_perform(conn));
\r
2482 MatchingCert = TRUE;
\r
2486 if (MatchingCert == FALSE){
\r
2488 claconncode = CURLE_SSL_CACERT;
\r
2489 return ContactListFinal;
\r
2493 curl_easy_cleanup(sslerrconn);
\r
2497 // Sort out SSL error.
\r
2499 // When SSL cert error occurs, connect again and fetch certificates.
\r
2500 // Display a message to the user explaining that an invalid
\r
2501 // certificate has been given and let the user decide what
\r
2504 if (claconncode == CURLE_OK){
\r
2506 } else if (claconncode == CURLE_SSL_CACERT || claconncode == CURLE_PEER_FAILED_VERIFICATION){
\r
2509 sslerrconn = curl_easy_init();
\r
2510 CURLcode sslerrconncode;
\r
2512 wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
2514 // Replace conn with sslerrconn!
\r
2516 curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));
\r
2517 curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0);
\r
2518 curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
2519 curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60);
\r
2520 curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE);
\r
2521 curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
2522 curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
2523 curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData);
\r
2524 curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader);
\r
2525 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this);
\r
2526 curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
2527 curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);
\r
2528 curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);
\r
2529 curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);
\r
2531 sslerrconncode = (curl_easy_perform(sslerrconn));
\r
2533 SSLCertCol = BuildSSLCollection(sslerrconn);
\r
2534 SSLCertCol.SuccessCode = 1;
\r
2536 return ContactListFinal;
\r
2538 } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){
\r
2540 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
2541 curl_easy_strerror(claconncode));
\r
2542 int http_code = 0;
\r
2543 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
2544 fprintf(stderr, "Error code was: %d\n", http_code);
\r
2546 return ContactListFinal;
\r
2550 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
2551 curl_easy_strerror(claconncode));
\r
2552 int http_code = 0;
\r
2553 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
2554 fprintf(stderr, "Error code was: %d\n", http_code);
\r
2556 return ContactListFinal;
\r
2560 SSLCertCol = BuildSSLCollection(conn);
\r
2566 wxString EmptyString;
\r
2568 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressNormal.mb_str(wxConvUTF8));
\r
2569 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
2570 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
2571 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
2572 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
2573 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
2574 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
2575 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
2576 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
2577 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
2578 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
2579 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
2580 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");
\r
2581 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
2582 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, slist);
\r
2584 //UploadData.readptr = &CardDAVDataQuery;
\r
2585 //UploadData.sizeleft = CardDAVDataQuery.Len();
\r
2586 //curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
2587 //curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
2588 //curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
2590 //curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writefunc);
\r
2591 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
2592 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
2595 PageHeader.Clear();
\r
2597 claconncode = (curl_easy_perform(conn));
\r
2599 if (claconncode == CURLE_OK){
\r
2603 } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){
\r
2605 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
2606 curl_easy_strerror(claconncode));
\r
2607 int http_code = 0;
\r
2608 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
2609 fprintf(stderr, "Error code was: %i\n", http_code);
\r
2611 return ContactListFinal;
\r
2615 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
2616 curl_easy_strerror(claconncode));
\r
2617 int http_code = 0;
\r
2618 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);
\r
2619 fprintf(stderr, "Error code was: %i\n", http_code);
\r
2621 return ContactListFinal;
\r
2627 xmlDocPtr xmlCardDAVDoc;
\r
2628 xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
\r
2630 xmlNodePtr nodeLevel1;
\r
2631 xmlNodePtr nodeLevel2;
\r
2632 xmlNodePtr nodeLevel3;
\r
2633 xmlNodePtr nodeLevel4;
\r
2634 xmlNodePtr nodeLevel5;
\r
2635 xmlNodePtr nodeLevel6;
\r
2637 xmlNodePtr nodeStatusLv1;
\r
2638 xmlNodePtr nodeStatusLv2;
\r
2640 std::map<wxString,wxString> xmlDataMap;
\r
2641 std::map<wxString,wxString> ServerETagData;
\r
2643 wxString DataFilename;
\r
2644 wxString DataSyncToken;
\r
2645 int DataFileStatus;
\r
2646 wxString ETagData;
\r
2647 bool SyncTokenFound = FALSE;
\r
2649 std::string xmlStringSafe;
\r
2651 // Tranverse through the catacombs of the response to get our ETag for the file and
\r
2652 // the server syncronisation token.
\r
2654 // Start by getting all the server ETag data.
\r
2656 for (nodeLevel1 = xmlCardDAVDoc->children;
\r
2657 nodeLevel1 != NULL;
\r
2658 nodeLevel1 = nodeLevel1->next)
\r
2661 for (nodeLevel2 = nodeLevel1->children;
\r
2662 nodeLevel2 != NULL;
\r
2663 nodeLevel2 = nodeLevel2->next)
\r
2666 printf("\t%s:%s\n", nodeLevel2->name, nodeLevel2->content);
\r
2668 for (nodeLevel3 = nodeLevel2->children;
\r
2669 nodeLevel3 != NULL;
\r
2670 nodeLevel3 = nodeLevel3->next)
\r
2673 DataFileStatus = 0;
\r
2674 bool HREFFound = FALSE;
\r
2675 bool ETagFound = FALSE;
\r
2676 bool HTTPStatus = FALSE;
\r
2678 printf("\t\t%s:%s\n", nodeLevel3->name, nodeLevel3->content);
\r
2680 if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"href") ||
\r
2681 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:href") ||
\r
2682 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:href")
\r
2685 // Get the filename.
\r
2687 for (nodeLevel4 = nodeLevel3->children;
\r
2688 nodeLevel4 != NULL;
\r
2689 nodeLevel4 = nodeLevel4->next)
\r
2692 if (!xmlStrcmp(nodeLevel4->name, (const xmlChar *)"text") ||
\r
2693 !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"d:text") ||
\r
2694 !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"D:text")
\r
2697 DataFilename = wxString::FromUTF8((const char*)nodeLevel4->content);
\r
2698 wxStringTokenizer wSTDFilename(DataFilename, wxT("/"));
\r
2700 while (wSTDFilename.HasMoreTokens()){
\r
2702 DataFilename = wSTDFilename.GetNextToken();
\r
2717 for (nodeLevel4 = nodeLevel3->children;
\r
2718 nodeLevel4 != NULL;
\r
2719 nodeLevel4 = nodeLevel4->next)
\r
2722 for (nodeStatusLv1 = nodeLevel3->children;
\r
2723 nodeStatusLv1 != NULL;
\r
2724 nodeStatusLv1 = nodeStatusLv1->next)
\r
2727 if (wxString::FromUTF8((const char*)nodeStatusLv1->content) == wxT("HTTP/1.1 404 Not Found")){
\r
2729 DataFileStatus = 2;
\r
2731 HTTPStatus = TRUE;
\r
2735 if ((!xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"status") ||
\r
2736 !xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"d:status") ||
\r
2737 !xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"D:status")) && HTTPStatus == FALSE)
\r
2740 // Get the filename.
\r
2742 for (nodeStatusLv2 = nodeStatusLv1->children;
\r
2743 nodeStatusLv2 != NULL;
\r
2744 nodeStatusLv2 = nodeStatusLv2->next)
\r
2747 if (!xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"text") ||
\r
2748 !xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"d:text") ||
\r
2749 !xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"D:text")
\r
2752 if (wxString::FromUTF8((const char*)nodeStatusLv2->content) == wxT("HTTP/1.1 200 OK")){
\r
2754 DataFileStatus = 1;
\r
2756 HTTPStatus = TRUE;
\r
2758 // This is currently in a WebDAV draft and may hopefully be enabled when this changes.
\r
2760 //} else if (wxString::FromUTF8((const char*)nodeStatusLv2->content) == wxT("HTTP/1.1 201 Created")){
\r
2762 // DataFileStatus = 0;
\r
2777 for (nodeLevel5 = nodeLevel4->children;
\r
2778 nodeLevel5 != NULL;
\r
2779 nodeLevel5 = nodeLevel5->next)
\r
2782 if (!xmlStrcmp(nodeLevel5->name, (const xmlChar *)"getetag") ||
\r
2783 !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"d:getetag") ||
\r
2784 !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"D:getetag")
\r
2787 for (nodeLevel6 = nodeLevel5->children;
\r
2788 nodeLevel6 != NULL;
\r
2789 nodeLevel6 = nodeLevel6->next)
\r
2792 // Strip the quotes from the ETag.
\r
2794 ETagData = wxString::FromUTF8((const char*)nodeLevel6->content);
\r
2795 if (ETagData.Mid(0, 1) == wxT("\"") && ETagData.Mid((ETagData.Len() - 1), 1) == wxT("\"")){
\r
2797 ETagData.Remove(0, 1);
\r
2798 ETagData.RemoveLast();
\r
2814 if (HREFFound == TRUE && ETagFound == TRUE && HTTPStatus == TRUE){
\r
2816 // Add to the map data.
\r
2818 FileSyncData SData;
\r
2820 SData.ETagData = ETagData;
\r
2821 SData.DataFlag = DataFileStatus;
\r
2823 ContactListFinal.ListData.insert(std::make_pair(DataFilename, SData));
\r
2827 // Reset the values.
\r
2829 HREFFound = FALSE;
\r
2830 ETagFound = FALSE;
\r
2831 HTTPStatus = FALSE;
\r
2835 if ((!xmlStrcmp(nodeLevel2->name, (const xmlChar *)"sync-token") ||
\r
2836 !xmlStrcmp(nodeLevel2->name, (const xmlChar *)"d:sync-token") ||
\r
2837 !xmlStrcmp(nodeLevel2->name, (const xmlChar *)"D:sync-token")) &&
\r
2838 SyncTokenFound == FALSE
\r
2841 for (nodeLevel3 = nodeLevel2->children;
\r
2842 nodeLevel3 != NULL;
\r
2843 nodeLevel3 = nodeLevel3->next)
\r
2846 if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"text") ||
\r
2847 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:text") ||
\r
2848 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:text")
\r
2851 DataSyncToken = wxString::FromUTF8((const char*)nodeLevel3->content);
\r
2853 SyncTokenFound = TRUE;
\r
2865 for (nodeLevel1 = xmlCardDAVDoc->children;
\r
2866 nodeLevel1 != NULL;
\r
2867 nodeLevel1 = nodeLevel1->next)
\r
2870 for (nodeLevel2 = nodeLevel1->children;
\r
2871 nodeLevel2 != NULL;
\r
2872 nodeLevel2 = nodeLevel2->next)
\r
2875 printf("\t%s:%s\n", nodeLevel2->name, nodeLevel2->content);
\r
2877 DataFileStatus = 0;
\r
2878 bool HREFFound = FALSE;
\r
2879 bool ETagFound = FALSE;
\r
2880 bool HTTPStatus = FALSE;
\r
2882 for (nodeLevel3 = nodeLevel2->children;
\r
2883 nodeLevel3 != NULL;
\r
2884 nodeLevel3 = nodeLevel3->next)
\r
2887 printf("\t\t%s:%s\n", nodeLevel3->name, nodeLevel3->content);
\r
2889 if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"href") ||
\r
2890 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:href") ||
\r
2891 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:href")
\r
2894 // Get the filename.
\r
2896 for (nodeLevel4 = nodeLevel3->children;
\r
2897 nodeLevel4 != NULL;
\r
2898 nodeLevel4 = nodeLevel4->next)
\r
2901 if (!xmlStrcmp(nodeLevel4->name, (const xmlChar *)"text") ||
\r
2902 !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"d:text") ||
\r
2903 !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"D:text")
\r
2906 DataFilename = wxString::FromUTF8((const char*)nodeLevel4->content);
\r
2907 wxStringTokenizer wSTDFilename(DataFilename, wxT("/"));
\r
2909 while (wSTDFilename.HasMoreTokens()){
\r
2911 DataFilename = wSTDFilename.GetNextToken();
\r
2926 for (nodeLevel4 = nodeLevel3->children;
\r
2927 nodeLevel4 != NULL;
\r
2928 nodeLevel4 = nodeLevel4->next)
\r
2931 for (nodeStatusLv1 = nodeLevel3->children;
\r
2932 nodeStatusLv1 != NULL;
\r
2933 nodeStatusLv1 = nodeStatusLv1->next)
\r
2936 if (wxString::FromUTF8((const char*)nodeStatusLv1->content) == wxT("HTTP/1.1 404 Not Found")){
\r
2938 DataFileStatus = 2;
\r
2940 HTTPStatus = TRUE;
\r
2944 if ((!xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"status") ||
\r
2945 !xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"d:status") ||
\r
2946 !xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"D:status")) && HTTPStatus == FALSE)
\r
2949 // Get the filename.
\r
2951 for (nodeStatusLv2 = nodeStatusLv1->children;
\r
2952 nodeStatusLv2 != NULL;
\r
2953 nodeStatusLv2 = nodeStatusLv2->next)
\r
2956 if (!xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"text") ||
\r
2957 !xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"d:text") ||
\r
2958 !xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"D:text")
\r
2961 if (wxString::FromUTF8((const char*)nodeStatusLv2->content) == wxT("HTTP/1.1 200 OK")){
\r
2963 DataFileStatus = 1;
\r
2965 HTTPStatus = TRUE;
\r
2967 // This is currently in a WebDAV draft and may hopefully be enabled when this changes.
\r
2969 //} else if (wxString::FromUTF8((const char*)nodeStatusLv2->content) == wxT("HTTP/1.1 201 Created")){
\r
2971 // DataFileStatus = 0;
\r
2986 for (nodeLevel5 = nodeLevel4->children;
\r
2987 nodeLevel5 != NULL;
\r
2988 nodeLevel5 = nodeLevel5->next)
\r
2991 if (!xmlStrcmp(nodeLevel5->name, (const xmlChar *)"getetag") ||
\r
2992 !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"d:getetag") ||
\r
2993 !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"D:getetag")
\r
2996 for (nodeLevel6 = nodeLevel5->children;
\r
2997 nodeLevel6 != NULL;
\r
2998 nodeLevel6 = nodeLevel6->next)
\r
3001 // Strip the quotes from the ETag.
\r
3003 ETagData = wxString::FromUTF8((const char*)nodeLevel6->content);
\r
3004 if (ETagData.Mid(0, 1) == wxT("\"") && ETagData.Mid((ETagData.Len() - 1), 1) == wxT("\"")){
\r
3006 ETagData.Remove(0, 1);
\r
3007 ETagData.RemoveLast();
\r
3025 if (HREFFound == TRUE && HTTPStatus == TRUE && DataFileStatus == 2){
\r
3027 FileSyncData SData;
\r
3029 SData.ETagData = wxT("");
\r
3030 SData.DataFlag = DataFileStatus;
\r
3032 ContactListFinal.ListData.insert(std::make_pair(DataFilename, SData));
\r
3036 if (HREFFound == TRUE && ETagFound == TRUE && HTTPStatus == TRUE){
\r
3038 // Add to the map data.
\r
3040 FileSyncData SData;
\r
3042 SData.ETagData = ETagData;
\r
3043 SData.DataFlag = DataFileStatus;
\r
3045 ContactListFinal.ListData.insert(std::make_pair(DataFilename, SData));
\r
3049 // Reset the values.
\r
3051 HREFFound = FALSE;
\r
3052 ETagFound = FALSE;
\r
3053 HTTPStatus = FALSE;
\r
3054 DataFilename.Clear();
\r
3056 if ((!xmlStrcmp(nodeLevel2->name, (const xmlChar *)"sync-token") ||
\r
3057 !xmlStrcmp(nodeLevel2->name, (const xmlChar *)"d:sync-token") ||
\r
3058 !xmlStrcmp(nodeLevel2->name, (const xmlChar *)"D:sync-token")) &&
\r
3059 SyncTokenFound == FALSE
\r
3062 for (nodeLevel3 = nodeLevel2->children;
\r
3063 nodeLevel3 != NULL;
\r
3064 nodeLevel3 = nodeLevel3->next)
\r
3067 if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"text") ||
\r
3068 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:text") ||
\r
3069 !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:text")
\r
3072 DataSyncToken = wxString::FromUTF8((const char*)nodeLevel3->content);
\r
3074 SyncTokenFound = TRUE;
\r
3086 // Get the sync token.
\r
3088 if (SyncTokenFound == TRUE){
\r
3090 ContactListFinal.SyncToken = DataSyncToken;
\r
3096 SleepFor(2000000000);
\r
3098 /*timespec n1, n2;
\r
3101 n1.tv_nsec = 2000000000L;
\r
3103 nanosleep(&n1, &n2);*/
\r
3105 xmlFreeDoc(xmlCardDAVDoc);
\r
3106 curl_easy_cleanup(conn);
\r
3108 SyncDataBuffer.reset();
\r
3110 // Get the first result.
\r
3112 return ContactListFinal;
\r
3116 int CardDAV::GetResultCode(){
\r
3118 return (int)claconncode;
\r
3122 int CardDAV::GetHTTPCode(){
\r
3124 return HTTPErrorCode;
\r
3128 wxString CardDAV::GetErrorBuffer(){
\r
3130 wxString ErrorBuffer = wxString::FromUTF8(curlerrbuffer);
\r
3132 return ErrorBuffer;
\r
3136 wxString CardDAV::GetDefaultAddressBookURL(){
\r
3138 // First: Get the principal UID address.
\r
3141 PageHeader.Clear();
\r
3144 AuthPassed = TRUE;
\r
3145 AbortConnection = FALSE;
\r
3148 CURLcode conncode;
\r
3149 wxString ServerAddressURL;
\r
3150 wxString ServerAuth;
\r
3151 wxString ServerAddressSSL;
\r
3152 wxString ServerAddressNormal;
\r
3154 conn = curl_easy_init();
\r
3156 struct curl_slist *connhd = NULL;
\r
3157 struct curl_slist *connhd2 = NULL;
\r
3158 struct curl_slist *connhd3 = NULL;
\r
3160 connhd = curl_slist_append(connhd, "Depth: 0");
\r
3161 connhd = curl_slist_append(connhd, "Prefer: return-minimal");
\r
3162 connhd = curl_slist_append(connhd, "Content-Type: application/xml; charset=utf-8");
\r
3164 connhd2 = curl_slist_append(connhd2, "Depth: 0");
\r
3165 connhd2 = curl_slist_append(connhd2, "Prefer: return-minimal");
\r
3166 connhd2 = curl_slist_append(connhd2, "Content-Type: application/xml; charset=utf-8");
\r
3168 connhd3 = curl_slist_append(connhd3, "Depth: 1");
\r
3169 connhd3 = curl_slist_append(connhd3, "Prefer: return-minimal");
\r
3170 connhd3 = curl_slist_append(connhd3, "Content-Type: application/xml; charset=utf-8");
\r
3172 struct CardDAVCURLPasser {
\r
3175 bool HeaderMode = TRUE;
\r
3177 } CardDAVHeader, CardDAVFooter;
\r
3179 CardDAVHeader.Data = this;
\r
3180 CardDAVHeader.HeaderMode = TRUE;
\r
3182 CardDAVFooter.Data = this;
\r
3183 CardDAVFooter.HeaderMode = FALSE;
\r
3189 wxString ETagOriginal;
\r
3190 wxString ETagServer;
\r
3192 ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
\r
3193 ServerAddressSSL = wxT("https://") + ServerAddressURL;
\r
3194 ServerAddressNormal = wxT("http://") + ServerAddressURL;
\r
3196 ServerAuth = ServerUser + wxT(":") + ServerPass;
\r
3198 wxString SAURLPrincipals = ServerAddressURL + wxT("principals/");
\r
3199 wxString SAURLPrincipalURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort);
\r
3200 wxString SAURLAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort);
\r
3201 wxString FinalPrefix;
\r
3203 struct UploadDataStruc UploadData;
\r
3205 // Setup the first query finding out where the principal URL is.
\r
3207 const char* query = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
\r
3208 "<D:propfind xmlns:D=\"DAV:\">\n"
\r
3210 " <D:current-user-principal/>\n"
\r
3214 // Setup the second query finding out where the address book home URL is.
\r
3216 const char* query2 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
\r
3217 "<D:propfind xmlns:D=\"DAV:\""
\r
3218 " xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"
\r
3220 " <C:addressbook-home-set/>\n"
\r
3224 // Setup the third query finding out where the default address book URL is.
\r
3226 const char* query3 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
\r
3227 "<D:propfind xmlns:D=\"DAV:\""
\r
3228 " xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"
\r
3230 " <C:default-addressbook-URL/>\n"
\r
3236 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipals.mb_str(wxConvUTF8));
\r
3237 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
3238 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
\r
3239 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
3240 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
\r
3241 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
3242 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
3243 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
3244 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
3245 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
3246 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
3248 if (UploadMode == TRUE){
\r
3250 UploadData.readptr = &ServerUploadData;
\r
3251 UploadData.sizeleft = ServerUploadData.Len();
\r
3252 curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
3253 curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
3254 curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
3258 conncode = (curl_easy_perform(conn));
\r
3260 if (conncode == CURLE_OK){
\r
3262 *ServerResult = TRUE;
\r
3263 AuthPassed = TRUE;
\r
3269 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3270 curl_easy_strerror(conncode));
\r
3272 *ServerResult = FALSE;
\r
3274 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
\r
3284 // Do an initial connection (incase of Digest authentication).
\r
3287 PageHeader.Clear();
\r
3289 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipals.mb_str(wxConvUTF8));
\r
3290 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
3291 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
\r
3292 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
3293 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
\r
3294 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
3295 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
3296 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
3297 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
3298 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
3299 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
3300 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
3301 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
3302 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
\r
3303 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
\r
3304 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
\r
3305 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd);
\r
3307 conncode = (curl_easy_perform(conn));
\r
3309 // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG,
\r
3310 // then bring up the conflict resolution form.
\r
3312 if (EditMode == TRUE){
\r
3316 if (conncode == CURLE_OK){
\r
3318 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
\r
3320 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
\r
3322 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3323 curl_easy_strerror(conncode));
\r
3325 fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
\r
3332 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3333 curl_easy_strerror(conncode));
\r
3340 // Process the XML data from the application.
\r
3342 xmlDocPtr xmlCardDAVDoc;
\r
3343 xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
\r
3345 xmlNodePtr nodeLevel1;
\r
3346 xmlNodePtr nodeLevel2;
\r
3347 xmlNodePtr nodeLevel3;
\r
3348 xmlNodePtr nodeLevel4;
\r
3349 xmlNodePtr nodeLevel5;
\r
3350 xmlNodePtr nodeLevel6;
\r
3351 xmlNodePtr nodeLevel7;
\r
3353 for (nodeLevel1 = xmlCardDAVDoc->children;
\r
3354 nodeLevel1 != NULL;
\r
3355 nodeLevel1 = nodeLevel1->next)
\r
3358 for (nodeLevel2 = nodeLevel1->children;
\r
3359 nodeLevel2 != NULL;
\r
3360 nodeLevel2 = nodeLevel2->next)
\r
3364 for (nodeLevel3 = nodeLevel2->children;
\r
3365 nodeLevel3 != NULL;
\r
3366 nodeLevel3 = nodeLevel3->next)
\r
3369 for (nodeLevel4 = nodeLevel3->children;
\r
3370 nodeLevel4 != NULL;
\r
3371 nodeLevel4 = nodeLevel4->next)
\r
3374 for (nodeLevel5 = nodeLevel4->children;
\r
3375 nodeLevel5 != NULL;
\r
3376 nodeLevel5 = nodeLevel5->next)
\r
3379 for (nodeLevel6 = nodeLevel5->children;
\r
3380 nodeLevel6 != NULL;
\r
3381 nodeLevel6 = nodeLevel6->next)
\r
3384 if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") ||
\r
3385 !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") ||
\r
3386 !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href")
\r
3389 // Found the <href> part so extract the principal URL address.
\r
3391 for (nodeLevel7 = nodeLevel6->children;
\r
3392 nodeLevel7 != NULL;
\r
3393 nodeLevel7 = nodeLevel7->next)
\r
3396 SAURLPrincipalURL.Append(wxString::FromUTF8((const char*)nodeLevel7->content));
\r
3414 xmlFreeDoc(xmlCardDAVDoc);
\r
3416 PageHeader.Clear();
\r
3418 // Second: Get the addressbook-home-set
\r
3420 curl_easy_reset(conn);
\r
3424 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
3425 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
3426 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
\r
3427 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
3428 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
\r
3429 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
3430 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
3431 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
3432 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
3433 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
3434 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
3436 if (UploadMode == TRUE){
\r
3438 UploadData.readptr = &ServerUploadData;
\r
3439 UploadData.sizeleft = ServerUploadData.Len();
\r
3440 curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
3441 curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
3442 curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
3446 conncode = (curl_easy_perform(conn));
\r
3448 if (conncode == CURLE_OK){
\r
3450 *ServerResult = TRUE;
\r
3451 AuthPassed = TRUE;
\r
3457 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3458 curl_easy_strerror(conncode));
\r
3460 *ServerResult = FALSE;
\r
3462 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
\r
3472 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipalURL.mb_str(wxConvUTF8));
\r
3473 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
3474 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
\r
3475 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
3476 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
\r
3477 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
3478 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
3479 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
3480 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
3481 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
3482 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
3483 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
3484 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
3485 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
\r
3486 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query2);
\r
3487 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query2));
\r
3488 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd2);
\r
3490 conncode = (curl_easy_perform(conn));
\r
3492 // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG,
\r
3493 // then bring up the conflict resolution form.
\r
3495 if (EditMode == TRUE){
\r
3499 if (conncode == CURLE_OK){
\r
3501 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
\r
3503 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
\r
3505 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3506 curl_easy_strerror(conncode));
\r
3508 fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
\r
3514 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3515 curl_easy_strerror(conncode));
\r
3522 xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
\r
3524 for (nodeLevel1 = xmlCardDAVDoc->children;
\r
3525 nodeLevel1 != NULL;
\r
3526 nodeLevel1 = nodeLevel1->next)
\r
3529 for (nodeLevel2 = nodeLevel1->children;
\r
3530 nodeLevel2 != NULL;
\r
3531 nodeLevel2 = nodeLevel2->next)
\r
3535 for (nodeLevel3 = nodeLevel2->children;
\r
3536 nodeLevel3 != NULL;
\r
3537 nodeLevel3 = nodeLevel3->next)
\r
3540 for (nodeLevel4 = nodeLevel3->children;
\r
3541 nodeLevel4 != NULL;
\r
3542 nodeLevel4 = nodeLevel4->next)
\r
3545 for (nodeLevel5 = nodeLevel4->children;
\r
3546 nodeLevel5 != NULL;
\r
3547 nodeLevel5 = nodeLevel5->next)
\r
3550 for (nodeLevel6 = nodeLevel5->children;
\r
3551 nodeLevel6 != NULL;
\r
3552 nodeLevel6 = nodeLevel6->next)
\r
3555 if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") ||
\r
3556 !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") ||
\r
3557 !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href")
\r
3560 // Found the <href> part so extract the principal URL address.
\r
3562 for (nodeLevel7 = nodeLevel6->children;
\r
3563 nodeLevel7 != NULL;
\r
3564 nodeLevel7 = nodeLevel7->next)
\r
3567 SAURLAddressURL.Append(wxString::FromUTF8((const char*)nodeLevel7->content));
\r
3585 xmlFreeDoc(xmlCardDAVDoc);
\r
3587 PageHeader.Clear();
\r
3589 // Finally: Get the default-addressbook-URL from the addressbook-home-set address.
\r
3591 curl_easy_reset(conn);
\r
3595 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
\r
3596 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
\r
3597 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
\r
3598 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
3599 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
\r
3600 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
3601 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
3602 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
3603 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
3604 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
3605 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
3607 if (UploadMode == TRUE){
\r
3609 UploadData.readptr = &ServerUploadData;
\r
3610 UploadData.sizeleft = ServerUploadData.Len();
\r
3611 curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);
\r
3612 curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);
\r
3613 curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);
\r
3617 conncode = (curl_easy_perform(conn));
\r
3619 if (conncode == CURLE_OK){
\r
3621 *ServerResult = TRUE;
\r
3622 AuthPassed = TRUE;
\r
3628 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3629 curl_easy_strerror(conncode));
\r
3631 *ServerResult = FALSE;
\r
3633 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
\r
3643 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLAddressURL.mb_str(wxConvUTF8));
\r
3644 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
\r
3645 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
\r
3646 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
\r
3647 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
\r
3648 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
\r
3649 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
\r
3650 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
\r
3651 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
\r
3652 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
\r
3653 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
\r
3654 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
\r
3655 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
\r
3656 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
\r
3657 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query3);
\r
3658 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query3));
\r
3659 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd3);
\r
3661 conncode = (curl_easy_perform(conn));
\r
3663 // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG,
\r
3664 // then bring up the conflict resolution form.
\r
3666 if (EditMode == TRUE){
\r
3670 if (conncode == CURLE_OK){
\r
3672 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
\r
3674 curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
\r
3676 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3677 curl_easy_strerror(conncode));
\r
3679 fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
\r
3685 fprintf(stderr, "curl_easy_perform() failed: %s\n",
\r
3686 curl_easy_strerror(conncode));
\r
3693 xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
\r
3695 for (nodeLevel1 = xmlCardDAVDoc->children;
\r
3696 nodeLevel1 != NULL;
\r
3697 nodeLevel1 = nodeLevel1->next)
\r
3700 for (nodeLevel2 = nodeLevel1->children;
\r
3701 nodeLevel2 != NULL;
\r
3702 nodeLevel2 = nodeLevel2->next)
\r
3706 for (nodeLevel3 = nodeLevel2->children;
\r
3707 nodeLevel3 != NULL;
\r
3708 nodeLevel3 = nodeLevel3->next)
\r
3711 for (nodeLevel4 = nodeLevel3->children;
\r
3712 nodeLevel4 != NULL;
\r
3713 nodeLevel4 = nodeLevel4->next)
\r
3716 for (nodeLevel5 = nodeLevel4->children;
\r
3717 nodeLevel5 != NULL;
\r
3718 nodeLevel5 = nodeLevel5->next)
\r
3721 for (nodeLevel6 = nodeLevel5->children;
\r
3722 nodeLevel6 != NULL;
\r
3723 nodeLevel6 = nodeLevel6->next)
\r
3726 if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") ||
\r
3727 !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") ||
\r
3728 !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href")
\r
3731 // Found the <href> part so extract the principal URL address.
\r
3733 for (nodeLevel7 = nodeLevel6->children;
\r
3734 nodeLevel7 != NULL;
\r
3735 nodeLevel7 = nodeLevel7->next)
\r
3738 FinalPrefix = wxString::FromUTF8((const char*)nodeLevel7->content);
\r
3756 xmlFreeDoc(xmlCardDAVDoc);
\r
3758 PageHeader.Clear();
\r
3760 return FinalPrefix;
\r
3764 SSLCertCollection CardDAV::BuildSSLCollection(CURL *conn){
\r
3766 SSLCertCollection SSLCertInfo;
\r
3768 // Grab the certificate data.
\r
3771 struct curl_slist *certdata;
\r
3772 struct curl_certinfo *certinfo;
\r
3775 certptr.certdata = NULL;
\r
3777 curl_easy_getinfo(conn, CURLINFO_CERTINFO, &certptr.certinfo);
\r
3779 wxString CertPropName;
\r
3780 wxString CertPropValue;
\r
3782 for (int i = 0; i < certptr.certinfo->num_of_certs; i++){
\r
3784 struct curl_slist *slist;
\r
3785 SSLCertData SSLCertDataInc;
\r
3787 for (slist = certptr.certinfo->certinfo[i]; slist; slist = slist->next){
\r
3789 wxStringTokenizer CertDataInc(wxString::FromUTF8(slist->data), ":");
\r
3791 // Get first token as the property name.
\r
3793 CertPropName = CertDataInc.GetNextToken();
\r
3795 // Get remaining tokens as the property value.
\r
3797 while(CertDataInc.HasMoreTokens()){
\r
3799 CertPropValue.Append(CertDataInc.GetNextToken());
\r
3803 SSLCertDataInc.CertData.insert(std::make_pair(CertPropName, CertPropValue));
\r
3804 CertPropName.clear();
\r
3805 CertPropValue.clear();
\r
3809 SSLCertInfo.SSLCollection.insert(std::make_pair(i, SSLCertDataInc));
\r
3813 return SSLCertInfo;
\r
3817 SSLCertCollection CardDAV::GetCertificateData(){
\r
3819 // Pass on the collected certificate data.
\r
3821 return SSLCertCol;
\r
3825 wxString CardDAV::GetErrorMessage(){
\r
3827 return ErrorMessage;
\r