3 * Copyright 2004-2006 Aaron Voisine <aaron@voisine.org>
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Modified for Palacios by Jack Lange <jarusl@cs.northwestern.edu>
32 #include <palacios/vmm.h>
33 #include <palacios/vmm_types.h>
37 char *name; // tag name
38 char **attr; // tag attributes { name, value, name, value, ... NULL }
39 char *txt; // tag character content, empty string if none
40 size_t off; // tag offset from start of parent tag character content
41 struct v3_xml * next; // next tag with same name in this section at this depth
42 struct v3_xml * sibling; // next tag with different name in same section and depth
43 struct v3_xml * ordered; // next tag, same section and depth, in original order
44 struct v3_xml * child; // head of sub tag list, NULL if none
45 struct v3_xml * parent; // parent tag, NULL if current tag is root tag
46 short flags; // additional information
49 // Given a string of xml data and its length, parses it and creates an v3_xml
50 // structure. For efficiency, modifies the data by adding null terminators
51 // and decoding ampersand sequences. If you don't want this, copy the data and
52 // pass in the copy. Returns NULL on failure.
53 struct v3_xml * v3_xml_parse(char * buf);
56 // returns the name of the given tag
57 #define v3_xml_name(xml) ((xml) ? xml->name : NULL)
59 // returns the given tag's character content or empty string if none
60 #define v3_xml_txt(xml) ((xml) ? xml->txt : "")
63 // returns the first child tag (one level deeper) with the given name or NULL
65 struct v3_xml * v3_xml_child(struct v3_xml * xml, const char * name);
67 // returns the next tag of the same name in the same section and depth or NULL
69 #define v3_xml_next(xml) ((xml) ? xml->next : NULL)
71 // Returns the Nth tag with the same name in the same section at the same depth
72 // or NULL if not found. An index of 0 returns the tag given.
73 struct v3_xml * v3_xml_idx(struct v3_xml * xml, int idx);
75 // returns the value of the requested tag attribute, or NULL if not found
76 const char *v3_xml_attr(struct v3_xml * xml, const char * attr);
81 // Traverses the v3_xml sturcture to retrieve a specific subtag. Takes a
82 // variable length list of tag names and indexes. The argument list must be
83 // terminated by either an index of -1 or an empty string tag name. Example:
84 // title = v3_xml_get(library, "shelf", 0, "book", 2, "title", -1);
85 // This retrieves the title of the 3rd book on the 1st shelf of library.
86 // Returns NULL if not found.
87 struct v3_xml * v3_xml_get(struct v3_xml * xml, ...);
90 // frees the memory allocated for an v3_xml structure
91 void v3_xml_free(struct v3_xml * xml);
98 char * v3_xml_tostr(struct v3_xml * xml);
100 struct v3_xml * v3_xml_insert(struct v3_xml * xml, struct v3_xml * dest, size_t off);
101 struct v3_xml * v3_xml_set_txt(struct v3_xml * xml, const char *txt);
104 struct v3_xml * v3_xml_set_attr(struct v3_xml * xml, const char * name, const char * value);
107 #endif // __VMM_XML_H