Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


interface updates
[palacios.git] / palacios / include / palacios / vmm_xml.h
1 /* ezxml.h
2  *
3  * Copyright 2004-2006 Aaron Voisine <aaron@voisine.org>
4  *
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:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
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.
23  */
24
25 /* 
26  * Modified for Palacios by Jack Lange <jarusl@cs.northwestern.edu> 
27  */
28
29 #ifndef __VMM_XML_H
30 #define __VMM_XML_H
31
32 #include <palacios/vmm.h>
33 #include <palacios/vmm_types.h>
34
35
36 struct v3_xml {
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
47 };
48
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);
54
55
56 // returns the name of the given tag
57 #define v3_xml_name(xml) ((xml) ? xml->name : NULL)
58
59 // returns the given tag's character content or empty string if none
60 #define v3_xml_txt(xml) ((xml) ? xml->txt : "")
61
62
63 // returns the first child tag (one level deeper) with the given name or NULL
64 // if not found
65 struct v3_xml * v3_xml_child(struct v3_xml * xml, const char * name);
66
67 // returns the next tag of the same name in the same section and depth or NULL
68 // if not found
69 #define v3_xml_next(xml) ((xml) ? xml->next : NULL)
70
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);
74
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);
77
78
79 // Traverses the v3_xml sturcture to retrieve a specific subtag. Takes a
80 // variable length list of tag names and indexes. The argument list must be
81 // terminated by either an index of -1 or an empty string tag name. Example: 
82 // title = v3_xml_get(library, "shelf", 0, "book", 2, "title", -1);
83 // This retrieves the title of the 3rd book on the 1st shelf of library.
84 // Returns NULL if not found.
85 struct v3_xml * v3_xml_get(struct v3_xml * xml, ...);
86
87
88 // frees the memory allocated for an v3_xml structure
89 void v3_xml_free(struct v3_xml * xml);
90     
91 #endif // __VMM_XML_H