1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-12-04 14:46:30 -05:00

Update: Removed report XML code and use that of libigloo

This commit is contained in:
Philipp Schafft 2018-11-09 14:23:53 +00:00
parent 92fe20125c
commit 92069a082f
8 changed files with 33 additions and 1599 deletions

View File

@ -29,7 +29,6 @@ noinst_HEADERS = \
matchfile.h \
tls.h \
module.h \
reportxml.h \
listensocket.h \
fastevent.h \
event.h \
@ -73,7 +72,6 @@ icecast_SOURCES = \
matchfile.c \
tls.c \
module.c \
reportxml.c \
listensocket.c \
fastevent.c \
format.c \

View File

@ -35,7 +35,6 @@
#include "auth.h"
#include "event.h"
#include <igloo/ro.h>
#include "reportxml.h"
/* for config_reread_config() */
#include "yp.h"
@ -258,7 +257,7 @@ void config_init_configuration(ice_config_t *configuration)
{
memset(configuration, 0, sizeof(ice_config_t));
_set_defaults(configuration);
configuration->reportxml_db = igloo_ro_new(reportxml_database_t);
configuration->reportxml_db = igloo_ro_new(igloo_reportxml_database_t);
}
static inline void __read_int(xmlDocPtr doc, xmlNodePtr node, int *val, const char *warning)
@ -2248,7 +2247,7 @@ static void _parse_paths(xmlDocPtr doc,
if (configuration->adminroot_dir[strlen(configuration->adminroot_dir)-1] == '/')
configuration->adminroot_dir[strlen(configuration->adminroot_dir)-1] = 0;
} else if (xmlStrcmp(node->name, XMLSTR("reportxmldb")) == 0) {
reportxml_t *report;
igloo_reportxml_t *report;
xmlDocPtr dbdoc;
if (!(temp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1))) {
@ -2259,12 +2258,12 @@ static void _parse_paths(xmlDocPtr doc,
if (!doc) {
ICECAST_LOG_ERROR("Can not read report xml database \"%H\" as XML", temp);
} else {
report = reportxml_parse_xmldoc(dbdoc);
report = igloo_reportxml_parse_xmldoc(dbdoc);
xmlFreeDoc(dbdoc);
if (!report) {
ICECAST_LOG_ERROR("Can not parse report xml database \"%H\"", temp);
} else {
reportxml_database_add_report(configuration->reportxml_db, report);
igloo_reportxml_database_add_report(configuration->reportxml_db, report);
igloo_ro_unref(report);
ICECAST_LOG_INFO("File \"%H\" added to report xml database", temp);
}

View File

@ -25,6 +25,7 @@
#include <libxml/tree.h>
#include <igloo/thread.h>
#include <igloo/avl.h>
#include <igloo/reportxml.h>
#include "icecasttypes.h"
#include "compat.h"
@ -257,7 +258,7 @@ struct ice_config_tag {
char *webroot_dir;
char *adminroot_dir;
resource_t *resources;
reportxml_database_t *reportxml_db;
igloo_reportxml_database_t *reportxml_db;
char *access_log;
char *error_log;

View File

@ -40,7 +40,6 @@
#include "stats.h"
#include "fserve.h"
#include "errors.h"
#include "reportxml.h"
#include <igloo/ro.h>
#include "xslt.h"
#include "source.h"
@ -319,7 +318,7 @@ int client_read_bytes(client_t *client, void *buf, unsigned len)
static inline void _client_send_report(client_t *client, const char *uuid, const char *message, int http_status, const char *location)
{
reportxml_t *report;
igloo_reportxml_t *report;
admin_format_t admin_format;
const char *xslt = NULL;
@ -492,7 +491,7 @@ void client_send_redirect(client_t *client, const char *uuid, int status, const
}
/* this function sends a reportxml file to the client in the prefered format. */
void client_send_reportxml(client_t *client, reportxml_t *report, document_domain_t domain, const char *xsl, admin_format_t admin_format_hint, int status, const char *location)
void client_send_reportxml(client_t *client, igloo_reportxml_t *report, document_domain_t domain, const char *xsl, admin_format_t admin_format_hint, int status, const char *location)
{
admin_format_t admin_format;
xmlDocPtr doc;
@ -538,7 +537,7 @@ void client_send_reportxml(client_t *client, reportxml_t *report, document_domai
return;
}
doc = reportxml_render_xmldoc(report);
doc = igloo_reportxml_render_xmldoc(report);
if (!doc) {
ICECAST_LOG_ERROR("Can not render XML Document from report. Sending 500 to client %p", client);
client_send_500(client, "Can not render XML Document from report.");
@ -647,18 +646,18 @@ void client_send_reportxml(client_t *client, reportxml_t *report, document_domai
xmlFreeDoc(doc);
}
static void client_get_reportxml__add_basic_stats(reportxml_t *report)
static void client_get_reportxml__add_basic_stats(igloo_reportxml_t *report)
{
reportxml_node_t *rootnode, *extension;
igloo_reportxml_node_t *rootnode, *extension;
xmlNodePtr xmlroot;
xmlNodePtr modules;
rootnode = reportxml_get_root_node(report);
rootnode = igloo_reportxml_get_root_node(report);
extension = reportxml_node_new(REPORTXML_NODE_TYPE_EXTENSION, NULL, NULL, NULL);
reportxml_node_set_attribute(extension, "application", ADMIN_ICESTATS_LEGACY_EXTENSION_APPLICATION);
extension = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_EXTENSION, NULL, NULL, NULL);
igloo_reportxml_node_set_attribute(extension, "application", ADMIN_ICESTATS_LEGACY_EXTENSION_APPLICATION);
reportxml_node_add_child(rootnode, extension);
igloo_reportxml_node_add_child(rootnode, extension);
igloo_ro_unref(rootnode);
@ -667,42 +666,42 @@ static void client_get_reportxml__add_basic_stats(reportxml_t *report)
xmlAddChild(xmlroot, modules);
reportxml_node_add_xml_child(extension, xmlroot);
igloo_reportxml_node_add_xml_child(extension, xmlroot);
igloo_ro_unref(extension);
xmlFreeNode(xmlroot);
}
reportxml_t *client_get_reportxml(const char *state_definition, const char *state_akindof, const char *state_text)
igloo_reportxml_t *client_get_reportxml(const char *state_definition, const char *state_akindof, const char *state_text)
{
reportxml_t *report = NULL;
igloo_reportxml_t *report = NULL;
if (state_definition) {
ice_config_t *config;
config = config_get_config();
report = reportxml_database_build_report(config->reportxml_db, state_definition, -1);
report = igloo_reportxml_database_build_report(config->reportxml_db, state_definition, -1);
config_release_config();
}
if (!report) {
reportxml_node_t *rootnode, *incidentnode, *statenode;
igloo_reportxml_node_t *rootnode, *incidentnode, *statenode;
report = igloo_ro_new(reportxml_t);
rootnode = reportxml_get_root_node(report);
incidentnode = reportxml_node_new(REPORTXML_NODE_TYPE_INCIDENT, NULL, NULL, NULL);
statenode = reportxml_node_new(REPORTXML_NODE_TYPE_STATE, NULL, state_definition, state_akindof);
report = igloo_ro_new(igloo_reportxml_t);
rootnode = igloo_reportxml_get_root_node(report);
incidentnode = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_INCIDENT, NULL, NULL, NULL);
statenode = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_STATE, NULL, state_definition, state_akindof);
if (state_text) {
reportxml_node_t *textnode;
igloo_reportxml_node_t *textnode;
textnode = reportxml_node_new(REPORTXML_NODE_TYPE_TEXT, NULL, NULL, NULL);
reportxml_node_set_content(textnode, state_text);
reportxml_node_add_child(statenode, textnode);
textnode = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_TEXT, NULL, NULL, NULL);
igloo_reportxml_node_set_content(textnode, state_text);
igloo_reportxml_node_add_child(statenode, textnode);
igloo_ro_unref(textnode);
}
reportxml_node_add_child(incidentnode, statenode);
reportxml_node_add_child(rootnode, incidentnode);
igloo_reportxml_node_add_child(incidentnode, statenode);
igloo_reportxml_node_add_child(rootnode, incidentnode);
igloo_ro_unref(statenode);
igloo_ro_unref(incidentnode);
igloo_ro_unref(rootnode);

View File

@ -21,6 +21,7 @@
#include <igloo/httpp.h>
#include <igloo/encoding.h>
#include <igloo/reportxml.h>
#include "icecasttypes.h"
#include "errors.h"
@ -148,8 +149,8 @@ void client_send_101(client_t *client, reuse_t reuse);
void client_send_204(client_t *client);
void client_send_426(client_t *client, reuse_t reuse);
void client_send_redirect(client_t *client, const char *uuid, int status, const char *location);
void client_send_reportxml(client_t *client, reportxml_t *report, document_domain_t domain, const char *xsl, admin_format_t admin_format_hint, int status, const char *location);
reportxml_t *client_get_reportxml(const char *state_definition, const char *state_akindof, const char *state_text);
void client_send_reportxml(client_t *client, igloo_reportxml_t *report, document_domain_t domain, const char *xsl, admin_format_t admin_format_hint, int status, const char *location);
igloo_reportxml_t *client_get_reportxml(const char *state_definition, const char *state_akindof, const char *state_text);
admin_format_t client_get_admin_format_by_content_negotiation(client_t *client);
int client_send_bytes (client_t *client, const void *buf, unsigned len);
int client_read_bytes (client_t *client, void *buf, unsigned len);

View File

@ -101,12 +101,6 @@ typedef struct module_tag module_t;
typedef struct module_container_tag module_container_t;
/* ---[ reportxml.[ch] ]--- */
typedef struct reportxml_tag reportxml_t;
typedef struct reportxml_node_tag reportxml_node_t;
typedef struct reportxml_database_tag reportxml_database_t;
/* ---[ listensocket.[ch] ]--- */
typedef struct listensocket_container_tag listensocket_container_t;
@ -117,9 +111,6 @@ typedef struct listensocket_tag listensocket_t;
#define igloo_RO_APPTYPES \
igloo_RO_TYPE(module_t) \
igloo_RO_TYPE(module_container_t) \
igloo_RO_TYPE(reportxml_t) \
igloo_RO_TYPE(reportxml_node_t) \
igloo_RO_TYPE(reportxml_database_t) \
igloo_RO_TYPE(listensocket_container_t) \
igloo_RO_TYPE(listensocket_t)

File diff suppressed because it is too large Load Diff

View File

@ -1,147 +0,0 @@
/* 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 __REPORTXML_H__
#define __REPORTXML_H__
#include <libxml/tree.h>
#include "icecasttypes.h"
#include "compat.h"
#include <igloo/ro.h>
/* 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 */
REPORTXML_NODE_TYPE__ERROR,
/* <report> is the root element of report XML documents */
REPORTXML_NODE_TYPE_REPORT,
/* <definition> is used to define templates */
REPORTXML_NODE_TYPE_DEFINITION,
/* <incident> defines an event that is reported */
REPORTXML_NODE_TYPE_INCIDENT,
/* <state> defines the state an <incident> resulted in */
REPORTXML_NODE_TYPE_STATE,
/* <backtrace> provides helpful information about the location some event happend */
REPORTXML_NODE_TYPE_BACKTRACE,
/* <position> defines an element within <backtrace> */
REPORTXML_NODE_TYPE_POSITION,
/* <more> allows to skip <position>s in <backtrace> for any reason
* (e.g. they are unknown or consider of no intrest)
*/
REPORTXML_NODE_TYPE_MORE,
/* <fix> provides a machine readable way to actually fix the problem */
REPORTXML_NODE_TYPE_FIX,
/* <action> defines a specific action to do */
REPORTXML_NODE_TYPE_ACTION,
/* <reason> allows to define why an event happend */
REPORTXML_NODE_TYPE_REASON,
/* <text> is used to provide messages to the user.
* The content of <text> is not machine readable.
*/
REPORTXML_NODE_TYPE_TEXT,
/* <timestamp> provides a way to present a point in time an event happend */
REPORTXML_NODE_TYPE_TIMESTAMP,
/* <resource> names a resource that was involved in the event such as user input or the result */
REPORTXML_NODE_TYPE_RESOURCE,
/* <value> provides an actual value for a <resource> */
REPORTXML_NODE_TYPE_VALUE,
/* <reference> provides a way to refer to external documents such as documentation */
REPORTXML_NODE_TYPE_REFERENCE,
/* <extension> is used to allow application specific extensions */
REPORTXML_NODE_TYPE_EXTENSION
} reportxml_node_type_t;
igloo_RO_FORWARD_TYPE(reportxml_t);
igloo_RO_FORWARD_TYPE(reportxml_node_t);
igloo_RO_FORWARD_TYPE(reportxml_database_t);
/* ---[ Document level ]--- */
/* The document object is NOT thread safe. */
/* Depreciated: This creates a new, empty report XML document
* Do NOT use this. Use refobject_new(reportxml_t)
*/
reportxml_t * reportxml_new(void);
/* This gets the root node of a report XML document */
reportxml_node_t * reportxml_get_root_node(reportxml_t *report);
/* 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.
*/
reportxml_node_t * reportxml_get_node_by_attribute(reportxml_t *report, const char *key, const char *value, int include_definitions);
/* 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);
/* This function parses an XML document and returns the parst report XML document */
reportxml_t * reportxml_parse_xmldoc(xmlDocPtr doc);
/* This function renders an report XML document as XML structure */
xmlDocPtr reportxml_render_xmldoc(reportxml_t *report);
/* ---[ 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.
*/
reportxml_node_t * reportxml_node_new(reportxml_node_type_t type, const char *id, const char *definition, const char *akindof);
/* This parses an XML node and returns the resulting report XML node */
reportxml_node_t * reportxml_node_parse_xmlnode(xmlNodePtr xmlnode);
/* Copy an report XML node (and it's children) */
reportxml_node_t * reportxml_node_copy(reportxml_node_t *node);
/* Renders an report XML node as XML node */
xmlNodePtr reportxml_node_render_xmlnode(reportxml_node_t *node);
/* This gets the type of an report XML node */
reportxml_node_type_t reportxml_node_get_type(reportxml_node_t *node);
/* Gets and Sets attribute values */
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);
/* Adds, counts, and get child nodes */
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);
/* This gets an child by it's value of the given attribute. See reportxml_get_node_by_attribute() for more details. */
reportxml_node_t * reportxml_node_get_child_by_attribute(reportxml_node_t *node, const char *key, const char *value, int include_definitions);
/* 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);
/* This gets and sets the text content of an node (used for <text>) */
int reportxml_node_set_content(reportxml_node_t *node, const char *value);
char * reportxml_node_get_content(reportxml_node_t *node);
/* Adds, counts, and gets XML childs (used for <extension>) */
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);
/* ---[ Database level ]--- */
/* The database object is thread safe. */
/* Depreciated: Create a new database object
* Do NOT use this. Use refobject_new(reportxml_database_t)
*/
reportxml_database_t * reportxml_database_new(void);
/* Add an report to the database */
int reportxml_database_add_report(reportxml_database_t *db, reportxml_t *report);
/* 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).
*/
reportxml_node_t * reportxml_database_build_node(reportxml_database_t *db, const char *id, ssize_t depth);
/* This does the same as reportxml_database_build_node() except that a new report document is returned. */
reportxml_t * reportxml_database_build_report(reportxml_database_t *db, const char *id, ssize_t depth);
#endif