2018-11-09 08:32:32 -05:00
|
|
|
/* 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>,
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* This file contains the API for report XML document parsing, manipulation, and rendering. */
|
|
|
|
|
|
|
|
#ifndef _LIBIGLOO__REPORTXML_H_
|
|
|
|
#define _LIBIGLOO__REPORTXML_H_
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <libxml/tree.h>
|
|
|
|
|
|
|
|
#include <igloo/ro.h>
|
|
|
|
|
|
|
|
igloo_RO_FORWARD_TYPE(igloo_reportxml_t);
|
|
|
|
igloo_RO_FORWARD_TYPE(igloo_reportxml_node_t);
|
|
|
|
igloo_RO_FORWARD_TYPE(igloo_reportxml_database_t);
|
|
|
|
|
|
|
|
|
|
|
|
/* XML Tag Types
|
|
|
|
* While a hint of what the nodes are used for is given, see the specification for more details.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
/* This is a virtual type used to indicate error conditions */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE__ERROR,
|
2018-11-09 08:32:32 -05:00
|
|
|
/* <report> is the root element of report XML documents */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE_REPORT,
|
2018-11-09 08:32:32 -05:00
|
|
|
/* <definition> is used to define templates */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE_DEFINITION,
|
2018-11-09 08:32:32 -05:00
|
|
|
/* <incident> defines an event that is reported */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE_INCIDENT,
|
2018-11-09 08:32:32 -05:00
|
|
|
/* <state> defines the state an <incident> resulted in */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE_STATE,
|
2018-11-09 08:32:32 -05:00
|
|
|
/* <backtrace> provides helpful information about the location some event happend */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE_BACKTRACE,
|
2018-11-09 08:32:32 -05:00
|
|
|
/* <position> defines an element within <backtrace> */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE_POSITION,
|
2018-11-09 08:32:32 -05:00
|
|
|
/* <more> allows to skip <position>s in <backtrace> for any reason
|
|
|
|
* (e.g. they are unknown or consider of no intrest)
|
|
|
|
*/
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE_MORE,
|
2018-11-09 08:32:32 -05:00
|
|
|
/* <fix> provides a machine readable way to actually fix the problem */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE_FIX,
|
2018-11-09 08:32:32 -05:00
|
|
|
/* <action> defines a specific action to do */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE_ACTION,
|
2018-11-09 08:32:32 -05:00
|
|
|
/* <reason> allows to define why an event happend */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE_REASON,
|
2018-11-09 08:32:32 -05:00
|
|
|
/* <text> is used to provide messages to the user.
|
|
|
|
* The content of <text> is not machine readable.
|
|
|
|
*/
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE_TEXT,
|
2018-11-09 08:32:32 -05:00
|
|
|
/* <timestamp> provides a way to present a point in time an event happend */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE_TIMESTAMP,
|
2018-11-09 08:32:32 -05:00
|
|
|
/* <resource> names a resource that was involved in the event such as user input or the result */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE_RESOURCE,
|
2018-11-09 08:32:32 -05:00
|
|
|
/* <value> provides an actual value for a <resource> */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE_VALUE,
|
2018-11-09 08:32:32 -05:00
|
|
|
/* <reference> provides a way to refer to external documents such as documentation */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE_REFERENCE,
|
2018-11-09 08:32:32 -05:00
|
|
|
/* <extension> is used to allow application specific extensions */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_REPORTXML_NODE_TYPE_EXTENSION
|
|
|
|
} igloo_reportxml_node_type_t;
|
2018-11-09 08:32:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
/* ---[ Document level ]--- */
|
|
|
|
/* The document object is NOT thread safe. */
|
|
|
|
|
|
|
|
|
|
|
|
/* This gets the root node of a report XML document */
|
2018-11-09 09:15:30 -05:00
|
|
|
igloo_reportxml_node_t * igloo_reportxml_get_root_node(igloo_reportxml_t *report);
|
2018-11-09 08:32:32 -05:00
|
|
|
/* 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.
|
|
|
|
*/
|
2018-11-09 09:15:30 -05:00
|
|
|
igloo_reportxml_node_t * igloo_reportxml_get_node_by_attribute(igloo_reportxml_t *report, const char *key, const char *value, int include_definitions);
|
|
|
|
/* This gets a node by it's type. Otherwise identical to igloo_reportxml_get_node_by_attribute() */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_reportxml_node_t * igloo_reportxml_get_node_by_type(igloo_reportxml_t *report, igloo_reportxml_node_type_t type, int include_definitions);
|
2018-11-09 08:32:32 -05:00
|
|
|
/* This function parses an XML document and returns the parst report XML document */
|
2019-09-15 04:10:32 -04:00
|
|
|
igloo_reportxml_t * igloo_reportxml_parse_xmldoc(xmlDocPtr doc, igloo_ro_t instance);
|
2018-11-09 08:32:32 -05:00
|
|
|
/* This function renders an report XML document as XML structure */
|
2018-11-09 09:15:30 -05:00
|
|
|
xmlDocPtr igloo_reportxml_render_xmldoc(igloo_reportxml_t *report);
|
2018-11-09 08:32:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
/* ---[ Node level ]--- */
|
|
|
|
/* The node object is NOT thread safe. */
|
|
|
|
|
|
|
|
|
|
|
|
/* This creates a new node of type type.
|
|
|
|
* It's id, definition, and akindof attributes can be given as parameters.
|
|
|
|
*/
|
2019-09-15 04:10:32 -04:00
|
|
|
igloo_reportxml_node_t * igloo_reportxml_node_new(igloo_reportxml_node_type_t type, const char *id, const char *definition, const char *akindof, igloo_ro_t instance);
|
2018-11-09 08:32:32 -05:00
|
|
|
/* This parses an XML node and returns the resulting report XML node */
|
2019-09-15 04:10:32 -04:00
|
|
|
igloo_reportxml_node_t * igloo_reportxml_node_parse_xmlnode(xmlNodePtr xmlnode, igloo_ro_t instance);
|
2018-11-09 08:32:32 -05:00
|
|
|
/* Copy an report XML node (and it's children) */
|
2018-11-09 09:15:30 -05:00
|
|
|
igloo_reportxml_node_t * igloo_reportxml_node_copy(igloo_reportxml_node_t *node);
|
2018-11-09 08:32:32 -05:00
|
|
|
/* Renders an report XML node as XML node */
|
2018-11-09 09:15:30 -05:00
|
|
|
xmlNodePtr igloo_reportxml_node_render_xmlnode(igloo_reportxml_node_t *node);
|
2018-11-09 08:32:32 -05:00
|
|
|
/* This gets the type of an report XML node */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_reportxml_node_type_t igloo_reportxml_node_get_type(igloo_reportxml_node_t *node);
|
2018-11-09 08:32:32 -05:00
|
|
|
/* Gets and Sets attribute values */
|
2018-11-09 09:15:30 -05:00
|
|
|
int igloo_reportxml_node_set_attribute(igloo_reportxml_node_t *node, const char *key, const char *value);
|
|
|
|
char * igloo_reportxml_node_get_attribute(igloo_reportxml_node_t *node, const char *key);
|
2018-11-09 08:32:32 -05:00
|
|
|
/* Adds, counts, and get child nodes */
|
2018-11-09 09:15:30 -05:00
|
|
|
int igloo_reportxml_node_add_child(igloo_reportxml_node_t *node, igloo_reportxml_node_t *child);
|
|
|
|
ssize_t igloo_reportxml_node_count_child(igloo_reportxml_node_t *node);
|
|
|
|
igloo_reportxml_node_t * igloo_reportxml_node_get_child(igloo_reportxml_node_t *node, size_t idx);
|
|
|
|
/* This gets an child by it's value of the given attribute. See igloo_reportxml_get_node_by_attribute() for more details. */
|
|
|
|
igloo_reportxml_node_t * igloo_reportxml_node_get_child_by_attribute(igloo_reportxml_node_t *node, const char *key, const char *value, int include_definitions);
|
|
|
|
/* This gets a child by it's type. Otherwise identical to igloo_reportxml_node_get_child_by_attribute() */
|
2018-11-09 09:17:52 -05:00
|
|
|
igloo_reportxml_node_t * igloo_reportxml_node_get_child_by_type(igloo_reportxml_node_t *node, igloo_reportxml_node_type_t type, int include_definitions);
|
2018-11-09 08:32:32 -05:00
|
|
|
/* This gets and sets the text content of an node (used for <text>) */
|
2018-11-09 09:15:30 -05:00
|
|
|
int igloo_reportxml_node_set_content(igloo_reportxml_node_t *node, const char *value);
|
|
|
|
char * igloo_reportxml_node_get_content(igloo_reportxml_node_t *node);
|
2018-11-09 08:32:32 -05:00
|
|
|
/* Adds, counts, and gets XML childs (used for <extension>) */
|
2018-11-09 09:15:30 -05:00
|
|
|
int igloo_reportxml_node_add_xml_child(igloo_reportxml_node_t *node, xmlNodePtr child);
|
|
|
|
ssize_t igloo_reportxml_node_count_xml_child(igloo_reportxml_node_t *node);
|
|
|
|
xmlNodePtr igloo_reportxml_node_get_xml_child(igloo_reportxml_node_t *node, size_t idx);
|
2018-11-09 08:32:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
/* ---[ Database level ]--- */
|
|
|
|
/* The database object is thread safe. */
|
|
|
|
|
|
|
|
|
|
|
|
/* Add an report to the database */
|
2018-11-09 09:15:30 -05:00
|
|
|
int igloo_reportxml_database_add_report(igloo_reportxml_database_t *db, igloo_reportxml_t *report);
|
2018-11-09 08:32:32 -05:00
|
|
|
/* 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).
|
|
|
|
*/
|
2018-11-09 09:15:30 -05:00
|
|
|
igloo_reportxml_node_t * igloo_reportxml_database_build_node(igloo_reportxml_database_t *db, const char *id, ssize_t depth);
|
|
|
|
/* This does the same as igloo_reportxml_database_build_node() except that a new report document is returned. */
|
|
|
|
igloo_reportxml_t * igloo_reportxml_database_build_report(igloo_reportxml_database_t *db, const char *id, ssize_t depth);
|
2018-11-09 08:32:32 -05:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|