DTS Application Library  0.2.3
Application library containing referenced objects and interfaces to common libraries
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
libxml2.c
Go to the documentation of this file.
1 
7 #include <string.h>
8 #include <stdint.h>
9 #ifdef __WIN32__
10 #include <sec_api/string_s.h>
11 #endif
12 
13 #include <libxml/tree.h>
14 #include <libxml/parser.h>
15 #include <libxml/xpath.h>
16 #include <libxml/xpathInternals.h>
17 
18 #include "include/priv_xml.h"
19 #include "include/dtsapp.h"
20 
22 struct xml_node_iter {
26  int curpos;
28  int cnt;
29 };
30 
33 struct xml_search {
35  struct xml_doc *xmldoc;
37  xmlXPathObjectPtr xpathObj;
39  struct bucket_list *nodes;
40 };
41 
42 static void *xml_has_init_parser = NULL;
43 
46 void xml_free_buffer(void *data) {
47  struct xml_buffer *xb = data;
48  xmlFree(xb->buffer);
49 }
50 
51 static void free_xmlsearch(void *data) {
52  struct xml_search *xs = data;
53  objunref(xs->xmldoc);
54  objunref(xs->nodes);
55  xmlXPathFreeObject(xs->xpathObj);
56 }
57 
58 static void free_parser(void *data) {
59  xmlCleanupParser();
60 }
61 
62 static void free_xmlnode(void *data) {
63  struct xml_node *ninfo = data;
64 
65  if (ninfo->attrs) {
66  objunref(ninfo->attrs);
67  }
68  if (ninfo->name) {
69  free((char *)ninfo->name);
70  }
71  if (ninfo->key) {
72  free((char *)ninfo->key);
73  }
74  if (ninfo->value) {
75  free((char *)ninfo->value);
76  }
77 }
78 
79 static void free_xmldata(void *data) {
80  struct xml_doc *xmldata = data;
81 
82  if (xmldata->xpathCtx) {
83  xmlXPathFreeContext(xmldata->xpathCtx);
84  }
85  if (xmldata->doc) {
86  xmlFreeDoc(xmldata->doc);
87  }
88  if (xmldata->ValidCtxt) {
89  xmlFreeValidCtxt(xmldata->ValidCtxt);
90  }
91  xml_close();
92 }
93 
94 static int32_t node_hash(const void *data, int key) {
95  int ret;
96  const struct xml_node *ni = data;
97  const char *hashkey = (key) ? data : ni->key;
98 
99  if (hashkey) {
100  ret = jenhash(hashkey, strlen(hashkey), 0);
101  } else {
102  ret = jenhash(ni, sizeof(ni), 0);
103  }
104  return(ret);
105 }
106 
107 static int32_t attr_hash(const void *data, int key) {
108  int ret;
109  const struct xml_attr *ai = data;
110  const char *hashkey = (key) ? data : ai->name;
111 
112  ret = jenhash(hashkey, strlen(hashkey), 0);
113 
114  return(ret);
115 }
116 
117 static struct xml_doc *xml_setup_parse(struct xml_doc *xmldata, int validate) {
118  if (validate) {
119  if (!(xmldata->ValidCtxt = xmlNewValidCtxt())) {
120  objunref(xmldata);
121  return NULL;
122  }
123  if (!xmlValidateDocument(xmldata->ValidCtxt, xmldata->doc)) {
124  objunref(xmldata);
125  return NULL;
126  }
127  /*xmlValidateDocumentFinal(xmldata->ValidCtxt, xmldata->doc);*/
128  }
129 
130  if (!(xmldata->root = xmlDocGetRootElement(xmldata->doc))) {
131  objunref(xmldata);
132  return NULL;
133  }
134 
135  if (!(xmldata->xpathCtx = xmlXPathNewContext(xmldata->doc))) {
136  objunref(xmldata);
137  return NULL;
138  }
139  return xmldata;
140 }
141 
146 extern struct xml_doc *xml_loaddoc(const char *docfile, int validate) {
147  struct xml_doc *xmldata;
148 
149  xml_init();
150 
151  if (!(xmldata = objalloc(sizeof(*xmldata), free_xmldata))) {
152  return NULL;
153  }
154 
155  if (!(xmldata->doc = xmlParseFile(docfile))) {
156  objunref(xmldata);
157  return NULL;
158  }
159 
160  return xml_setup_parse(xmldata, validate);
161 }
162 
168 extern struct xml_doc *xml_loadbuf(const uint8_t *buffer, uint32_t len, int validate) {
169  struct xml_doc *xmldata;
170  int flags;
171 
172  xml_init();
173 
174  if (!(xmldata = objalloc(sizeof(*xmldata), free_xmldata))) {
175  return NULL;
176  }
177 
178  if (validate) {
179  flags = XML_PARSE_DTDLOAD | XML_PARSE_DTDVALID;
180  } else {
181  flags = XML_PARSE_DTDVALID;
182  }
183 
184  if (!(xmldata->doc = xmlReadMemory((const char *)buffer, len, NULL, NULL, flags))) {
185  objunref(xmldata);
186  return NULL;
187  }
188  return xml_setup_parse(xmldata, 0);
189 }
190 
191 static struct xml_node *xml_nodetohash(struct xml_doc *xmldoc, xmlNodePtr node, const char *attrkey) {
192  struct xml_node *ninfo;
193  struct xml_attr *ainfo;
194  xmlChar *xmlstr;
195  xmlAttr *attrs;
196 
197  if (!(ninfo = objalloc(sizeof(*ninfo), free_xmlnode))) {
198  return NULL;
199  }
200  ninfo->attrs = NULL;
201 
202  if (!(ninfo->attrs = create_bucketlist(0, attr_hash))) {
203  objunref(ninfo);
204  return NULL;
205  }
206 
207  ALLOC_CONST(ninfo->name, (const char *)node->name);
208  xmlstr = xmlNodeListGetString(xmldoc->doc, node->xmlChildrenNode, 1);
209  ALLOC_CONST(ninfo->value, (const char *)xmlstr);
210  xmlFree(xmlstr);
211  ninfo->nodeptr = node;
212 
213  attrs = node->properties;
214  while(attrs && attrs->name && attrs->children) {
215  if (!(ainfo = objalloc(sizeof(*ainfo), NULL))) {
216  objunref(ninfo);
217  return NULL;
218  }
219  ALLOC_CONST(ainfo->name, (const char *)attrs->name);
220  xmlstr = xmlNodeListGetString(xmldoc->doc, attrs->children, 1);
221  ALLOC_CONST(ainfo->value, (const char *)xmlstr);
222  if (attrkey && !strcmp((const char *)attrs->name, (const char *)attrkey)) {
223  ALLOC_CONST(ninfo->key, (const char *)xmlstr);
224  }
225  xmlFree(xmlstr);
226  addtobucket(ninfo->attrs, ainfo);
227  objunref(ainfo);
228  attrs = attrs->next;
229  }
230  if (!attrkey && ninfo->value) {
231  ALLOC_CONST(ninfo->key, ninfo->value);
232  }
233  return ninfo;
234 }
235 
236 static struct xml_node *xml_gethash(struct xml_search *xpsearch, int i, const char *attrkey) {
237  xmlNodePtr node;
238  xmlNodeSetPtr nodeset;
239  struct xml_node *xn;
240 
241  if (!objref(xpsearch)) {
242  return NULL;
243  }
244 
245  objlock(xpsearch->xmldoc);
246  objlock(xpsearch);
247  if (!(nodeset = xpsearch->xpathObj->nodesetval)) {
248  objunlock(xpsearch);
249  objunlock(xpsearch->xmldoc);
250  objunref(xpsearch);
251  return NULL;
252  }
253 
254  if (!(node = nodeset->nodeTab[i])) {
255  objunlock(xpsearch);
256  objunlock(xpsearch->xmldoc);
257  objunref(xpsearch);
258  return NULL;
259  }
260  xn = xml_nodetohash(xpsearch->xmldoc, node, attrkey);
261  objunlock(xpsearch);
262  objunlock(xpsearch->xmldoc);
263  objunref(xpsearch);
264 
265  return xn;
266 }
267 
268 static void free_iter(void *data) {
269  struct xml_node_iter *xi = data;
270 
271  objunref(xi->xsearch);
272 }
273 
276 extern struct xml_node *xml_getrootnode(struct xml_doc *xmldoc) {
277  struct xml_node *rn;
278 
279  objlock(xmldoc);
280  rn = xml_nodetohash(xmldoc, xmldoc->root, NULL);
281  objunlock(xmldoc);
282  return rn;
283 }
284 
295 extern struct xml_node *xml_getfirstnode(struct xml_search *xpsearch, void **iter) {
296  struct xml_node_iter *newiter;
297  struct xml_node *xn;
298 
299  if (!objref(xpsearch)) {
300  return NULL;
301  }
302 
303  if (iter) {
304  newiter = objalloc(sizeof(*newiter), free_iter);
305  objlock(xpsearch);
306  newiter->cnt = xml_nodecount(xpsearch);
307  objunlock(xpsearch);
308  newiter->curpos = 0;
309  newiter->xsearch = xpsearch;
310  objref(newiter->xsearch);
311  *iter = newiter;
312  }
313 
314  xn = xml_gethash(xpsearch, 0, NULL);
315  objunref(xpsearch);
316  return xn;
317 }
318 
322 extern struct xml_node *xml_getnextnode(void *iter) {
323  struct xml_node_iter *xi = iter;
324  struct xml_node *xn;
325 
326  if (!objref(xi->xsearch)) {
327  return NULL;
328  }
329 
330  objlock(xi);
331  xi->curpos ++;
332  if (xi->curpos >= xi->cnt) {
333  objunlock(xi);
334  objunref(xi->xsearch);
335  return NULL;
336  }
337  xn = xml_gethash(xi->xsearch, xi->curpos, NULL);
338  objunlock(xi);
339  objunref(xi->xsearch);
340 
341  return xn;
342 }
343 
349 extern struct bucket_list *xml_getnodes(struct xml_search *xpsearch) {
350  return (xpsearch && objref(xpsearch->nodes)) ? xpsearch->nodes : NULL;
351 }
352 
353 static struct bucket_list *xml_setnodes(struct xml_search *xpsearch, const char *attrkey) {
354  struct xml_node *ninfo;
355  struct bucket_list *nodes;
356  int cnt, i;
357 
358  if (!(nodes = create_bucketlist(2, node_hash))) {
359  return NULL;
360  }
361 
362  cnt = xml_nodecount(xpsearch);
363  for(i=0; i < cnt; i++) {
364  ninfo = xml_gethash(xpsearch, i, attrkey);
365  if (!addtobucket(nodes, ninfo)) {
366  objunref(ninfo);
367  objunref(nodes);
368  nodes = NULL;
369  break;
370  }
371  objunref(ninfo);
372  }
373  return nodes;
374 }
375 
381 extern struct xml_search *xml_xpath(struct xml_doc *xmldata, const char *xpath, const char *attrkey) {
382  struct xml_search *xpsearch;
383 
384  if (!objref(xmldata) || !(xpsearch = objalloc(sizeof(*xpsearch), free_xmlsearch))) {
385  return NULL;
386  }
387 
388  objlock(xmldata);
389  xpsearch->xmldoc = xmldata;
390  if (!(xpsearch->xpathObj = xmlXPathEvalExpression((const xmlChar *)xpath, xmldata->xpathCtx))) {
391  objunlock(xmldata);
392  objunref(xpsearch);
393  return NULL;
394  }
395 
396  if (xmlXPathNodeSetIsEmpty(xpsearch->xpathObj->nodesetval)) {
397  objunlock(xmldata);
398  objunref(xpsearch);
399  return NULL;
400  }
401  objunlock(xmldata);
402 
403  if (!(xpsearch->nodes = xml_setnodes(xpsearch, attrkey))) {
404  objunref(xpsearch);
405  return NULL;
406  }
407  return xpsearch;
408 }
409 
413 extern int xml_nodecount(struct xml_search *xsearch) {
414  xmlNodeSetPtr nodeset;
415 
416  if (xsearch && xsearch->xpathObj && ((nodeset = xsearch->xpathObj->nodesetval))) {
417  return nodeset->nodeNr;
418  } else {
419  return 0;
420  }
421 }
422 
429 extern struct xml_node *xml_getnode(struct xml_search *xsearch, const char *key) {
430  if (!xsearch) {
431  return NULL;
432  }
433  return bucket_list_find_key(xsearch->nodes, key);
434 }
435 
440 extern const char *xml_getattr(struct xml_node *xnode, const char *attr) {
441  struct xml_attr *ainfo;
442 
443  if (!xnode) {
444  return NULL;
445  }
446 
447  if ((ainfo = bucket_list_find_key(xnode->attrs, attr))) {
448  objunref(ainfo);
449  return ainfo->value;
450  } else {
451  return NULL;
452  }
453 }
454 
458 extern const char *xml_getrootname(struct xml_doc *xmldoc) {
459  if (xmldoc) {
460  return (const char *)xmldoc->root->name;
461  }
462  return NULL;
463 }
464 
469 extern void xml_modify(struct xml_doc *xmldoc, struct xml_node *xnode, const char *value) {
470  xmlChar *encval;
471  xmlNodePtr node;
472 
473  objlock(xmldoc);
474  node = xnode->nodeptr;
475  encval = xmlEncodeSpecialChars(xmldoc->doc, (const xmlChar *)value);
476  xmlNodeSetContent(node, encval);
477  xmlFree(encval);
478  encval = xmlNodeListGetString(xmldoc->doc, node->xmlChildrenNode, 1);
479  objunlock(xmldoc);
480 
481  if (xnode->value) {
482  free((void*)xnode->value);
483  }
484  ALLOC_CONST(xnode->value, (const char *)encval);
485  xmlFree(encval);
486 }
487 
493 extern void xml_setattr(struct xml_doc *xmldoc, struct xml_node *xnode, const char *name, const char *value) {
494  xmlChar *encval;
495 
496  objlock(xmldoc);
497  encval = xmlEncodeSpecialChars(xmldoc->doc, (const xmlChar *)value);
498  xmlSetProp(xnode->nodeptr, (const xmlChar *)name, (const xmlChar *)encval);
499  objunlock(xmldoc);
500  xmlFree(encval);
501 }
502 
507 extern void xml_createpath(struct xml_doc *xmldoc, const char *xpath) {
508  struct xml_node *nn;
509  xmlXPathObjectPtr xpathObj;
510  char *lpath, *tok, *save, *cpath, *dup;
511  const char *root = (char *)xmldoc->root->name;
512  int len;
513 
514 
515  if (!objref(xmldoc)) {
516  return;
517  }
518 
519  if (!(dup = strdup(xpath))) {
520  objunref(xmldoc);
521  return;
522  }
523 
524  len = strlen(xpath)+1;
525  if (!(cpath = malloc(len))) {
526  free(dup);
527  objunref(xmldoc);
528  return;
529  }
530  if (!(lpath = malloc(len))) {
531  free(dup);
532  free(cpath);
533  objunref(xmldoc);
534  return;
535  }
536 
537  cpath[0] = '\0';
538  lpath[0] = '\0';
539 
540 #ifndef __WIN32__
541  for (tok = strtok_r(dup, "/", &save); tok ; tok = strtok_r(NULL, "/", &save)) {
542 #else
543  for (tok = strtok_s(dup, "/", &save); tok ; tok = strtok_s(NULL, "/", &save)) {
544 #endif
545  strcat(cpath,"/");
546  strcat(cpath, tok);
547  if (!strcmp(tok, root)) {
548  strcat(lpath,"/");
549  strcat(lpath, tok);
550  continue;
551  }
552 
553  objlock(xmldoc);
554  if (!(xpathObj = xmlXPathEvalExpression((const xmlChar *)cpath, xmldoc->xpathCtx))) {
555  objunlock(xmldoc);
556  free(lpath);
557  free(cpath);
558  free(dup);
559  objunref(xmldoc);
560  return;
561  }
562  objunlock(xmldoc);
563 
564  if (xmlXPathNodeSetIsEmpty(xpathObj->nodesetval)) {
565  nn = xml_addnode(xmldoc, lpath, tok, NULL, NULL, NULL);
566  objunref(nn);
567  }
568 
569  xmlXPathFreeObject(xpathObj);
570  strcat(lpath,"/");
571  strcat(lpath, tok);
572  }
573 
574  free(dup);
575  free(lpath);
576  free(cpath);
577  objunref(xmldoc);
578 }
579 
580 
581 static xmlNodePtr xml_getparent(struct xml_doc *xmldoc, const char *xpath) {
582  xmlXPathObjectPtr xpathObj;
583  xmlNodePtr parent = NULL;
584  xmlNodeSetPtr nodes;
585  int i, cnt;
586 
587  if (!(xpathObj = xmlXPathEvalExpression((const xmlChar *)xpath, xmldoc->xpathCtx))) {
588  return NULL;
589  }
590 
591  if (xmlXPathNodeSetIsEmpty(xpathObj->nodesetval)) {
592  xmlXPathFreeObject(xpathObj);
593  return NULL;
594  }
595 
596  if (!(nodes = xpathObj->nodesetval)) {
597  xmlXPathFreeObject(xpathObj);
598  return NULL;
599  }
600 
601  cnt = nodes->nodeNr;
602  for(i=cnt - 1; i >= 0; i--) {
603  if (nodes->nodeTab[i]->type == XML_ELEMENT_NODE) {
604  parent=nodes->nodeTab[i];
605  nodes->nodeTab[i] = NULL;
606  break;
607  }
608  }
609 
610  if (!parent) {
611  xmlXPathFreeObject(xpathObj);
612  return NULL;
613  }
614 
615  xmlXPathFreeObject(xpathObj);
616  return parent;
617 }
618 
619 
625 extern void xml_appendnode(struct xml_doc *xmldoc, const char *xpath, struct xml_node *child) {
626  xmlNodePtr parent;
627 
628  if (!objref(xmldoc)) {
629  return;
630  }
631 
632  objlock(xmldoc);
633  if (!(parent = xml_getparent(xmldoc, xpath))) {
634  objunlock(xmldoc);
635  objunref(xmldoc);
636  }
637 
638  xmlAddChild(parent,child->nodeptr);
639  objunlock(xmldoc);
640  objunref(xmldoc);
641 }
642 
651 extern struct xml_node *xml_addnode(struct xml_doc *xmldoc, const char *xpath, const char *name, const char *value,
652  const char *attrkey, const char *keyval) {
653  struct xml_node *newnode;
654  xmlNodePtr parent;
655  xmlNodePtr child;
656  xmlChar *encval;
657 
658  if (!objref(xmldoc)) {
659  return NULL;
660  }
661 
662  objlock(xmldoc);
663  if (!(parent = xml_getparent(xmldoc, xpath))) {
664  objunlock(xmldoc);
665  objunref(xmldoc);
666  return NULL;
667  }
668 
669  encval = xmlEncodeSpecialChars(xmldoc->doc, (const xmlChar *)value);
670  child = xmlNewDocNode(xmldoc->doc, NULL, (const xmlChar *)name, encval);
671  xmlFree(encval);
672  xmlAddChild(parent,child);
673 
674  if (attrkey && keyval) {
675  encval = xmlEncodeSpecialChars(xmldoc->doc, (const xmlChar *)keyval);
676  xmlSetProp(child, (const xmlChar *)attrkey, (const xmlChar *)encval);
677  xmlFree(encval);
678  }
679  objunlock(xmldoc);
680 
681  if (!(newnode = xml_nodetohash(xmldoc, child, attrkey))) {
682  objunref(xmldoc);
683  return NULL;
684  }
685 
686  objunref(xmldoc);
687 
688  return newnode;
689 }
690 
693 extern void xml_unlink(struct xml_node *xnode) {
694  objlock(xnode);
695  xmlUnlinkNode(xnode->nodeptr);
696  objunlock(xnode);
697 }
698 
701 extern void xml_delete(struct xml_node *xnode) {
702  objlock(xnode);
703  xmlUnlinkNode(xnode->nodeptr);
704  xmlFreeNode(xnode->nodeptr);
705  xnode->nodeptr = NULL;
706  objunlock(xnode);
707 }
708 
712 extern char *xml_getbuffer(void *buffer) {
713  struct xml_buffer *xb = buffer;
714 
715  if (!xb) {
716  return NULL;
717  }
718  return (char *)xb->buffer;
719 }
720 
726 extern void *xml_doctobuffer(struct xml_doc *xmldoc) {
727  struct xml_buffer *xmlbuf;
728 
729  if (!(xmlbuf = objalloc(sizeof(*xmlbuf),xml_free_buffer))) {
730  return NULL;
731  }
732 
733  objlock(xmldoc);
734  xmlDocDumpFormatMemory(xmldoc->doc, &xmlbuf->buffer, &xmlbuf->size, 1);
735  objunlock(xmldoc);
736  return xmlbuf;
737 }
738 
742 extern void xml_init() {
743  if (!xml_has_init_parser) {
744  xml_has_init_parser = objalloc(0, free_parser);
745  xmlInitParser();
746  LIBXML_TEST_VERSION
747  xmlKeepBlanksDefault(0);
748  xmlLoadExtDtdDefaultValue = 1;
749  xmlSubstituteEntitiesDefault(1);
750  } else {
751  objref(xml_has_init_parser);
752  }
753 }
754 
758 extern void xml_close() {
759  if (xml_has_init_parser) {
760  objunref(xml_has_init_parser);
761  }
762 }
763 
769 extern void xml_savefile(struct xml_doc *xmldoc, const char *file, int format, int compress) {
770  objlock(xmldoc);
771  xmlSetDocCompressMode(xmldoc->doc, compress);
772  xmlSaveFormatFile(file, xmldoc->doc, format);
773  xmlSetDocCompressMode(xmldoc->doc, 0);
774  objunlock(xmldoc);
775 }
776 
777 /*static void xml_modify2(struct xml_search *xpsearch, struct xml_node *xnode, const char *value) {
778  xmlNodeSetPtr nodes;
779  int size, i;
780 
781  if (!(nodes = xpsearch->xpathObj->nodesetval)) {
782  return;
783  }
784 
785  size = (nodes) ? nodes->nodeNr : 0;
786 
787 */ /*
788  * http://www.xmlsoft.org/examples/xpath2.c
789  * remove the reference to the modified nodes from the node set
790  * as they are processed, if they are not namespace nodes.
791  */
792 /* for(i = size - 1; i >= 0; i--) {
793  if (nodes->nodeTab[i] == xnode->nodeptr) {
794  xmlNodeSetContent(nodes->nodeTab[i], (const xmlChar *)value);
795  if (nodes->nodeTab[i]->type != XML_NAMESPACE_DECL) {
796  nodes->nodeTab[i] = NULL;
797  }
798  }
799  }
800 }*/
801 
void xml_modify(struct xml_doc *xmldoc, struct xml_node *xnode, const char *value)
Modify a XML node.
Definition: libxml2.c:469
void * create_bucketlist(int bitmask, blisthash hash_function)
Definition: refobj.c:356
const char * key
Attribute key for searching and indexing.
Definition: dtsapp.h:654
int curpos
current position.
Definition: libxml2.c:26
int objref(void *data)
Reference a object.
Definition: refobj.c:153
struct xml_node * xml_getnextnode(void *iter)
Return the next node.
Definition: libxml2.c:322
struct xml_doc xml_doc
Forward decleration of structure.
Definition: dtsapp.h:631
int cnt
number of nodes in search path.
Definition: libxml2.c:28
Iterator to traverse nodes in a xpath.
Definition: libxml2.c:22
struct xml_node * xml_getrootnode(struct xml_doc *xmldoc)
Return reference to the root node.
Definition: libxml2.c:276
void xml_unlink(struct xml_node *xnode)
Unlink a node from the document.
Definition: libxml2.c:693
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
const char * name
Name of the node.
Definition: dtsapp.h:650
struct xml_node * xml_addnode(struct xml_doc *xmldoc, const char *xpath, const char *name, const char *value, const char *attrkey, const char *keyval)
Append a node to a path.
Definition: libxml2.c:651
XML xpath search result.
Definition: libxml2.c:33
void xml_createpath(struct xml_doc *xmldoc, const char *xpath)
Create a path in XML document.
Definition: libxml2.c:507
XML attribute name value pair.
Definition: dtsapp.h:639
struct xml_doc * xml_loadbuf(const uint8_t *buffer, uint32_t len, int validate)
Load a buffer into XML document returning refereence.
Definition: libxml2.c:168
struct bucket_list * attrs
Bucket list of attributes.
Definition: dtsapp.h:656
struct xml_node * xml_getnode(struct xml_search *xsearch, const char *key)
Return a node in the search matching key.
Definition: libxml2.c:429
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
Definition: refobj.c:129
struct xml_doc * xml_loaddoc(const char *docfile, int validate)
Load a XML file into XML document and return reference.
Definition: libxml2.c:146
void xml_free_buffer(void *data)
Reference destructor for xml_buffer.
Definition: libxml2.c:46
struct xml_search * xsearch
Reference to search returned from xml_search()
Definition: libxml2.c:24
void xml_appendnode(struct xml_doc *xmldoc, const char *xpath, struct xml_node *child)
Append a node to a path.
Definition: libxml2.c:625
const char * xml_getattr(struct xml_node *xnode, const char *attr)
Return value of attribute.
Definition: libxml2.c:440
void * xml_doctobuffer(struct xml_doc *xmldoc)
Return a dump of a XML document.
Definition: libxml2.c:726
DTS Application library API Include file.
int xml_nodecount(struct xml_search *xsearch)
Return the number of nodes in the search path.
Definition: libxml2.c:413
const char * name
Name of attribute.
Definition: dtsapp.h:641
const char * xml_getrootname(struct xml_doc *xmldoc)
Return the name of the root node.
Definition: libxml2.c:458
struct xml_doc * xmldoc
Reference to XML document.
Definition: libxml2.c:35
void xml_close()
Unreference the XML library.
Definition: libxml2.c:758
const char * value
Value of the node.
Definition: dtsapp.h:652
struct bucket_list * nodes
Bucket list of all nodes.
Definition: libxml2.c:39
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
void xml_init()
Initialise/Reference the XML library.
Definition: libxml2.c:742
void xml_setattr(struct xml_doc *xmldoc, struct xml_node *xnode, const char *name, const char *value)
Modify a XML node attribute.
Definition: libxml2.c:493
char * xml_getbuffer(void *buffer)
Return the buffer of a xml_buffer structure.
Definition: libxml2.c:712
struct xml_search * xml_xpath(struct xml_doc *xmldata, const char *xpath, const char *attrkey)
Return a reference to a xpath search result.
Definition: libxml2.c:381
void * nodeptr
Internal libxml2 node pointer.
Definition: dtsapp.h:658
void xml_delete(struct xml_node *xnode)
Delete a node from document it is not unrefd and should be.
Definition: libxml2.c:701
#define jenhash(key, length, initval)
Define jenhash as hashlittle on big endian it should be hashbig.
Definition: dtsapp.h:914
const char * value
Value of attribute.
Definition: dtsapp.h:643
Reference to a XML Node.
Definition: dtsapp.h:648
#define ALLOC_CONST(const_var, val)
Macro to assign values to char const.
Definition: dtsapp.h:959
int addtobucket(struct bucket_list *blist, void *data)
Add a reference to the bucketlist.
Definition: refobj.c:428
void * bucket_list_find_key(struct bucket_list *list, const void *key)
Find and return a reference to a item matching supplied key.
Definition: refobj.c:572
xmlXPathObjectPtr xpathObj
Xpath object.
Definition: libxml2.c:37
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184
struct xml_node * xml_getfirstnode(struct xml_search *xpsearch, void **iter)
Return reference to the first node optionally creating a iterator.
Definition: libxml2.c:295
void xml_savefile(struct xml_doc *xmldoc, const char *file, int format, int compress)
Save XML document to a file.
Definition: libxml2.c:769
Bucket list, hold hashed objects in buckets.
Definition: refobj.c:75
struct bucket_list * xml_getnodes(struct xml_search *xpsearch)
Return reference to bucket list containing nodes.
Definition: libxml2.c:349