reportxml.h 7.26 KB
Newer Older
1 2 3 4 5 6 7 8
/* Icecast
 *
 * This program is distributed under the GNU General Public License, version 2.
 * A copy of this license is included with this source.
 *
 * Copyright 2018,      Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
 */

9 10
/* This file contains the API for report XML document parsing, manipulation, and rendering. */

11 12 13 14 15 16 17
#ifndef __REPORTXML_H__
#define __REPORTXML_H__

#include <libxml/tree.h>

#include "icecasttypes.h"
#include "compat.h"
18
#include "refobject.h"
19

20 21 22
/* XML Tag Types
 * While a hint of what the nodes are used for is given, see the specification for more details.
 */
23
typedef enum {
24
    /* This is a virtual type used to indicate error conditions */
25
    REPORTXML_NODE_TYPE__ERROR,
26
    /* <report> is the root element of report XML documents */
27
    REPORTXML_NODE_TYPE_REPORT,
28
    /* <definition> is used to define templates */
29
    REPORTXML_NODE_TYPE_DEFINITION,
30
    /* <incident> defines an event that is reported */
31
    REPORTXML_NODE_TYPE_INCIDENT,
32
    /* <state> defines the state an <incident> resulted in */
33
    REPORTXML_NODE_TYPE_STATE,
34
    /* <backtrace> provides helpful information about the location some event happend */
35
    REPORTXML_NODE_TYPE_BACKTRACE,
36
    /* <position> defines an element within <backtrace> */
37
    REPORTXML_NODE_TYPE_POSITION,
38 39 40
    /* <more> allows to skip <position>s in <backtrace> for any reason
     * (e.g. they are unknown or consider of no intrest)
     */
41
    REPORTXML_NODE_TYPE_MORE,
42
    /* <fix> provides a machine readable way to actually fix the problem */
43
    REPORTXML_NODE_TYPE_FIX,
44
    /* <action> defines a specific action to do */
45
    REPORTXML_NODE_TYPE_ACTION,
46
    /* <reason> allows to define why an event happend */
47
    REPORTXML_NODE_TYPE_REASON,
48 49 50
    /* <text> is used to provide messages to the user.
     * The content of <text> is not machine readable.
     */
51
    REPORTXML_NODE_TYPE_TEXT,
52
    /* <timestamp> provides a way to present a point in time an event happend */
53
    REPORTXML_NODE_TYPE_TIMESTAMP,
54
    /* <resource> names a resource that was involved in the event such as user input or the result */
55
    REPORTXML_NODE_TYPE_RESOURCE,
56
    /* <value> provides an actual value for a <resource> */
57
    REPORTXML_NODE_TYPE_VALUE,
58
    /* <reference> provides a way to refer to external documents such as documentation */
59
    REPORTXML_NODE_TYPE_REFERENCE,
60
    /* <extension> is used to allow application specific extensions */
61 62 63
    REPORTXML_NODE_TYPE_EXTENSION
} reportxml_node_type_t;

64 65 66
REFOBJECT_FORWARD_TYPE(reportxml_t);
REFOBJECT_FORWARD_TYPE(reportxml_node_t);
REFOBJECT_FORWARD_TYPE(reportxml_database_t);
67

68
/* ---[ Document level ]--- */
69 70
/* The document object is NOT thread safe. */

71 72 73
/* Depreciated: This creates a new, empty report XML document
 * Do NOT use this. Use refobject_new(reportxml_t)
 */
74
reportxml_t *           reportxml_new(void);
75
/* This gets the root node of a report XML document */
76
reportxml_node_t *      reportxml_get_root_node(reportxml_t *report);
77 78 79 80 81 82 83
/* This selects a node by an attribute and it's value.
 * This is mostly useful to look for an object by using it's ID.
 * If more than one node matches the first one found is returned.
 * If the parameter include_definitions is true nodes from within
 * <definition> are also considered. If it is false nodes inside
 * <definition>s are skipped.
 */
