src/server/webdav/davparser.cpp

changeset 107
7e81699d1f77
parent 106
b122f34ddc80
child 108
2a394ccdd778
equal deleted inserted replaced
106:b122f34ddc80 107:7e81699d1f77
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "davparser.h"
30
31 #include "../util/pool.h"
32 #include "../util/pblock.h"
33
34 #include "saxhandler.h"
35
36 #include <xercesc/sax2/SAX2XMLReader.hpp>
37 #include <xercesc/sax2/XMLReaderFactory.hpp>
38 #include <xercesc/sax2/DefaultHandler.hpp>
39 #include <xercesc/util/XMLString.hpp>
40 #include <xercesc/framework/MemBufInputSource.hpp>
41
42 XERCES_CPP_NAMESPACE_USE;
43
44 int xcinit = 0;
45
46 PropfindRequest* dav_parse_propfind(
47 Session *sn,
48 Request *rq,
49 char *xml,
50 size_t len)
51 {
52 if(!xcinit) {
53 /* TODO: create webdav module init function */
54 XMLPlatformUtils::Initialize();
55 xcinit = 1;
56 }
57 PropfindRequest *davrq = (PropfindRequest*)pool_calloc(
58 sn->pool,
59 1,
60 sizeof(PropfindRequest));
61 davrq->nsmap = xmlnsmap_create(sn->pool);
62 xmlnsmap_put(davrq->nsmap, (char*)"DAV:");
63 davrq->allprop = 0;
64 davrq->propname = 0;
65 davrq->prop = 0;
66 davrq->properties = NULL;
67 davrq->forbiddenProps = NULL;
68 davrq->notFoundProps = NULL;
69 davrq->mgrdata = NULL;
70 // create xml parser
71 SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
72 parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
73
74 PropfindHandler handler(davrq, sn->pool);
75 parser->setContentHandler(&handler);
76 parser->setErrorHandler(&handler);
77
78 MemBufInputSource source((XMLByte*)xml, (XMLSize_t)len, "wsid");
79 try {
80 parser->parse(source);
81 }
82 catch (const XMLException& e) {
83 printf("XMLException\n");
84
85 }
86 catch (const SAXParseException& e) {
87 printf("SAXParseException\n");
88
89 }
90 catch (...) {
91 printf("davaparser Exception\n");
92 }
93
94 delete parser;
95
96
97 return davrq;
98 }
99
100 void dav_free_propfind(PropfindRequest *rq) {
101 ucx_list_free(rq->forbiddenProps);
102 ucx_list_free(rq->notFoundProps);
103 //ucx_dlist_free(rq->properties); // uses pool
104 sbuf_free(rq->out);
105 }
106
107 ProppatchRequest* dav_parse_proppatch(
108 Session *sn,
109 Request *rq,
110 char *xml,
111 size_t len)
112 {
113 if(!xcinit) {
114 /* TODO: create webdav module init function */
115 XMLPlatformUtils::Initialize();
116 xcinit = 1;
117 }
118 ProppatchRequest *davrq = (ProppatchRequest*)pool_calloc(
119 sn->pool,
120 1,
121 sizeof(PropfindRequest));
122 davrq->nsmap = xmlnsmap_create(sn->pool);
123 xmlnsmap_put(davrq->nsmap, (char*)"DAV:");
124
125
126 // create xml parser
127 SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
128 parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
129
130 ProppatchHandler handler(davrq, sn->pool);
131 parser->setContentHandler(&handler);
132 parser->setErrorHandler(&handler);
133
134 MemBufInputSource source((XMLByte*)xml, (XMLSize_t)len, "wsid");
135 try {
136 parser->parse(source);
137 }
138 catch (const XMLException& e) {
139 printf("XMLException\n");
140
141 }
142 catch (const SAXParseException& e) {
143 printf("SAXParseException\n");
144
145 }
146 catch (...) {
147 printf("davaparser Exception\n");
148 }
149
150 delete parser;
151
152
153 return davrq;
154 }
155
156 void dav_free_proppatch(ProppatchRequest *rq) {
157 ucx_list_free(rq->removeProps);
158 ucx_list_free(rq->setProps);
159 xmlnsmap_free(rq->nsmap);
160 ucx_map_free(rq->propstat->map);
161 ucx_list_free(rq->propstat->okprop);
162 }

mercurial