Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Split carddav/carddav.cpp down into 8 files to make it manageable.
[xestiaab/.git] / source / carddav / carddav-defaultadrurl.cpp
1 #include "carddav.h"
2 #include "../version.h"
3 #include <wx/wx.h>
4 #include <wx/tokenzr.h>
5 #include <wx/ffile.h>
6 #include <libxml/parser.h>
7 #include <libxml/tree.h>
8 #include <map>
9 #include <thread>
10 #include "../vcard/vcard.h"
11 #include "../common/dirs.h"
13 wxString CardDAV::GetDefaultAddressBookURL(){
15         // First: Get the principal UID address.
16         
17         PageData.Clear();
18         PageHeader.Clear();
20         SSLStatus = TRUE;
21         AuthPassed = TRUE;
22         AbortConnection = FALSE;
24         CURL *conn;
25         CURLcode conncode;
26         wxString ServerAddressURL;
27         wxString ServerAuth;
28         wxString ServerAddressSSL;
29         wxString ServerAddressNormal;   
31         conn = curl_easy_init();
32         
33         struct curl_slist *connhd = NULL;
34         struct curl_slist *connhd2 = NULL;
35         struct curl_slist *connhd3 = NULL;
37         connhd = curl_slist_append(connhd, "Depth: 0");
38         connhd = curl_slist_append(connhd, "Prefer: return-minimal");
39         connhd = curl_slist_append(connhd, "Content-Type: application/xml; charset=utf-8");
41         connhd2 = curl_slist_append(connhd2, "Depth: 0");
42         connhd2 = curl_slist_append(connhd2, "Prefer: return-minimal");
43         connhd2 = curl_slist_append(connhd2, "Content-Type: application/xml; charset=utf-8");
45         connhd3 = curl_slist_append(connhd3, "Depth: 1");
46         connhd3 = curl_slist_append(connhd3, "Prefer: return-minimal");
47         connhd3 = curl_slist_append(connhd3, "Content-Type: application/xml; charset=utf-8");
49         struct CardDAVCURLPasser {
50         
51                 CardDAV *Data;
52                 bool HeaderMode = TRUE;
53         
54         } CardDAVHeader, CardDAVFooter;
56         CardDAVHeader.Data = this;
57         CardDAVHeader.HeaderMode = TRUE;
58         
59         CardDAVFooter.Data = this;
60         CardDAVFooter.HeaderMode = FALSE;
62         wxString Data1;
63         wxString Data2;
64         
65         wxString ETag;
66         wxString ETagOriginal;
67         wxString ETagServer;
68         
69         ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
70         ServerAddressSSL = wxT("https://") + ServerAddressURL;
71         ServerAddressNormal = wxT("http://") + ServerAddressURL;
72         
73         ServerAuth = ServerUser + wxT(":") + ServerPass;
74         
75         wxString SAURLPrincipals;
76         wxString SAURLPrincipalURL;
77         wxString SAURLAddressURL;
78         
79         if (ServerSSL){
80         
81                 SAURLPrincipals = ServerAddressSSL + wxT("principals/");
82                 SAURLPrincipalURL = ServerAddressSSL;
83                 SAURLAddressURL = ServerAddressSSL;
84         
85         } else {
86         
87                 SAURLPrincipals = ServerAddressNormal + wxT("principals/");
88                 SAURLPrincipalURL = ServerAddressNormal;
89                 SAURLAddressURL = ServerAddressNormal;
90         
91         }
92         
93         wxString FinalPrefix;
95         struct UploadDataStruc UploadData;
96         
97         // Setup the first query finding out where the principal URL is.
98         
99         const char* query = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
100                 "<D:propfind xmlns:D=\"DAV:\">\n"
101                 " <D:prop>"
102                 "  <D:current-user-principal/>\n"
103                 " </D:prop>"
104                 "</D:propfind>";
106         // Setup the second query finding out where the address book home URL is.
107         
108         const char* query2 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
109         "<D:propfind xmlns:D=\"DAV:\""
110         "  xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"
111         "  <D:prop>\n"
112         "    <C:addressbook-home-set/>\n"
113         "  </D:prop>\n"
114         "</D:propfind>";
115         
116         // Setup the third query finding out where the default address book URL is.
117         
118         const char* query3 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
119         "<D:propfind xmlns:D=\"DAV:\""
120         "  xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"
121         "  <D:prop>\n"
122         "    <C:default-addressbook-URL/>\n"    
123         "  </D:prop>\n"
124         "</D:propfind>";
125         
126         if (ServerSSL){
128                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipals.mb_str(wxConvUTF8));
129                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
130                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
131                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
132                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
133                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);             
134                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
135                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
136                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
137                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
138                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
139                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
140                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
141                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
142                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd);
143                 
144                 if (AllowSelfSign == TRUE){
145                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);
146                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);
147                 }
149                 conncode = (curl_easy_perform(conn));
151                 if (conncode == CURLE_OK){
153                         *ServerResult = TRUE;
154                         AuthPassed = TRUE;
155                         ValidResponse = TRUE;
156                         SSLStatus = TRUE;
158                 } else {
160                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
161                                         curl_easy_strerror(conncode));                                  
162                                         
163                         *ServerResult = FALSE;
164                         
165                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
166                         
167                         return wxT("");                                 
169                 }
171         } else {
172         
173                 // No SSL.
175                 // Do an initial connection (incase of Digest authentication).
177                 PageData.Clear();
178                 PageHeader.Clear();
180                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipals.mb_str(wxConvUTF8));
181                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
182                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
183                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
184                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
185                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
186                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
187                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
188                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
189                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
190                 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
191                 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
192                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
193                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
194                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);
195                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));
196                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd);
197                 
198                 conncode = (curl_easy_perform(conn));
200                 // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG,
201                 // then bring up the conflict resolution form.
202                 
203                 if (EditMode == TRUE){
204                 
205                 }
207                 if (conncode == CURLE_OK){
209                 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
211                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
212                 
213                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
214                                         curl_easy_strerror(conncode));
216                         fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
217                                         GetHTTPCode());
219                         return wxT("");
220                 
221                 } else {
223                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
224                                         curl_easy_strerror(conncode));
225                         return wxT("");
227                 }
229         }
230         
231         // Process the XML data from the application.
232         
233         xmlDocPtr xmlCardDAVDoc;
234         xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
236         xmlNodePtr nodeLevel1;
237         xmlNodePtr nodeLevel2;
238         xmlNodePtr nodeLevel3;
239         xmlNodePtr nodeLevel4;
240         xmlNodePtr nodeLevel5;
241         xmlNodePtr nodeLevel6;
242         xmlNodePtr nodeLevel7;
243                 
244         for (nodeLevel1 = xmlCardDAVDoc->children;
245                 nodeLevel1 != NULL;
246                 nodeLevel1 = nodeLevel1->next)
247         {
249                 for (nodeLevel2 = nodeLevel1->children;
250                         nodeLevel2 != NULL;
251                         nodeLevel2 = nodeLevel2->next)
252                 {
255                         for (nodeLevel3 = nodeLevel2->children;
256                         nodeLevel3 != NULL;
257                         nodeLevel3 = nodeLevel3->next)
258                         {
259                         
260                                 for (nodeLevel4 = nodeLevel3->children;
261                                 nodeLevel4 != NULL;
262                                 nodeLevel4 = nodeLevel4->next)
263                                 {
264                         
265                                         for (nodeLevel5 = nodeLevel4->children;
266                                         nodeLevel5 != NULL;
267                                         nodeLevel5 = nodeLevel5->next)
268                                         {
269                         
270                                                 for (nodeLevel6 = nodeLevel5->children;
271                                                 nodeLevel6 != NULL;
272                                                 nodeLevel6 = nodeLevel6->next)
273                                                 {
274                         
275                                                         if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") ||
276                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") ||
277                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href")
278                                                         ){
279                         
280                                                                 // Found the <href> part so extract the principal URL address.
281                                                                 
282                                                                 for (nodeLevel7 = nodeLevel6->children;
283                                                                 nodeLevel7 != NULL;
284                                                                 nodeLevel7 = nodeLevel7->next)
285                                                                 {
286                                                                 
287                                                                         SAURLPrincipalURL.Append(wxString::FromUTF8((const char*)nodeLevel7->content));
288                         
289                                                                 }
290                         
291                                                         }
292                         
293                                                 }
294                         
295                                         }
296                         
297                                 }
298                         
299                         }
300                 
301                 }
302                 
303         }
304         
305         xmlFreeDoc(xmlCardDAVDoc);
306         PageData.Clear();
307         PageHeader.Clear();
308                 
309         // Second: Get the addressbook-home-set 
311         curl_easy_reset(conn);
313         if (ServerSSL){
315                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipalURL.mb_str(wxConvUTF8));
316                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
317                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
318                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
319                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
320                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);             
321                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
322                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
323                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
324                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
325                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
326                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
327                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query2);
328                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query2));
329                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd2);
331                 if (AllowSelfSign == TRUE){
332                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);
333                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);
334                 }
336                 conncode = (curl_easy_perform(conn));
338                 if (conncode == CURLE_OK){
340                         *ServerResult = TRUE;
341                         AuthPassed = TRUE;
342                         SSLStatus = TRUE;
344                 } else {
346                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
347                                         curl_easy_strerror(conncode));                                  
348                                         
349                         *ServerResult = FALSE;
350                         ValidResponse = FALSE;
351                         
352                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
353                         
354                         return wxT("");                                 
356                 }
358         } else {
359         
360         // No SSL.
361                 
362                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipalURL.mb_str(wxConvUTF8));
363                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
364                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
365                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
366                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
367                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
368                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
369                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
370                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
371                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
372                 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
373                 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
374                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
375                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
376                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query2);
377                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query2));
378                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd2);
379                 
380                 conncode = (curl_easy_perform(conn));
381                 
382                 // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG,
383                 // then bring up the conflict resolution form.
384                 
385                 if (EditMode == TRUE){
386                 
387                 }
389                 if (conncode == CURLE_OK){
391                 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
393                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
394                 
395                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
396                                         curl_easy_strerror(conncode));
398                         fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
399                                         GetHTTPCode());
400                         
401                         ValidResponse = FALSE;
402                         
403                         return wxT("");
404                 
405                 } else {
407                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
408                                         curl_easy_strerror(conncode));
409                         
410                         ValidResponse = FALSE;
411                         
412                         return wxT("");
414                 }
415                 
416         }
418         xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
419                 
420         for (nodeLevel1 = xmlCardDAVDoc->children;
421                 nodeLevel1 != NULL;
422                 nodeLevel1 = nodeLevel1->next)
423         {
425                 for (nodeLevel2 = nodeLevel1->children;
426                         nodeLevel2 != NULL;
427                         nodeLevel2 = nodeLevel2->next)
428                 {
431                         for (nodeLevel3 = nodeLevel2->children;
432                         nodeLevel3 != NULL;
433                         nodeLevel3 = nodeLevel3->next)
434                         {
435                         
436                                 for (nodeLevel4 = nodeLevel3->children;
437                                 nodeLevel4 != NULL;
438                                 nodeLevel4 = nodeLevel4->next)
439                                 {
440                         
441                                         for (nodeLevel5 = nodeLevel4->children;
442                                         nodeLevel5 != NULL;
443                                         nodeLevel5 = nodeLevel5->next)
444                                         {
445                         
446                                                 for (nodeLevel6 = nodeLevel5->children;
447                                                 nodeLevel6 != NULL;
448                                                 nodeLevel6 = nodeLevel6->next)
449                                                 {
450                         
451                                                         if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") ||
452                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") ||
453                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href")
454                                                         ){
455                         
456                                                                 // Found the <href> part so extract the principal URL address.
457                                                                 
458                                                                 for (nodeLevel7 = nodeLevel6->children;
459                                                                 nodeLevel7 != NULL;
460                                                                 nodeLevel7 = nodeLevel7->next)
461                                                                 {
462                                                                 
463                                                                         SAURLAddressURL.Append(wxString::FromUTF8((const char*)nodeLevel7->content));
464                         
465                                                                 }
466                         
467                                                         }
468                         
469                                                 }
470                         
471                                         }
472                         
473                                 }
474                         
475                         }
476                 
477                 }
478                 
479         }
481         xmlFreeDoc(xmlCardDAVDoc);
482         PageData.Clear();
483         PageHeader.Clear();
485         // Finally: Get the default-addressbook-URL from the addressbook-home-set address.
486                 
487         curl_easy_reset(conn);
489         if (ServerSSL){
491                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLAddressURL.mb_str(wxConvUTF8));
492                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
493                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
494                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
495                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
496                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);             
497                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
498                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
499                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
500                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
501                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
502                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
503                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query3);
504                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query3));
505                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd3);
507                 if (AllowSelfSign == TRUE){
508                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);
509                         curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);
510                 }
512                 conncode = (curl_easy_perform(conn));
514                 if (conncode == CURLE_OK){
516                         *ServerResult = TRUE;
517                         AuthPassed = TRUE;
518                         SSLStatus = TRUE;
520                 } else {
522                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
523                                         curl_easy_strerror(conncode));                                  
524                                         
525                         *ServerResult = FALSE;
526                         ValidResponse = FALSE;
527                         
528                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
529                         
530                         return wxT("");                                 
532                 }
534         } else {
535         
536         // No SSL.
537                 
538                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLAddressURL.mb_str(wxConvUTF8));
539                 curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
540                 curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
541                 curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);
542                 curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE);
543                 curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
544                 curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));
545                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
546                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
547                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
548                 curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this);
549                 curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc);
550                 curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
551                 curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");
552                 curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query3);
553                 curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query3));
554                 curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd3);
555                 
556                 conncode = (curl_easy_perform(conn));
557                 
558                 // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG,
559                 // then bring up the conflict resolution form.
560                 
561                 if (EditMode == TRUE){
562                 
563                 }
565                 if (conncode == CURLE_OK){
567                 } else if (conncode == CURLE_HTTP_RETURNED_ERROR){
569                         curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);
570                 
571                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
572                                         curl_easy_strerror(conncode));
574                         fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",
575                                         GetHTTPCode());
576                                         
577                         ValidResponse = FALSE;
578                                         
579                         return wxT("");
580                 
581                 } else {
583                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
584                                         curl_easy_strerror(conncode));
585                                         
586                         ValidResponse = FALSE;
587                                         
588                         return wxT("");
590                 }
591                 
592         }
593         
594         xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0);
595                 
596         for (nodeLevel1 = xmlCardDAVDoc->children;
597                 nodeLevel1 != NULL;
598                 nodeLevel1 = nodeLevel1->next)
599         {
601                 for (nodeLevel2 = nodeLevel1->children;
602                         nodeLevel2 != NULL;
603                         nodeLevel2 = nodeLevel2->next)
604                 {
607                         for (nodeLevel3 = nodeLevel2->children;
608                         nodeLevel3 != NULL;
609                         nodeLevel3 = nodeLevel3->next)
610                         {
611                         
612                                 for (nodeLevel4 = nodeLevel3->children;
613                                 nodeLevel4 != NULL;
614                                 nodeLevel4 = nodeLevel4->next)
615                                 {
616                         
617                                         for (nodeLevel5 = nodeLevel4->children;
618                                         nodeLevel5 != NULL;
619                                         nodeLevel5 = nodeLevel5->next)
620                                         {
621                         
622                                                 for (nodeLevel6 = nodeLevel5->children;
623                                                 nodeLevel6 != NULL;
624                                                 nodeLevel6 = nodeLevel6->next)
625                                                 {
626                         
627                                                         if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") ||
628                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") ||
629                                                         !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href")
630                                                         ){
631                         
632                                                                 // Found the <href> part so extract the principal URL address.
633                                                                 
634                                                                 for (nodeLevel7 = nodeLevel6->children;
635                                                                 nodeLevel7 != NULL;
636                                                                 nodeLevel7 = nodeLevel7->next)
637                                                                 {
638                                                                 
639                                                                         FinalPrefix = wxString::FromUTF8((const char*)nodeLevel7->content);
640                         
641                                                                 }
642                         
643                                                         }
644                         
645                                                 }
646                         
647                                         }
648                         
649                                 }
650                         
651                         }
652                 
653                 }
654                 
655         }
657         xmlFreeDoc(xmlCardDAVDoc);
658         PageData.Clear();
659         PageHeader.Clear();
661         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