84
reportxml_node_t *      reportxml_get_node_by_attribute(reportxml_t *report, const char *key, const char *value, int include_definitions);
85 86
/* This gets a node by it's type. Otherwise identical to reportxml_get_node_by_attribute() */
reportxml_node_t *      reportxml_get_node_by_type(reportxml_t *report, reportxml_node_type_t type, int include_definitions);
87
/* This function parses an XML document and returns the parst report XML document */
88
reportxml_t *           reportxml_parse_xmldoc(xmlDocPtr doc);
89
/* This function renders an report XML document as XML structure */
90 91
xmlDocPtr               reportxml_render_xmldoc(reportxml_t *report);

92

93
/* ---[ Node level ]--- */
94 95
/* The node object is NOT thread safe. */

96 97 98 99

/* This creates a new node of type type.
 * It's id, definition, and akindof attributes can be given as parameters.
 */
100
reportxml_node_t *      reportxml_node_new(reportxml_node_type_t type, const char *id, const char *definition, const char *akindof);
101
/* This parses an XML node and returns the resulting report XML node */
102
reportxml_node_t *      reportxml_node_parse_xmlnode(xmlNodePtr xmlnode);
103
/* Copy an report XML node (and it's children) */
104
reportxml_node_t *      reportxml_node_copy(reportxml_node_t *node);
105
/* Renders an report XML node as XML node */
106
xmlNodePtr              reportxml_node_render_xmlnode(reportxml_node_t *node);
107
/* This gets the type of an report XML node */
108
reportxml_node_type_t   reportxml_node_get_type(reportxml_node_t *node);
109
/* Gets and Sets attribute values */
110 111
int                     reportxml_node_set_attribute(reportxml_node_t *node, const char *key, const char *value);
char *                  reportxml_node_get_attribute(reportxml_node_t *node, const char *key);
112
/* Adds, counts, and get child nodes */
113 114 115
int                     reportxml_node_add_child(reportxml_node_t *node, reportxml_node_t *child);
ssize_t                 reportxml_node_count_child(reportxml_node_t *node);
reportxml_node_t *      reportxml_node_get_child(reportxml_node_t *node, size_t idx);
116
/* This gets an child by it's value of the given attribute. See reportxml_get_node_by_attribute() for more details. */
117
reportxml_node_t *      reportxml_node_get_child_by_attribute(reportxml_node_t *node, const char *key, const char *value, int include_definitions);
118 119
/* This gets a child by it's type. Otherwise identical to reportxml_node_get_child_by_attribute() */
reportxml_node_t *      reportxml_node_get_child_by_type(reportxml_node_t *node, reportxml_node_type_t type, int include_definitions);
120
/* This gets and sets the text content of an node (used for <text>) */
121 122
int                     reportxml_node_set_content(reportxml_node_t *node, const char *value);
char *                  reportxml_node_get_content(reportxml_node_t *node);
123
/* Adds, counts, and gets XML childs (used for <extension>) */
124 125 126
int                     reportxml_node_add_xml_child(reportxml_node_t *node, xmlNodePtr child);
ssize_t                 reportxml_node_count_xml_child(reportxml_node_t *node);
xmlNodePtr              reportxml_node_get_xml_child(reportxml_node_t *node, size_t idx);
127

128

129
/* ---[ Database level ]--- */
130 131
/* The database object is thread safe. */

132

133 134 135
/* Depreciated: Create a new database object
 * Do NOT use this. Use refobject_new(reportxml_database_t)
 */
136
reportxml_database_t *  reportxml_database_new(void);
137
/* Add an report to the database */
138
int                     reportxml_database_add_report(reportxml_database_t *db, reportxml_t *report);
139 140 141 142
/* Build a node (copy) from the data in the database based on the given ID (using "definition" and "defines" attributes)
 * depth may be used to select how many recursions may be used to resolve definitions within defines.
 * The default value is selected by passing -1 (recommended).
 */
143
reportxml_node_t *      reportxml_database_build_node(reportxml_database_t *db, const char *id, ssize_t depth);
144
/* This does the same as reportxml_database_build_node() except that a new report document is returned. */
145 146
reportxml_t *           reportxml_database_build_report(reportxml_database_t *db, const char *id, ssize_t depth);

147
#endif