libidav/xml.c

changeset 736
40be8db6fe45
parent 666
97061483d06e
child 747
efbd59642577
equal deleted inserted replaced
735:74a6e2d4fb1f 736:40be8db6fe45
238 node = node->next; 238 node = node->next;
239 } 239 }
240 return NULL; 240 return NULL;
241 } 241 }
242 242
243 DavXmlNode* dav_text_node(DavSession *sn, char *text) { 243 DavXmlNode* dav_text_node(DavSession *sn, const char *text) {
244 UcxMempool *mp = sn->mp; 244 UcxMempool *mp = sn->mp;
245 DavXmlNode *newxn = ucx_mempool_calloc(mp, 1, sizeof(DavXmlNode)); 245 DavXmlNode *newxn = ucx_mempool_calloc(mp, 1, sizeof(DavXmlNode));
246 newxn->type = DAV_XML_TEXT; 246 newxn->type = DAV_XML_TEXT;
247 sstr_t content = sstrdup_a(mp->allocator, sstr(text)); 247 sstr_t content = scstrdup_a(mp->allocator, scstr(text));
248 newxn->content = content.ptr; 248 newxn->content = content.ptr;
249 newxn->contentlength = content.length; 249 newxn->contentlength = content.length;
250 return newxn; 250 return newxn;
251 } 251 }
252 252
253 DavXmlNode* dav_text_element(DavSession *sn, const char *ns, const char *name, const char *text) {
254 UcxMempool *mp = sn->mp;
255 DavXmlNode *newelm = ucx_mempool_calloc(mp, 1, sizeof(DavXmlNode));
256 newelm->type = DAV_XML_ELEMENT;
257 newelm->namespace = scstrdup_a(mp->allocator, scstr(ns)).ptr;
258 newelm->name = scstrdup_a(mp->allocator, scstr(name)).ptr;
259 newelm->children = dav_text_node(sn, text);
260 return newelm;
261 }
262
263 static void dav_free_xml_node_a(UcxAllocator *a, DavXmlNode *node) {
264 if(node->name) alfree(a, node->name);
265 if(node->namespace) alfree(a, node->namespace);
266 if(node->content) alfree(a, node->content);
267 DavXmlAttr *attr = node->attributes;
268 while(attr) {
269 if(attr->name) alfree(a, attr->name);
270 if(attr->value) alfree(a, attr->value);
271 attr = attr->next;
272 }
273 DavXmlNode *children = node->children;
274 while(children) {
275 DavXmlNode *next_ch = children->next;
276 dav_free_xml_node_a(a, children);
277 children = next_ch;
278 }
279 alfree(a, node);
280 }
281
282 void dav_free_xml_node_sn(DavSession *sn, DavXmlNode *node) {
283 dav_free_xml_node_a(sn->mp->allocator, node);
284 }
285
286 void dav_free_xml_node(DavXmlNode *node) {
287 dav_free_xml_node_a(ucx_default_allocator(), node);
288 }
253 289
254 DavXmlAttr* dav_copy_xml_attr(DavXmlAttr *attr) { 290 DavXmlAttr* dav_copy_xml_attr(DavXmlAttr *attr) {
255 if(!attr) { 291 if(!attr) {
256 return NULL; 292 return NULL;
257 } 293 }

mercurial