diff options
Diffstat (limited to 'src/aul_rsc_mgr_internal.c')
-rw-r--r-- | src/aul_rsc_mgr_internal.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/aul_rsc_mgr_internal.c b/src/aul_rsc_mgr_internal.c index 3b1a5777..760059e4 100644 --- a/src/aul_rsc_mgr_internal.c +++ b/src/aul_rsc_mgr_internal.c @@ -20,11 +20,13 @@ #include <glib.h> #include <libxml/tree.h> +#include <libxml/xmlschemas.h> #include <dlog.h> #include <bundle.h> #include "aul_rsc_mgr_internal.h" +#include "aul_rsc_mgr_schema.h" static char *_get_attribute(xmlNode *xml_node, const char *name) { @@ -145,13 +147,53 @@ static int _parse_resource(xmlNode *xml_node, resource_data_t **data) return 0; } +static int __validate_schema(const char *path) +{ + xmlSchemaParserCtxt *parser_ctxt; + xmlSchema *schema; + xmlSchemaValidCtxt *valid_ctxt; + int ret; + + parser_ctxt = xmlSchemaNewMemParserCtxt(res_schema, sizeof(res_schema)); + if (parser_ctxt == NULL) { + LOGE("failed to create parser context"); + return -1; + } + + schema = xmlSchemaParse(parser_ctxt); + if (schema == NULL) { + LOGE("failed to create schema"); + xmlSchemaFreeParserCtxt(parser_ctxt); + return -1; + } + + valid_ctxt = xmlSchemaNewValidCtxt(schema); + if (valid_ctxt == NULL) { + LOGE("failed to create valid context"); + xmlSchemaFree(schema); + xmlSchemaFreeParserCtxt(parser_ctxt); + return -1; + } + + ret = xmlSchemaValidateFile(valid_ctxt, path, 0); + if (ret) + LOGE("%s: validation failed(%d)", path, ret); + + xmlSchemaFreeValidCtxt(valid_ctxt); + xmlSchemaFree(schema); + xmlSchemaFreeParserCtxt(parser_ctxt); + + return ret; +} + int _resource_open(const char *path, resource_data_t **data) { int ret; xmlDoc *doc; xmlNode *root; - /* TODO: validate ? */ + if (__validate_schema(path)) + return -1; doc = xmlReadFile(path, NULL, 0); if (doc == NULL) return -1; |