Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
e691cc44839a43d5dca1fd3b7419223c00b8a85c
[xestiaab/.git] / source / carddav / carddav-defaultadrurl.cpp
1 // carddav-defaultadrurl.cpp - CardDAV Object - Default Address URL subroutines.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "carddav.h"
20 #include "../version.h"
21 #include <wx/wx.h>
22 #include <wx/tokenzr.h>
23 #include <wx/ffile.h>
24 #include <libxml/parser.h>
25 #include <libxml/tree.h>
26 #include <map>
27 #include <thread>
28 #include "../vcard/vcard.h"
29 #include "../common/dirs.h"
31 wxString CardDAV::GetDefaultAddressBookURL(){
33         // Get the default address book URL.
34         
35         PageData.Clear();
36         PageHeader.Clear();
38         SSLStatus = TRUE;
39         AuthPassed = TRUE;
40         AbortConnection = FALSE;
42         CURL *conn;
43         CURLcode conncode;
44         wxString ServerAddressURL;
45         wxString ServerAuth;
46         wxString ServerAddressSSL;
47         wxString ServerAddressNormal;   
49         // First: Get the principal UID address.
50         
51         conn = curl_easy_init();
52         
53         struct curl_slist *connhd = NULL;
54         struct curl_slist *connhd2 = NULL;
55         struct curl_slist *connhd3 = NULL;
57         connhd = curl_slist_append(connhd, "Depth: 0");
58         connhd = curl_slist_append(connhd, "Prefer: return-minimal");
59         connhd = curl_slist_append(connhd, "Content-Type: application/xml; charset=utf-8");
61         connhd2 = curl_slist_append(connhd2, "Depth: 0");
62         connhd2 = curl_slist_append(connhd2, "Prefer: return-minimal");
63         connhd2 = curl_slist_append(connhd2, "Content-Type: application/xml; charset=utf-8");
65         connhd3 = curl_slist_append(connhd3, "Depth: 1");
66         connhd3 = curl_slist_append(connhd3, "Prefer: return-minimal");
67         connhd3 = curl_slist_append(connhd3, "Content-Type: application/xml; charset=utf-8");
69         struct CardDAVCURLPasser {
70         
71                 CardDAV *Data;
72                 bool HeaderMode = TRUE;
73         
74         } CardDAVHeader, CardDAVFooter;
76         CardDAVHeader.Data = this;
77         CardDAVHeader.HeaderMode = TRUE;
78         
79         CardDAVFooter.Data = this;
80         CardDAVFooter.HeaderMode = FALSE;
82         wxString Data1;
83         wxString Data2;
84         
85         wxString ETag;
86         wxString ETagOriginal;
87         wxString ETagServer;
88         
89         ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
90         ServerAddressSSL = wxT("https://") + ServerAddressURL;
91         ServerAddressNormal = wxT("http://") + ServerAddressURL;
92         
93         ServerAuth = ServerUser + wxT(":") + ServerPass;
94         
95         wxString SAURLPrincipals;
96         wxString SAURLPrincipalURL;
97         wxString SAURLAddressURL;
98         
99         if (ServerSSL){
100         
101                 SAURLPrincipals = ServerAddressSSL + wxT("principals/");
102                 SAURLPrincipalURL = ServerAddressSSL;
103                 SAURLAddressURL = ServerAddressSSL;
104         
105         } else {
106         
107                 SAURLPrincipals = ServerAddressNormal + wxT("principals/");
108                 SAURLPrincipalURL = ServerAddressNormal;
109                 SAURLAddressURL = ServerAddressNormal;
110         
111         }
112         
113         wxString FinalPrefix;
115         struct UploadDataStruc UploadData;
116         
117         // Setup the first query finding out where the principal URL is.
118         
119         const char* query = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
120                 "<D:propfind xmlns:D=\"DAV:\">\n"
121                 " <D:prop>"
122                 "  <D:current-user-principal/>\n"
123                 " </D:prop>"
124                 "</D:propfind>";
126         // Setup the second query finding out where the address book home URL is.
127         
128         const char* query2 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
129         "<D:propfind xmlns:D=\"DAV:\""
130         "  xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"
131         "  <D:prop>\n"
132         "    <C:addressbook-home-set/>\n"
133         "  </D:prop>\n"
134         "</D:propfind>";
135         
136         // Setup the third query finding out where the default address book URL is.
137         
138         const char* query3 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
139         "<D:propfind xmlns:D=\"DAV:\""
140         "  xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"
141         "  <D:prop>\n"
142         "    <C:default-addressbook-URL/>\n"    
143         "  </D:prop>\n"
144         "</D:propfind>";
145         
146         if (ServerSSL){
148                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipals.mb_str(wxConvUTF8));
149                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
150                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
151                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
152                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
153                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);             
154                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
155                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
156                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
157                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
158                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
159                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
160                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
161                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
162                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd);
163                 
164                 if (AllowSelfSign == TRUE){
165                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);
166                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);
167                 }
169                 conncode = (curl_easy_perform(conn));
171                 if (conncode == CURLE_OK){
173                         *ServerResult = TRUE;
174                         AuthPassed = TRUE;
175                         ValidResponse = TRUE;
176                         SSLStatus = TRUE;
178                 } else {
180                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
181                                         curl_easy_strerror(conncode));                                  
182                                         
183                         *ServerResult = FALSE;
184                         
185                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
186                         
187                         return wxT("");                                 
189                 }
191         } else {
192         
193                 // No SSL.
195                 // Do an initial connection (incase of Digest authentication).
197                 PageData.Clear();
198                 PageHeader.Clear();
200                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipals.mb_str(wxConvUTF8));
201                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
202                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
203                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
204                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
205                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
206                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
207                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
208                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
209                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
210                 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
211                 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
212                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
213                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
214                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
215                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
216                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd);
217                 
218                 conncode = (curl_easy_perform(conn));
220                 // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG,
221                 // then bring up the conflict resolution form.
222                 
223                 if (EditMode == TRUE){
224                 
225                 }
227                 if (conncode == CURLE_OK){
229                 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
231                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
232                 
233                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
234                                         curl_easy_strerror(conncode));
236                         fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
237                                         GetHTTPCode());
239                         return wxT("");
240                 
241                 } else {
243                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
244                                         curl_easy_strerror(conncode));
245                         return wxT("");
247                 }
249         }
250         
251         // Process the XML data from the application.
252         
253         xmlDocPtr xmlCardDAVDoc;
254         xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
256         xmlNodePtr nodeLevel1;
257         xmlNodePtr nodeLevel2;
258         xmlNodePtr nodeLevel3;
259         xmlNodePtr nodeLevel4;
260         xmlNodePtr nodeLevel5;
261         xmlNodePtr nodeLevel6;
262         xmlNodePtr nodeLevel7;
263                 
264         for (nodeLevel1 = xmlCardDAVDoc->children;
265                 nodeLevel1 != NULL;
266                 nodeLevel1 = nodeLevel1->next)
267         {
269                 for (nodeLevel2 = nodeLevel1->children;
270                         nodeLevel2 != NULL;
271                         nodeLevel2 = nodeLevel2->next)
272                 {
275                         for (nodeLevel3 = nodeLevel2->children;
276                         nodeLevel3 != NULL;
277                         nodeLevel3 = nodeLevel3->next)
278                         {
279                         
280                                 for (nodeLevel4 = nodeLevel3->children;
281                                 nodeLevel4 != NULL;
282                                 nodeLevel4 = nodeLevel4->next)
283                                 {
284                         
285                                         for (nodeLevel5 = nodeLevel4->children;
286                                         nodeLevel5 != NULL;
287                                         nodeLevel5 = nodeLevel5->next)
288                                         {
289                         
290                                                 for (nodeLevel6 = nodeLevel5->children;
291                                                 nodeLevel6 != NULL;
292                                                 nodeLevel6 = nodeLevel6->next)
293                                                 {
294                         
295                                                         if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") ||
296                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") ||
297                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href")
298                                                         ){
299                         
300                                                                 // Found the <href> part so extract the principal URL address.
301                                                                 
302                                                                 for (nodeLevel7 = nodeLevel6->children;
303                                                                 nodeLevel7 != NULL;
304                                                                 nodeLevel7 = nodeLevel7->next)
305                                                                 {
306                                                                 
307                                                                         SAURLPrincipalURL.Append(wxString::FromUTF8((const char*)nodeLevel7->content));
308                         
309                                                                 }
310                         
311                                                         }
312                         
313                                                 }
314                         
315                                         }
316                         
317                                 }
318                         
319                         }
320                 
321                 }
322                 
323         }
324         
325         xmlFreeDoc(xmlCardDAVDoc);
326         PageData.Clear();
327         PageHeader.Clear();
328                 
329         // Second: Get the addressbook-home-set 
331         curl_easy_reset(conn);
333         if (ServerSSL){
335                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipalURL.mb_str(wxConvUTF8));
336                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
337                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
338                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
339                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
340                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);             
341                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
342                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
343                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
344                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
345                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
346                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
347                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query2);
348                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query2));
349                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd2);
351                 if (AllowSelfSign == TRUE){
352                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);
353                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);
354                 }
356                 conncode = (curl_easy_perform(conn));
358                 if (conncode == CURLE_OK){
360                         *ServerResult = TRUE;
361                         AuthPassed = TRUE;
362                         SSLStatus = TRUE;
364                 } else {
366                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
367                                         curl_easy_strerror(conncode));                                  
368                                         
369                         *ServerResult = FALSE;
370                         ValidResponse = FALSE;
371                         
372                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
373                         
374                         return wxT("");                                 
376                 }
378         } else {
379         
380         // No SSL.
381                 
382                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipalURL.mb_str(wxConvUTF8));
383                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
384                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
385                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
386                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
387                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
388                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
389                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
390                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
391                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
392                 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
393                 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
394                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
395                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
396                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query2);
397                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query2));
398                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd2);
399                 
400                 conncode = (curl_easy_perform(conn));
401                 
402                 // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG,
403                 // then bring up the conflict resolution form.
404                 
405                 if (EditMode == TRUE){
406                 
407                 }
409                 if (conncode == CURLE_OK){
411                 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
413                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
414                 
415                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
416                                         curl_easy_strerror(conncode));
418                         fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
419                                         GetHTTPCode());
420                         
421                         ValidResponse = FALSE;
422                         
423                         return wxT("");
424                 
425                 } else {
427                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
428                                         curl_easy_strerror(conncode));
429                         
430                         ValidResponse = FALSE;
431                         
432                         return wxT("");
434                 }
435                 
436         }
438         xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
439                 
440         for (nodeLevel1 = xmlCardDAVDoc->children;
441                 nodeLevel1 != NULL;
442                 nodeLevel1 = nodeLevel1->next)
443         {
445                 for (nodeLevel2 = nodeLevel1->children;
446                         nodeLevel2 != NULL;
447                         nodeLevel2 = nodeLevel2->next)
448                 {
451                         for (nodeLevel3 = nodeLevel2->children;
452                         nodeLevel3 != NULL;
453                         nodeLevel3 = nodeLevel3->next)
454                         {
455                         
456                                 for (nodeLevel4 = nodeLevel3->children;
457                                 nodeLevel4 != NULL;
458                                 nodeLevel4 = nodeLevel4->next)
459                                 {
460                         
461                                         for (nodeLevel5 = nodeLevel4->children;
462                                         nodeLevel5 != NULL;
463                                         nodeLevel5 = nodeLevel5->next)
464                                         {
465                         
466                                                 for (nodeLevel6 = nodeLevel5->children;
467                                                 nodeLevel6 != NULL;
468                                                 nodeLevel6 = nodeLevel6->next)
469                                                 {
470                         
471                                                         if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") ||
472                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") ||
473                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href")
474                                                         ){
475                         
476                                                                 // Found the <href> part so extract the principal URL address.
477                                                                 
478                                                                 for (nodeLevel7 = nodeLevel6->children;
479                                                                 nodeLevel7 != NULL;
480                                                                 nodeLevel7 = nodeLevel7->next)
481                                                                 {
482                                                                 
483                                                                         SAURLAddressURL.Append(wxString::FromUTF8((const char*)nodeLevel7->content));
484                         
485                                                                 }
486                         
487                                                         }
488                         
489                                                 }
490                         
491                                         }
492                         
493                                 }
494                         
495                         }
496                 
497                 }
498                 
499         }
501         xmlFreeDoc(xmlCardDAVDoc);
502         PageData.Clear();
503         PageHeader.Clear();
505         // Finally: Get the default-addressbook-URL from the addressbook-home-set address.
506                 
507         curl_easy_reset(conn);
509         if (ServerSSL){
511                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLAddressURL.mb_str(wxConvUTF8));
512                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
513                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
514                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
515                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
516                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);             
517                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
518                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
519                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
520                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
521                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
522                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
523                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query3);
524                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query3));
525                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd3);
527                 if (AllowSelfSign == TRUE){
528                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);
529                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);
530                 }
532                 conncode = (curl_easy_perform(conn));
534                 if (conncode == CURLE_OK){
536                         *ServerResult = TRUE;
537                         AuthPassed = TRUE;
538                         SSLStatus = TRUE;
540                 } else {
542                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
543                                         curl_easy_strerror(conncode));                                  
544                                         
545                         *ServerResult = FALSE;
546                         ValidResponse = FALSE;
547                         
548                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
549                         
550                         return wxT("");                                 
552                 }
554         } else {
555         
556         // No SSL.
557                 
558                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLAddressURL.mb_str(wxConvUTF8));
559                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
560                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
561                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
562                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
563                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
564                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
565                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
566                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
567                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
568                 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
569                 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
570                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
571                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
572                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query3);
573                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query3));
574                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd3);
575                 
576                 conncode = (curl_easy_perform(conn));
577                 
578                 // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG,
579                 // then bring up the conflict resolution form.
580                 
581                 if (EditMode == TRUE){
582                 
583                 }
585                 if (conncode == CURLE_OK){
587                 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
589                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
590                 
591                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
592                                         curl_easy_strerror(conncode));
594                         fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
595                                         GetHTTPCode());
596                                         
597                         ValidResponse = FALSE;
598                                         
599                         return wxT("");
600                 
601                 } else {
603                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
604                                         curl_easy_strerror(conncode));
605                                         
606                         ValidResponse = FALSE;
607                                         
608                         return wxT("");
610                 }
611                 
612         }
613         
614         xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
615                 
616         for (nodeLevel1 = xmlCardDAVDoc->children;
617                 nodeLevel1 != NULL;
618                 nodeLevel1 = nodeLevel1->next)
619         {
621                 for (nodeLevel2 = nodeLevel1->children;
622                         nodeLevel2 != NULL;
623                         nodeLevel2 = nodeLevel2->next)
624                 {
627                         for (nodeLevel3 = nodeLevel2->children;
628                         nodeLevel3 != NULL;
629                         nodeLevel3 = nodeLevel3->next)
630                         {
631                         
632                                 for (nodeLevel4 = nodeLevel3->children;
633                                 nodeLevel4 != NULL;
634                                 nodeLevel4 = nodeLevel4->next)
635                                 {
636                         
637                                         for (nodeLevel5 = nodeLevel4->children;
638                                         nodeLevel5 != NULL;
639                                         nodeLevel5 = nodeLevel5->next)
640                                         {
641                         
642                                                 for (nodeLevel6 = nodeLevel5->children;
643                                                 nodeLevel6 != NULL;
644                                                 nodeLevel6 = nodeLevel6->next)
645                                                 {
646                         
647                                                         if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") ||
648                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") ||
649                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href")
650                                                         ){
651                         
652                                                                 // Found the <href> part so extract the principal URL address.
653                                                                 
654                                                                 for (nodeLevel7 = nodeLevel6->children;
655                                                                 nodeLevel7 != NULL;
656                                                                 nodeLevel7 = nodeLevel7->next)
657                                                                 {
658                                                                 
659                                                                         FinalPrefix = wxString::FromUTF8((const char*)nodeLevel7->content);
660                         
661                                                                 }
662                         
663                                                         }
664                         
665                                                 }
666                         
667                                         }
668                         
669                                 }
670                         
671                         }
672                 
673                 }
674                 
675         }
677         xmlFreeDoc(xmlCardDAVDoc);
678         PageData.Clear();
679         PageHeader.Clear();
681         return FinalPrefix;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy