Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added copyright and license headers on C++ source and header files in the carddav...
[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         // First: Get the principal UID address.
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         conn = curl_easy_init();
50         
51         struct curl_slist *connhd = NULL;
52         struct curl_slist *connhd2 = NULL;
53         struct curl_slist *connhd3 = NULL;
55         connhd = curl_slist_append(connhd, "Depth: 0");
56         connhd = curl_slist_append(connhd, "Prefer: return-minimal");
57         connhd = curl_slist_append(connhd, "Content-Type: application/xml; charset=utf-8");
59         connhd2 = curl_slist_append(connhd2, "Depth: 0");
60         connhd2 = curl_slist_append(connhd2, "Prefer: return-minimal");
61         connhd2 = curl_slist_append(connhd2, "Content-Type: application/xml; charset=utf-8");
63         connhd3 = curl_slist_append(connhd3, "Depth: 1");
64         connhd3 = curl_slist_append(connhd3, "Prefer: return-minimal");
65         connhd3 = curl_slist_append(connhd3, "Content-Type: application/xml; charset=utf-8");
67         struct CardDAVCURLPasser {
68         
69                 CardDAV *Data;
70                 bool HeaderMode = TRUE;
71         
72         } CardDAVHeader, CardDAVFooter;
74         CardDAVHeader.Data = this;
75         CardDAVHeader.HeaderMode = TRUE;
76         
77         CardDAVFooter.Data = this;
78         CardDAVFooter.HeaderMode = FALSE;
80         wxString Data1;
81         wxString Data2;
82         
83         wxString ETag;
84         wxString ETagOriginal;
85         wxString ETagServer;
86         
87         ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
88         ServerAddressSSL = wxT("https://") + ServerAddressURL;
89         ServerAddressNormal = wxT("http://") + ServerAddressURL;
90         
91         ServerAuth = ServerUser + wxT(":") + ServerPass;
92         
93         wxString SAURLPrincipals;
94         wxString SAURLPrincipalURL;
95         wxString SAURLAddressURL;
96         
97         if (ServerSSL){
98         
99                 SAURLPrincipals = ServerAddressSSL + wxT("principals/");
100                 SAURLPrincipalURL = ServerAddressSSL;
101                 SAURLAddressURL = ServerAddressSSL;
102         
103         } else {
104         
105                 SAURLPrincipals = ServerAddressNormal + wxT("principals/");
106                 SAURLPrincipalURL = ServerAddressNormal;
107                 SAURLAddressURL = ServerAddressNormal;
108         
109         }
110         
111         wxString FinalPrefix;
113         struct UploadDataStruc UploadData;
114         
115         // Setup the first query finding out where the principal URL is.
116         
117         const char* query = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
118                 "<D:propfind xmlns:D=\"DAV:\">\n"
119                 " <D:prop>"
120                 "  <D:current-user-principal/>\n"
121                 " </D:prop>"
122                 "</D:propfind>";
124         // Setup the second query finding out where the address book home URL is.
125         
126         const char* query2 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
127         "<D:propfind xmlns:D=\"DAV:\""
128         "  xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"
129         "  <D:prop>\n"
130         "    <C:addressbook-home-set/>\n"
131         "  </D:prop>\n"
132         "</D:propfind>";
133         
134         // Setup the third query finding out where the default address book URL is.
135         
136         const char* query3 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
137         "<D:propfind xmlns:D=\"DAV:\""
138         "  xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"
139         "  <D:prop>\n"
140         "    <C:default-addressbook-URL/>\n"    
141         "  </D:prop>\n"
142         "</D:propfind>";
143         
144         if (ServerSSL){
146                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipals.mb_str(wxConvUTF8));
147                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
148                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
149                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
150                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
151                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);             
152                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
153                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
154                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
155                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
156                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
157                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
158                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
159                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
160                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd);
161                 
162                 if (AllowSelfSign == TRUE){
163                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);
164                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);
165                 }
167                 conncode = (curl_easy_perform(conn));
169                 if (conncode == CURLE_OK){
171                         *ServerResult = TRUE;
172                         AuthPassed = TRUE;
173                         ValidResponse = TRUE;
174                         SSLStatus = TRUE;
176                 } else {
178                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
179                                         curl_easy_strerror(conncode));                                  
180                                         
181                         *ServerResult = FALSE;
182                         
183                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
184                         
185                         return wxT("");                                 
187                 }
189         } else {
190         
191                 // No SSL.
193                 // Do an initial connection (incase of Digest authentication).
195                 PageData.Clear();
196                 PageHeader.Clear();
198                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipals.mb_str(wxConvUTF8));
199                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
200                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
201                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
202                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
203                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
204                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
205                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
206                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
207                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
208                 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
209                 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
210                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
211                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
212                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
213                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
214                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd);
215                 
216                 conncode = (curl_easy_perform(conn));
218                 // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG,
219                 // then bring up the conflict resolution form.
220                 
221                 if (EditMode == TRUE){
222                 
223                 }
225                 if (conncode == CURLE_OK){
227                 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
229                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
230                 
231                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
232                                         curl_easy_strerror(conncode));
234                         fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
235                                         GetHTTPCode());
237                         return wxT("");
238                 
239                 } else {
241                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
242                                         curl_easy_strerror(conncode));
243                         return wxT("");
245                 }
247         }
248         
249         // Process the XML data from the application.
250         
251         xmlDocPtr xmlCardDAVDoc;
252         xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
254         xmlNodePtr nodeLevel1;
255         xmlNodePtr nodeLevel2;
256         xmlNodePtr nodeLevel3;
257         xmlNodePtr nodeLevel4;
258         xmlNodePtr nodeLevel5;
259         xmlNodePtr nodeLevel6;
260         xmlNodePtr nodeLevel7;
261                 
262         for (nodeLevel1 = xmlCardDAVDoc->children;
263                 nodeLevel1 != NULL;
264                 nodeLevel1 = nodeLevel1->next)
265         {
267                 for (nodeLevel2 = nodeLevel1->children;
268                         nodeLevel2 != NULL;
269                         nodeLevel2 = nodeLevel2->next)
270                 {
273                         for (nodeLevel3 = nodeLevel2->children;
274                         nodeLevel3 != NULL;
275                         nodeLevel3 = nodeLevel3->next)
276                         {
277                         
278                                 for (nodeLevel4 = nodeLevel3->children;
279                                 nodeLevel4 != NULL;
280                                 nodeLevel4 = nodeLevel4->next)
281                                 {
282                         
283                                         for (nodeLevel5 = nodeLevel4->children;
284                                         nodeLevel5 != NULL;
285                                         nodeLevel5 = nodeLevel5->next)
286                                         {
287                         
288                                                 for (nodeLevel6 = nodeLevel5->children;
289                                                 nodeLevel6 != NULL;
290                                                 nodeLevel6 = nodeLevel6->next)
291                                                 {
292                         
293                                                         if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") ||
294                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") ||
295                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href")
296                                                         ){
297                         
298                                                                 // Found the <href> part so extract the principal URL address.
299                                                                 
300                                                                 for (nodeLevel7 = nodeLevel6->children;
301                                                                 nodeLevel7 != NULL;
302                                                                 nodeLevel7 = nodeLevel7->next)
303                                                                 {
304                                                                 
305                                                                         SAURLPrincipalURL.Append(wxString::FromUTF8((const char*)nodeLevel7->content));
306                         
307                                                                 }
308                         
309                                                         }
310                         
311                                                 }
312                         
313                                         }
314                         
315                                 }
316                         
317                         }
318                 
319                 }
320                 
321         }
322         
323         xmlFreeDoc(xmlCardDAVDoc);
324         PageData.Clear();
325         PageHeader.Clear();
326                 
327         // Second: Get the addressbook-home-set 
329         curl_easy_reset(conn);
331         if (ServerSSL){
333                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipalURL.mb_str(wxConvUTF8));
334                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
335                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
336                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
337                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
338                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);             
339                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
340                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
341                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
342                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
343                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
344                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
345                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query2);
346                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query2));
347                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd2);
349                 if (AllowSelfSign == TRUE){
350                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);
351                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);
352                 }
354                 conncode = (curl_easy_perform(conn));
356                 if (conncode == CURLE_OK){
358                         *ServerResult = TRUE;
359                         AuthPassed = TRUE;
360                         SSLStatus = TRUE;
362                 } else {
364                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
365                                         curl_easy_strerror(conncode));                                  
366                                         
367                         *ServerResult = FALSE;
368                         ValidResponse = FALSE;
369                         
370                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
371                         
372                         return wxT("");                                 
374                 }
376         } else {
377         
378         // No SSL.
379                 
380                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipalURL.mb_str(wxConvUTF8));
381                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
382                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
383                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
384                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
385                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
386                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
387                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
388                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
389                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
390                 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
391                 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
392                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
393                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
394                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query2);
395                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query2));
396                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd2);
397                 
398                 conncode = (curl_easy_perform(conn));
399                 
400                 // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG,
401                 // then bring up the conflict resolution form.
402                 
403                 if (EditMode == TRUE){
404                 
405                 }
407                 if (conncode == CURLE_OK){
409                 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
411                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
412                 
413                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
414                                         curl_easy_strerror(conncode));
416                         fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
417                                         GetHTTPCode());
418                         
419                         ValidResponse = FALSE;
420                         
421                         return wxT("");
422                 
423                 } else {
425                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
426                                         curl_easy_strerror(conncode));
427                         
428                         ValidResponse = FALSE;
429                         
430                         return wxT("");
432                 }
433                 
434         }
436         xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
437                 
438         for (nodeLevel1 = xmlCardDAVDoc->children;
439                 nodeLevel1 != NULL;
440                 nodeLevel1 = nodeLevel1->next)
441         {
443                 for (nodeLevel2 = nodeLevel1->children;
444                         nodeLevel2 != NULL;
445                         nodeLevel2 = nodeLevel2->next)
446                 {
449                         for (nodeLevel3 = nodeLevel2->children;
450                         nodeLevel3 != NULL;
451                         nodeLevel3 = nodeLevel3->next)
452                         {
453                         
454                                 for (nodeLevel4 = nodeLevel3->children;
455                                 nodeLevel4 != NULL;
456                                 nodeLevel4 = nodeLevel4->next)
457                                 {
458                         
459                                         for (nodeLevel5 = nodeLevel4->children;
460                                         nodeLevel5 != NULL;
461                                         nodeLevel5 = nodeLevel5->next)
462                                         {
463                         
464                                                 for (nodeLevel6 = nodeLevel5->children;
465                                                 nodeLevel6 != NULL;
466                                                 nodeLevel6 = nodeLevel6->next)
467                                                 {
468                         
469                                                         if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") ||
470                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") ||
471                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href")
472                                                         ){
473                         
474                                                                 // Found the <href> part so extract the principal URL address.
475                                                                 
476                                                                 for (nodeLevel7 = nodeLevel6->children;
477                                                                 nodeLevel7 != NULL;
478                                                                 nodeLevel7 = nodeLevel7->next)
479                                                                 {
480                                                                 
481                                                                         SAURLAddressURL.Append(wxString::FromUTF8((const char*)nodeLevel7->content));
482                         
483                                                                 }
484                         
485                                                         }
486                         
487                                                 }
488                         
489                                         }
490                         
491                                 }
492                         
493                         }
494                 
495                 }
496                 
497         }
499         xmlFreeDoc(xmlCardDAVDoc);
500         PageData.Clear();
501         PageHeader.Clear();
503         // Finally: Get the default-addressbook-URL from the addressbook-home-set address.
504                 
505         curl_easy_reset(conn);
507         if (ServerSSL){
509                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLAddressURL.mb_str(wxConvUTF8));
510                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
511                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
512                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
513                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
514                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);             
515                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
516                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
517                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
518                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
519                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
520                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
521                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query3);
522                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query3));
523                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd3);
525                 if (AllowSelfSign == TRUE){
526                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);
527                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);
528                 }
530                 conncode = (curl_easy_perform(conn));
532                 if (conncode == CURLE_OK){
534                         *ServerResult = TRUE;
535                         AuthPassed = TRUE;
536                         SSLStatus = TRUE;
538                 } else {
540                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
541                                         curl_easy_strerror(conncode));                                  
542                                         
543                         *ServerResult = FALSE;
544                         ValidResponse = FALSE;
545                         
546                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
547                         
548                         return wxT("");                                 
550                 }
552         } else {
553         
554         // No SSL.
555                 
556                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLAddressURL.mb_str(wxConvUTF8));
557                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
558                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
559                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
560                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
561                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
562                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
563                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
564                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
565                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
566                 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
567                 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
568                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
569                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
570                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query3);
571                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query3));
572                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd3);
573                 
574                 conncode = (curl_easy_perform(conn));
575                 
576                 // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG,
577                 // then bring up the conflict resolution form.
578                 
579                 if (EditMode == TRUE){
580                 
581                 }
583                 if (conncode == CURLE_OK){
585                 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
587                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
588                 
589                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
590                                         curl_easy_strerror(conncode));
592                         fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
593                                         GetHTTPCode());
594                                         
595                         ValidResponse = FALSE;
596                                         
597                         return wxT("");
598                 
599                 } else {
601                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
602                                         curl_easy_strerror(conncode));
603                                         
604                         ValidResponse = FALSE;
605                                         
606                         return wxT("");
608                 }
609                 
610         }
611         
612         xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
613                 
614         for (nodeLevel1 = xmlCardDAVDoc->children;
615                 nodeLevel1 != NULL;
616                 nodeLevel1 = nodeLevel1->next)
617         {
619                 for (nodeLevel2 = nodeLevel1->children;
620                         nodeLevel2 != NULL;
621                         nodeLevel2 = nodeLevel2->next)
622                 {
625                         for (nodeLevel3 = nodeLevel2->children;
626                         nodeLevel3 != NULL;
627                         nodeLevel3 = nodeLevel3->next)
628                         {
629                         
630                                 for (nodeLevel4 = nodeLevel3->children;
631                                 nodeLevel4 != NULL;
632                                 nodeLevel4 = nodeLevel4->next)
633                                 {
634                         
635                                         for (nodeLevel5 = nodeLevel4->children;
636                                         nodeLevel5 != NULL;
637                                         nodeLevel5 = nodeLevel5->next)
638                                         {
639                         
640                                                 for (nodeLevel6 = nodeLevel5->children;
641                                                 nodeLevel6 != NULL;
642                                                 nodeLevel6 = nodeLevel6->next)
643                                                 {
644                         
645                                                         if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") ||
646                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") ||
647                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href")
648                                                         ){
649                         
650                                                                 // Found the <href> part so extract the principal URL address.
651                                                                 
652                                                                 for (nodeLevel7 = nodeLevel6->children;
653                                                                 nodeLevel7 != NULL;
654                                                                 nodeLevel7 = nodeLevel7->next)
655                                                                 {
656                                                                 
657                                                                         FinalPrefix = wxString::FromUTF8((const char*)nodeLevel7->content);
658                         
659                                                                 }
660                         
661                                                         }
662                         
663                                                 }
664                         
665                                         }
666                         
667                                 }
668                         
669                         }
670                 
671                 }
672                 
673         }
675         xmlFreeDoc(xmlCardDAVDoc);
676         PageData.Clear();
677         PageHeader.Clear();
679         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