Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added separate C++ file for processing XML data within the CalDAV object.
[xestiacalendar/.git] / source / objects / CalDAV / CalDAV-XMLProcessing.cpp
1 // CalDAV-XMLProcessing.cpp - CalDAV Connection Object - XML Processing.
2 //
3 // (c) 2016 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
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 Calendar. If not, see <http://www.gnu.org/licenses/>
19 #include "CalDAV.h"
21 using namespace std;
22  
23 string CalDAV::ProcessXMLUserPrincipal(){
25         string UserPrincipalURI;
26         
27         xmlDocPtr xmlCalDAVDoc;
28         xmlCalDAVDoc = xmlReadMemory(ServerData.c_str(), (int)ServerData.size(), "noname.xml", NULL, 0);
30         xmlNodePtr NodeSeek;
31         bool NodeFound = false;
32         
33         // Start with the first node, look for multistatus.
34         
35         for (NodeSeek = xmlCalDAVDoc->children;
36                 NodeSeek != NULL;
37                 NodeSeek = NodeSeek->next)
38         {
39         
40                 if (!xmlStrcmp(NodeSeek->name, (const xmlChar *)"multistatus") ||
41                         !xmlStrcmp(NodeSeek->name, (const xmlChar *)"d:multistatus") ||
42                         !xmlStrcmp(NodeSeek->name, (const xmlChar *)"D:multistatus")
43                 ){
44                         
45                         NodeFound = true;
46                         break;
47                         
48                 }
49                 
50         }
51         
52         // Look for response.
54         if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
55         NodeFound = MatchXMLName(&NodeSeek, "response");
57         // Look for propstat.
58         
59         if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
60         NodeFound = MatchXMLName(&NodeSeek, "propstat");
62         // Look for prop.
63         
64         if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
65         NodeFound = MatchXMLName(&NodeSeek, "prop");
66         
67         // Look for current-user-principal.
68         
69         if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
70         NodeFound = MatchXMLName(&NodeSeek, "current-user-principal");
71         
72         // Look for href.       
73         
74         if (NodeFound == false){ return UserPrincipalURI; } else { NodeFound = false; }
75         NodeFound = MatchXMLName(&NodeSeek, "href");
77         // Get the data from href.
78         
79         UserPrincipalURI = FetchXMLData(&NodeSeek);
80         
81         xmlFreeDoc(xmlCalDAVDoc);
82         
83         return UserPrincipalURI;
84         
85 }
87 bool CalDAV::MatchXMLName(xmlNodePtr *NodePtr, string NodeName){
89         string NodeNameSmallD = "d:" + NodeName;
90         string NodeNameLargeD = "D:" + NodeName;
91         
92         for ((*NodePtr) = (*NodePtr)->children;
93                 (*NodePtr) != NULL;
94                 (*NodePtr) = (*NodePtr)->next)
95         {
96         
97                 if (!xmlStrcmp((*NodePtr)->name, (const xmlChar *)NodeName.c_str()) ||
98                         !xmlStrcmp((*NodePtr)->name, (const xmlChar *)NodeNameSmallD.c_str()) ||
99                         !xmlStrcmp((*NodePtr)->name, (const xmlChar *)NodeNameLargeD.c_str())
100                 ){
101                         
102                         return true;
103                         
104                 }
105                 
106         }
107         
108         return false;
109         
112 string CalDAV::FetchXMLData(xmlNodePtr *NodePtr){
114         for ((*NodePtr) = (*NodePtr)->children;
115                 (*NodePtr) != NULL;
116                 (*NodePtr) = (*NodePtr)->next)
117         {
118                                                                 
119                 return (const char*)(*NodePtr)->content;
120                         
121         }
122         
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