1 /*
2  * libInstPatch
3  * Copyright (C) 1999-2014 Element Green <element@elementsofsound.org>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License
7  * as published by the Free Software Foundation; version 2.1
8  * of the License only.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301, USA or on the web at http://www.gnu.org.
19  */
20 #ifndef __IPATCH_XML_H__
21 #define __IPATCH_XML_H__
22 
23 #include <glib.h>
24 
25 typedef struct _IpatchXmlNode IpatchXmlNode;
26 typedef struct _IpatchXmlAttr IpatchXmlAttr;
27 
28 /**
29  * IpatchXmlAttr:
30  * @name: Attribute name
31  * @value: Attribute value
32  *
33  * Structure for storing an XML attribute.
34  */
35 struct _IpatchXmlAttr
36 {
37     char *name;
38     char *value;
39 };
40 
41 /**
42  * IpatchXmlNode:
43  * @name: XML element name
44  * @value: XML text value or %NULL
45  * @attributes: Linked list of #IpatchXmlAttr structures
46  *
47  * An XML element node.  Note that a given node can contain only one text value.
48  */
49 struct _IpatchXmlNode
50 {
51     char *name;		/* XML element name */
52     char *value;		/* Text content of element */
53     GData *qdata;		/* To associate arbitrary data with XML nodes */
54     GList *attributes;	/* List of IpatchXmlAttr structures */
55 };
56 
57 GNode *ipatch_xml_new_node(GNode *parent, const char *name, const char *value,
58                            const char *attr_name, ...);
59 GNode *ipatch_xml_new_node_strv(GNode *parent, const char *name, const char *value,
60                                 const char **attr_names, const char **attr_values);
61 gpointer ipatch_xml_get_data(GNode *node, const char *key);
62 void ipatch_xml_set_data(GNode *node, const char *key, gpointer data);
63 void ipatch_xml_set_data_full(GNode *node, const char *key, gpointer data,
64                               GDestroyNotify destroy_func);
65 gpointer ipatch_xml_steal_data(GNode *node, const char *key);
66 gpointer ipatch_xml_get_qdata(GNode *node, GQuark quark);
67 void ipatch_xml_set_qdata(GNode *node, GQuark quark, gpointer data);
68 void ipatch_xml_set_qdata_full(GNode *node, GQuark quark, gpointer data,
69                                GDestroyNotify destroy_func);
70 gpointer ipatch_xml_steal_qdata(GNode *node, GQuark quark);
71 void ipatch_xml_destroy(GNode *node);
72 GNode *ipatch_xml_copy(GNode *node);
73 void ipatch_xml_set_name(GNode *node, const char *name);
74 void ipatch_xml_set_value(GNode *node, const char *value);
75 void ipatch_xml_set_value_printf(GNode *node, const char *format, ...);
76 void ipatch_xml_take_name(GNode *node, char *name);
77 void ipatch_xml_take_value(GNode *node, char *value);
78 G_CONST_RETURN char *ipatch_xml_get_name(GNode *node);
79 gboolean ipatch_xml_test_name(GNode *node, const char *cmpname);
80 G_CONST_RETURN char *ipatch_xml_get_value(GNode *node);
81 char *ipatch_xml_dup_value(GNode *node);
82 gboolean ipatch_xml_test_value(GNode *node, const char *cmpvalue);
83 void ipatch_xml_set_attribute(GNode *node, const char *attr_name,
84                               const char *attr_value);
85 void ipatch_xml_set_attributes(GNode *node, const char *attr_name,
86                                const char *attr_value, const char *attr2_name, ...);
87 G_CONST_RETURN char *ipatch_xml_get_attribute(GNode *node, const char *attr_name);
88 gboolean ipatch_xml_test_attribute(GNode *node, const char *attr_name,
89                                    const char *cmpval);
90 GNode *ipatch_xml_find_child(GNode *node, const char *name);
91 GNode *ipatch_xml_find_by_path(GNode *node, const char *path);
92 char *ipatch_xml_to_str(GNode *node, guint indent);
93 gboolean ipatch_xml_save_to_file(GNode *node, guint indent, const char *filename,
94                                  GError **err);
95 GNode *ipatch_xml_from_str(const char *str, GError **err);
96 GNode *ipatch_xml_load_from_file(const char *filename, GError **err);
97 
98 IpatchXmlNode *ipatch_xml_node_new(void);
99 void ipatch_xml_node_free(IpatchXmlNode *xmlnode);
100 IpatchXmlNode *ipatch_xml_node_duplicate(const IpatchXmlNode *xmlnode);
101 IpatchXmlAttr *ipatch_xml_attr_new(void);
102 void ipatch_xml_attr_free(IpatchXmlAttr *attr);
103 IpatchXmlAttr *ipatch_xml_attr_duplicate(const IpatchXmlAttr *attr);
104 
105 #endif
106