OPTION(MULTIPROCESS_SERVICE_SUPPORT_INLINE "Process per service - inline mode support" OFF)
OPTION(CSP_SUPPORT "Support for csp policy" ON)
OPTION(ALLOW_NAVIGATION_SUPPORT "Support for allow-navigation" ON)
+OPTION(SCHEMA_VALIDATION_SUPPORT "Support for XML schema validation" OFF)
############################# compiler flags ##################################
IF(ALLOW_NAVIGATION_SUPPORT)
ADD_DEFINITIONS("-DALLOW_NAVIGATION_ENABLED")
ENDIF(ALLOW_NAVIGATION_SUPPORT)
+IF(SCHEMA_VALIDATION_SUPPORT)
+ MESSAGE(STATUS "XML Schema validation of installed app enabled")
+ ADD_DEFINITIONS("-DSCHEMA_VALIDATION_ENABLED")
+ENDIF(SCHEMA_VALIDATION_SUPPORT)
# If supported for the target machine, emit position-independent code,suitable
# for dynamic linking and avoiding any limit on the size of the global offset
############################# subdirectories ##################################
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(etc)
+ADD_SUBDIRECTORY(configuration)
IF(WITH_TESTS)
ADD_SUBDIRECTORY(tests)
%attr(755,root,root) %{_bindir}/wrt-installer
%attr(775,root,root) %{_bindir}/wrt_preinstall_widgets.sh
/usr/etc/package-manager/backendlib/libwgt.so
+%attr(644,root,root) /usr/etc/wrt-installer/*.xsd
%{_datadir}/license/%{name}
%{_libdir}/systemd/user/tizen-mobile-session.target.wants/wrt-preinstall-widgets.service
%{_libdir}/systemd/user/wrt-preinstall-widgets.service
#include "parser_runner.h"
#include "root_parser.h"
+#include "stdio.h"
+
#include <stack>
#include <libxml/xmlreader.h>
#include <dpl/binary_queue.h>
class ParserRunner::Impl
{
+ static void logErrorLibxml2(void *, const char *msg, ...)
+ {
+ char buffer[300];
+ va_list args;
+ va_start(args, msg);
+ vsnprintf(buffer, 300, msg, args);
+ va_end(args);
+ LogError(buffer);
+ }
+
+ static void logWarningLibxml2(void *, const char *msg, ...)
+ {
+ char buffer[300];
+ va_list args;
+ va_start(args, msg);
+ vsnprintf(buffer, 300, msg, args);
+ va_end(args);
+ LogWarning(buffer);
+ }
+
public:
+ bool Validate(const std::string& filename, const std::string& schema)
+ {
+ int ret = -1;
+ xmlSchemaParserCtxtPtr ctx;
+ xmlSchemaValidCtxtPtr vctx;
+ xmlSchemaPtr xschema;
+ ctx = xmlSchemaNewParserCtxt(schema.c_str());
+ if (ctx == NULL) {
+ LogError("xmlSchemaNewParserCtxt() Failed");
+ return false;
+ }
+ xschema = xmlSchemaParse(ctx);
+ if (xschema == NULL) {
+ LogError("xmlSchemaParse() Failed");
+ return false;
+ }
+ vctx = xmlSchemaNewValidCtxt(xschema);
+ if (vctx == NULL) {
+ LogError("xmlSchemaNewValidCtxt() Failed");
+ return false;
+ }
+ xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc)&logErrorLibxml2, (xmlSchemaValidityWarningFunc) &logWarningLibxml2, NULL);
+ ret = xmlSchemaValidateFile(vctx, filename.c_str(), 0);
+ if (ret == -1) {
+ LogError("xmlSchemaValidateFile() failed");
+ return false;
+ } else if (ret == 0) {
+ LogError("Config is Valid");
+ return true;
+ } else {
+ LogError("Config Validation Failed with error code " << ret);
+ return false;
+ }
+ return true;
+ }
+
void Parse(const std::string& filename,
const ElementParserPtr& root)
{
m_impl(new ParserRunner::Impl())
{}
+bool ParserRunner::Validate(const std::string& filename, const std::string& schema)
+{
+ return m_impl->Validate(filename, schema);
+}
+
void ParserRunner::Parse(const std::string& filename,
ElementParserPtr root)
{
class ParserRunner : private DPL::Noncopyable
{
public:
+ bool Validate(const std::string& filename, const std::string& schema);
+
void Parse(const std::string& filename,
ElementParserPtr root);
void Parse(DPL::AbstractInput *input,
const char *const WRT_WIDGET_CONFIG_FILE_NAME = "config.xml";
const std::string WINDGET_INSTALL_NETWORK_ACCESS = "network access";
+
+const char WRT_WIDGETS_XML_SCHEMA[] = "/usr/etc/wrt-installer/widgets.xsd";
}
namespace Jobs {
Try
{
ParserRunner parser;
+#ifdef SCHEMA_VALIDATION_ENABLED
+ if(!parser.Validate(configFilePath, WRT_WIDGETS_XML_SCHEMA))
+ {
+ LogError("Invalid configuration file - schema validation failed");
+ return false;
+ }
+#endif
parser.Parse(configFilePath,
ElementParserPtr(new RootParser<WidgetParser>(
configInfo,