mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2024-06-23 06:25:24 +00:00
Add XML validation
This commit adds a function to check the validity of the icecast.xml configuration file. The function returns 0 if the file is valid, -1 if there was an unknown error or error codes as defined in xmlRelaxNGValidErr. TODO: * Add the schema somewhere into the repository where it makes sense. * Use the function to validate the configuration file and add handling for invalid configuration files.
This commit is contained in:
parent
ae83ea8705
commit
754fead151
|
@ -25,6 +25,7 @@
|
||||||
#endif
|
#endif
|
||||||
#include <libxml/xmlmemory.h>
|
#include <libxml/xmlmemory.h>
|
||||||
#include <libxml/parser.h>
|
#include <libxml/parser.h>
|
||||||
|
#include <libxml/relaxng.h>
|
||||||
|
|
||||||
#include "common/thread/thread.h"
|
#include "common/thread/thread.h"
|
||||||
#include "cfgfile.h"
|
#include "cfgfile.h"
|
||||||
|
@ -626,6 +627,27 @@ int config_initial_parse_file(const char *filename)
|
||||||
return config_parse_file(filename, &_current_configuration);
|
return config_parse_file(filename, &_current_configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Has to be called after xmlParseFile(...) */
|
||||||
|
int config_validate(const xmlDocPtr doc)
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
xmlRelaxNGPtr schema;
|
||||||
|
xmlRelaxNGValidCtxtPtr validctxt;
|
||||||
|
xmlRelaxNGParserCtxtPtr rngparser;
|
||||||
|
|
||||||
|
rngparser = xmlRelaxNGNewParserCtxt("icecast.rng");
|
||||||
|
schema = xmlRelaxNGParse(rngparser);
|
||||||
|
validctxt = xmlRelaxNGNewValidCtxt(schema);
|
||||||
|
|
||||||
|
status = xmlRelaxNGValidateDoc(validctxt, doc);
|
||||||
|
|
||||||
|
xmlRelaxNGFree(schema);
|
||||||
|
xmlRelaxNGFreeValidCtxt(validctxt);
|
||||||
|
xmlRelaxNGFreeParserCtxt(rngparser);
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
int config_parse_file(const char *filename, ice_config_t *configuration)
|
int config_parse_file(const char *filename, ice_config_t *configuration)
|
||||||
{
|
{
|
||||||
xmlDocPtr doc;
|
xmlDocPtr doc;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user