JSON Auto correction + hyperion schema split for better readability (#452)

* revoke schema split

* add "getAutoCorrectedConfig" function

* revoke schema split

* revoke schema split

* revoke schema split

* Prevent compiler error if none grabber is available

* revoke schema split

* add "getAutoCorrectedConfig" function

* revoke schema split

* remove "configMigrator"

* remove "configMigrator"

* Change TestConfigFile to show how the autocorrection works

* revoke schema split

* revoke schema split

* remove "ConfigMigrator"

* remove "ConfigMigrator"

* remove "ConfigMigratorBase"

* remove "ConfigMigratorBase"

* Add QJsonUtils.h

* added ability "ignore-required"

It has been added the ability to correct the configuration without having to pay attention to the keyword "required" in the hyperion schema

* Allow Comments in Hyperion Schema

* add ability to ignore the "required" keyword in hyperion schema

* add ability to ignore the "required" keyword in hyperion schema

* add ability to ignore the "required" keyword in hyperion schema

* //Allow Comments in Hyperion Schema

* Update jsonschema.py to version 0.8.0 to support ...

references in json schema

* add RefResolver from jsonschema.py to resolve

references in hyperion schema

* remove dupe code

* split the hyperion schema in separatly files

For better readability

* add function "resolveReferences" to resolve

references in hyperion schema.

* remove CURRENT_CONFIG_VERSION

* remove CURRENT_CONFIG_VERSION

* split the hyperion schema in separatly files

For better readability

* Create schema-backgroundEffect.json

* Add the rest of the Hyperion schema via upload

* Remove Comments in config file

* Add return variable to function writeJson().

fix function resolveReferences().
edit function load() to handle QPair result from schemaChecker.

* edit function validate() to return QPair variable

* fit function loadEffectDefinition()

* fit function checkJson()

*  Expand error check by dividing

"_error" variable in "_error" and "_schemaError".
Replace variable "bool" in validate() in QPair

* Extend function "cmd_cfg_set" to handle auto correction

* Extend function "loadConfig" to handle auto correction

* fix function loadConfig()
This commit is contained in:
Paulchen Panther
2017-07-30 13:32:10 +02:00
committed by brindosch
parent 622a171808
commit 5bd020a570
45 changed files with 2356 additions and 2254 deletions

View File

@@ -150,7 +150,7 @@ bool EffectEngine::loadEffectDefinition(const QString &path, const QString &effe
QJsonSchemaChecker schemaChecker;
schemaChecker.setSchema(configSchema.object());
if (!schemaChecker.validate(configEffect.object()))
if (!schemaChecker.validate(configEffect.object()).first)
{
const QStringList & errors = schemaChecker.getMessages();
foreach (auto & error, errors)

View File

@@ -5,9 +5,84 @@
{
"general" :
{
"type" : "object",
"required" : true
"$ref": "schema-general.json"
},
"logger" :
{
"$ref": "schema-logger.json"
},
"device" :
{
"$ref": "schema-device.json"
},
"color" :
{
"$ref": "schema-color.json"
},
"smoothing":
{
"$ref": "schema-smoothing.json"
},
"grabberV4L2" :
{
"$ref": "schema-grabberV4L2.json"
},
"framegrabber" :
{
"$ref": "schema-framegrabber.json"
},
"blackborderdetector" :
{
"$ref": "schema-blackborderdetector.json"
},
"kodiVideoChecker" :
{
"$ref": "schema-kodiVideoChecker.json"
},
"foregroundEffect" :
{
"$ref": "schema-foregroundEffect.json"
},
"backgroundEffect" :
{
"$ref": "schema-backgroundEffect.json"
},
"forwarder" :
{
"$ref": "schema-forwarder.json"
},
"jsonServer" :
{
"$ref": "schema-jsonServer.json"
},
"protoServer" :
{
"$ref": "schema-protoServer.json"
},
"boblightServer" :
{
"$ref": "schema-boblightServer.json"
},
"udpListener" :
{
"$ref": "schema-udpListener.json"
},
"webConfig" :
{
"$ref": "schema-webConfig.json"
},
"effects" :
{
"$ref": "schema-effects.json"
},
"ledConfig":
{
"$ref": "schema-ledConfig.json"
},
"leds":
{
"$ref": "schema-leds.json"
}
},
"additionalProperties" : true
"additionalProperties" : false
}

View File

@@ -1,8 +1,26 @@
<RCC>
<qresource prefix="/">
<file alias="hyperion-schema">hyperion.schema.json</file>
<file alias="hyperion-schema-1">schemas/hyperion.schema-1.json</file>
<file alias="hyperion-schema-2">schemas/hyperion.schema-2.json</file>
<file alias="hyperion_default.config">../../config/hyperion.config.json.default</file>
</qresource>
<qresource prefix="/">
<file alias="hyperion-schema">hyperion.schema.json</file>
<file alias="hyperion_default.config">../../config/hyperion.config.json.default</file>
<file alias="schema-general.json">schema/schema-general.json</file>
<file alias="schema-logger.json">schema/schema-logger.json</file>
<file alias="schema-device.json">schema/schema-device.json</file>
<file alias="schema-color.json">schema/schema-color.json</file>
<file alias="schema-smoothing.json">schema/schema-smoothing.json</file>
<file alias="schema-grabberV4L2.json">schema/schema-grabberV4L2.json</file>
<file alias="schema-framegrabber.json">schema/schema-framegrabber.json</file>
<file alias="schema-blackborderdetector.json">schema/schema-blackborderdetector.json</file>
<file alias="schema-kodiVideoChecker.json">schema/schema-kodiVideoChecker.json</file>
<file alias="schema-foregroundEffect.json">schema/schema-foregroundEffect.json</file>
<file alias="schema-backgroundEffect.json">schema/schema-backgroundEffect.json</file>
<file alias="schema-forwarder.json">schema/schema-forwarder.json</file>
<file alias="schema-jsonServer.json">schema/schema-jsonServer.json</file>
<file alias="schema-protoServer.json">schema/schema-protoServer.json</file>
<file alias="schema-boblightServer.json">schema/schema-boblightServer.json</file>
<file alias="schema-udpListener.json">schema/schema-udpListener.json</file>
<file alias="schema-webConfig.json">schema/schema-webConfig.json</file>
<file alias="schema-effects.json">schema/schema-effects.json</file>
<file alias="schema-ledConfig.json">schema/schema-ledConfig.json</file>
<file alias="schema-leds.json">schema/schema-leds.json</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,48 @@
{
"type" : "object",
"title" : "edt_conf_bge_heading_title",
"properties" :
{
"enable" :
{
"type" : "boolean",
"title" : "edt_conf_general_enable_title",
"default" : true,
"propertyOrder" : 1
},
"type" :
{
"type" : "string",
"title" : "edt_conf_fge_type_title",
"enum" : ["color", "effect"],
"default" : "effect",
"options" : {
"enum_titles" : ["edt_conf_enum_color", "edt_conf_enum_effect"]
},
"propertyOrder" : 2
},
"color" :
{
"type" : "array",
"format" : "colorpicker",
"title" : "edt_conf_fge_color_title",
"default" : [255,138,0],
"items" : {
"type" : "integer",
"minimum" : 0,
"maximum" : 255
},
"minItems" : 3,
"maxItems" : 3,
"propertyOrder" : 3
},
"effect" :
{
"type" : "string",
"format" : "select",
"title" : "edt_conf_fge_effect_title",
"propertyOrder" : 4
}
},
"additionalProperties" : false
}

View File

@@ -0,0 +1,72 @@
{
"type" : "object",
"title" : "edt_conf_bb_heading_title",
"properties" :
{
"enable" :
{
"type" : "boolean",
"title" : "edt_conf_general_enable_title",
"default" : true,
"propertyOrder" : 1
},
"threshold" :
{
"type" : "integer",
"title" : "edt_conf_bb_threshold_title",
"minimum" : 0,
"maximum" : 100,
"default" : 5,
"append" : "edt_append_percent",
"propertyOrder" : 2
},
"unknownFrameCnt" :
{
"type" : "integer",
"title" : "edt_conf_bb_unknownFrameCnt_title",
"minimum" : 0,
"default" : 600,
"access" : "expert",
"propertyOrder" : 3
},
"borderFrameCnt" :
{
"type" : "integer",
"title" : "edt_conf_bb_borderFrameCnt_title",
"minimum" : 0,
"default" : 50,
"access" : "expert",
"propertyOrder" : 4
},
"maxInconsistentCnt" :
{
"type" : "integer",
"title" : "edt_conf_bb_maxInconsistentCnt_title",
"minimum" : 0,
"default" : 10,
"access" : "expert",
"propertyOrder" : 5
},
"blurRemoveCnt" :
{
"type" : "integer",
"title" : "edt_conf_bb_blurRemoveCnt_title",
"minimum" : 0,
"default" : 1,
"access" : "expert",
"propertyOrder" : 6
},
"mode" :
{
"type" : "string",
"title": "edt_conf_bb_mode_title",
"enum" : ["default", "classic", "osd"],
"default" : "default",
"options" : {
"enum_titles" : ["edt_conf_enum_bbdefault", "edt_conf_enum_bbclassic", "edt_conf_enum_bbosd"]
},
"propertyOrder" : 7
}
},
"additionalProperties" : false
}

View File

@@ -0,0 +1,33 @@
{
"type" : "object",
"title" : "edt_conf_bobls_heading_title",
"properties" :
{
"enable" :
{
"type" : "boolean",
"title" : "edt_conf_general_enable_title",
"default" : false,
"propertyOrder" : 1
},
"port" :
{
"type" : "integer",
"required" : true,
"title" : "edt_conf_general_port_title",
"minimum" : 0,
"maximum" : 65535,
"propertyOrder" : 2
},
"priority" :
{
"type" : "integer",
"title" : "edt_conf_general_priority_title",
"minimum" : 100,
"maximum" : 254,
"default" : 201,
"propertyOrder" : 3
}
},
"additionalProperties" : false
}

View File

@@ -0,0 +1,257 @@
{
"type":"object",
"title" : "edt_conf_color_heading_title",
"required" : true,
"properties":
{
"imageToLedMappingType" :
{
"type" : "string",
"required" : true,
"title" : "edt_conf_color_imageToLedMappingType_title",
"enum" : ["multicolor_mean", "unicolor_mean"],
"default" : "multicolor_mean",
"options" : {
"enum_titles" : ["edt_conf_enum_multicolor_mean", "edt_conf_enum_unicolor_mean"]
},
"propertyOrder" : 1
},
"channelAdjustment" :
{
"type" : "array",
"title" : "edt_conf_color_channelAdjustment_header_title",
"required" : true,
"propertyOrder" : 3,
"items" :
{
"type" : "object",
"required" : true,
"title" : "edt_conf_color_channelAdjustment_header_itemtitle",
"properties" :
{
"id" :
{
"type" : "string",
"title" : "edt_conf_color_id_title",
"required" : true,
"default" : "A userdefined name",
"propertyOrder" : 1
},
"leds" :
{
"type" : "string",
"title" : "edt_conf_color_leds_title",
"required" : true,
"default" : "*",
"propertyOrder" : 2
},
"black" :
{
"type" : "array",
"title" : "edt_conf_color_black_title",
"format" : "colorpicker",
"required" : true,
"default": [0,0,0],
"items" : {
"type" : "integer",
"minimum" : 0,
"maximum" : 255
},
"minItems" : 3,
"maxItems" : 3,
"propertyOrder" : 3
},
"white" :
{
"type" : "array",
"title" : "edt_conf_color_white_title",
"format" : "colorpicker",
"required" : true,
"default": [255,255,255],
"items" : {
"type" : "integer",
"minimum" : 0,
"maximum" : 255
},
"minItems" : 3,
"maxItems" : 3,
"propertyOrder" : 4
},
"red" :
{
"type" : "array",
"title" : "edt_conf_color_red_title",
"format" : "colorpicker",
"required" : true,
"default": [255,0,0],
"items" : {
"type" : "integer",
"minimum" : 0,
"maximum" : 255
},
"minItems" : 3,
"maxItems" : 3,
"propertyOrder" : 5
},
"green" :
{
"type" : "array",
"title" : "edt_conf_color_green_title",
"format" : "colorpicker",
"required" : true,
"default": [0,255,0],
"items" : {
"type" : "integer",
"minimum" : 0,
"maximum" : 255
},
"minItems" : 3,
"maxItems" : 3,
"propertyOrder" : 6
},
"blue" :
{
"type" : "array",
"title" : "edt_conf_color_blue_title",
"format" : "colorpicker",
"required" : true,
"default": [0,0,255],
"items" : {
"type" : "integer",
"minimum" : 0,
"maximum" : 255
},
"minItems" : 3,
"maxItems" : 3,
"propertyOrder" : 7
},
"cyan" :
{
"type" : "array",
"title" : "edt_conf_color_cyan_title",
"format" : "colorpicker",
"required" : true,
"default": [0,255,255],
"items" : {
"type" : "integer",
"minimum" : 0,
"maximum" : 255
},
"minItems" : 3,
"maxItems" : 3,
"propertyOrder" : 8
},
"magenta" :
{
"type" : "array",
"title" : "edt_conf_color_magenta_title",
"format" : "colorpicker",
"required" : true,
"default": [255,0,255],
"items" : {
"type" : "integer",
"minimum" : 0,
"maximum" : 255
},
"minItems" : 3,
"maxItems" : 3,
"propertyOrder" : 9
},
"yellow" :
{
"type" : "array",
"title" : "edt_conf_color_yellow_title",
"format" : "colorpicker",
"required" : true,
"default": [255,255,0],
"items" : {
"type" : "integer",
"minimum" : 0,
"maximum" : 255
},
"minItems" : 3,
"maxItems" : 3,
"propertyOrder" : 10
},
"backlightThreshold" :
{
"type" : "integer",
"title" : "edt_conf_color_backlightThreshold_title",
"required" : true,
"minimum" : 0,
"maximum": 100,
"default" : 0,
"append" : "edt_append_percent",
"propertyOrder" : 11
},
"backlightColored" :
{
"type" : "boolean",
"title" : "edt_conf_color_backlightColored_title",
"required" : true,
"default" : false,
"propertyOrder" : 12
},
"brightness" :
{
"type" : "integer",
"title" : "edt_conf_color_brightness_title",
"required" : true,
"minimum" : 0,
"maximum": 100,
"default" : 100,
"append" : "edt_append_percent",
"propertyOrder" : 13
},
"brightnessCompensation" :
{
"type" : "integer",
"title" : "edt_conf_color_brightnessComp_title",
"required" : true,
"minimum" : 0,
"maximum": 100,
"default" : 90,
"append" : "edt_append_percent",
"access" : "advanced",
"propertyOrder" : 14
},
"gammaRed" :
{
"type" : "number",
"title" : "edt_conf_color_gammaRed_title",
"required" : true,
"minimum" : 0.1,
"maximum": 100.0,
"default" : 1.5,
"step" : 0.1,
"propertyOrder" : 15
},
"gammaGreen" :
{
"type" : "number",
"title" : "edt_conf_color_gammaGreen_title",
"required" : true,
"minimum" : 0.1,
"maximum": 100.0,
"default" : 1.5,
"step" : 0.1,
"propertyOrder" : 16
},
"gammaBlue" :
{
"type" : "number",
"title" : "edt_conf_color_gammaBlue_title",
"required" : true,
"minimum" : 0.1,
"maximum": 100.0,
"default" : 1.5,
"step" : 0.1,
"propertyOrder" : 17
}
},
"additionalProperties" : false
}
}
},
"additionalProperties" : false
}

View File

@@ -0,0 +1,41 @@
{
"type" : "object",
"title" : "edt_dev_general_heading_title",
"required" : true,
"defaultProperties": ["ledCount","colorOrder","rewriteTime","minimumWriteTime"],
"properties" :
{
"type" :
{
"type" : "string"
},
"ledCount" :
{
"type" : "integer",
"minimum" : 0,
"title" : "edt_dev_general_ledCount_title",
"propertyOrder" : 2
},
"colorOrder" :
{
"type" : "string",
"title" : "edt_dev_general_colorOrder_title",
"enum" : ["rgb", "bgr", "rbg", "brg", "gbr", "grb"],
"default" : "rgb",
"options" : {
"enum_titles" : ["edt_conf_enum_rgb", "edt_conf_enum_bgr", "edt_conf_enum_rbg", "edt_conf_enum_brg", "edt_conf_enum_gbr", "edt_conf_enum_grb"]
},
"propertyOrder" : 3
},
"rewriteTime": {
"type": "integer",
"title":"edt_dev_general_rewriteTime_title",
"default": 1000,
"append" : "edt_append_ms",
"minimum": 0,
"access" : "expert",
"propertyOrder" : 4
}
},
"additionalProperties" : true
}

View File

@@ -0,0 +1,29 @@
{
"type" : "object",
"title" : "edt_conf_effp_heading_title",
"properties" :
{
"paths" :
{
"type" : "array",
"title" : "edt_conf_effp_paths_title",
"default" : ["../custom-effects"],
"items" : {
"type": "string",
"title" : "edt_conf_effp_paths_itemtitle"
},
"propertyOrder" : 1
},
"disable" :
{
"type" : "array",
"title" : "edt_conf_effp_disable_title",
"items" : {
"type": "string",
"title" : "edt_conf_effp_disable_itemtitle"
},
"propertyOrder" : 2
}
},
"additionalProperties" : false
}

View File

@@ -0,0 +1,57 @@
{
"type" : "object",
"title" : "edt_conf_fge_heading_title",
"properties" :
{
"enable" :
{
"type" : "boolean",
"title" : "edt_conf_general_enable_title",
"default" : true,
"propertyOrder" : 1
},
"type" :
{
"type" : "string",
"title" : "edt_conf_fge_type_title",
"enum" : ["color", "effect"],
"default" : "effect",
"options" : {
"enum_titles" : ["edt_conf_enum_color", "edt_conf_enum_effect"]
},
"propertyOrder" : 2
},
"color" :
{
"type" : "array",
"format" : "colorpicker",
"title" : "edt_conf_fge_color_title",
"default" : [255,0,0],
"items" : {
"type" : "integer",
"minimum" : 0,
"maximum" : 255
},
"minItems" : 3,
"maxItems" : 3,
"propertyOrder" : 3
},
"effect" :
{
"type" : "string",
"format" : "select",
"title" : "edt_conf_fge_effect_title",
"propertyOrder" : 4
},
"duration_ms" :
{
"type" : "integer",
"title" : "edt_conf_fge_duration_ms_title",
"default" : 3000,
"minimum" : 100,
"append" : "edt_append_ms",
"propertyOrder" : 5
}
},
"additionalProperties" : false
}

View File

@@ -0,0 +1,36 @@
{
"type" : "object",
"title" : "edt_conf_fw_heading_title",
"required" : true,
"properties" :
{
"enable" :
{
"type" : "boolean",
"title" : "edt_conf_general_enable_title",
"propertyOrder" : 1
},
"json" :
{
"type" : "array",
"title" : "edt_conf_fw_json_title",
"required" : true,
"items" : {
"type": "string",
"title" : "edt_conf_fw_json_itemtitle"
},
"propertyOrder" : 2
},
"proto" :
{
"type" : "array",
"title" : "edt_conf_fw_proto_title",
"items" : {
"type": "string",
"title" : "edt_conf_fw_proto_itemtitle"
},
"propertyOrder" : 3
}
},
"additionalProperties" : false
}

View File

@@ -0,0 +1,132 @@
{
"type" : "object",
"title" : "edt_conf_fg_heading_title",
"properties" :
{
"enable" :
{
"type" : "boolean",
"title" : "edt_conf_general_enable_title",
"default" : true,
"propertyOrder" : 1
},
"type" :
{
"type" : "string",
"title" : "edt_conf_fg_type_title",
"enum" : ["auto","dispmanx","amlogic","x11","framebuffer"],
"default" : "auto",
"propertyOrder" : 2
},
"width" :
{
"type" : "integer",
"title" : "edt_conf_fg_width_title",
"minimum" : 10,
"default" : 80,
"append" : "edt_append_pixel",
"propertyOrder" : 3
},
"height" :
{
"type" : "integer",
"title" : "edt_conf_fg_height_title",
"minimum" : 10,
"default" : 45,
"append" : "edt_append_pixel",
"propertyOrder" : 3
},
"frequency_Hz" :
{
"type" : "integer",
"title" : "edt_conf_fg_frequency_Hz_title",
"minimum" : 1,
"default" : 10,
"append" : "edt_append_hz",
"propertyOrder" : 4
},
"priority" :
{
"type" : "integer",
"title" : "edt_conf_general_priority_title",
"minimum" : 100,
"maximum" : 254,
"default" : 250,
"propertyOrder" : 5
},
"cropLeft" :
{
"type" : "integer",
"title" : "edt_conf_v4l2_cropLeft_title",
"minimum" : 0,
"default" : 0,
"append" : "edt_append_pixel",
"propertyOrder" : 6
},
"cropRight" :
{
"type" : "integer",
"title" : "edt_conf_v4l2_cropRight_title",
"minimum" : 0,
"default" : 0,
"append" : "edt_append_pixel",
"propertyOrder" : 7
},
"cropTop" :
{
"type" : "integer",
"title" : "edt_conf_v4l2_cropTop_title",
"minimum" : 0,
"default" : 0,
"append" : "edt_append_pixel",
"propertyOrder" : 8
},
"cropBottom" :
{
"type" : "integer",
"title" : "edt_conf_v4l2_cropBottom_title",
"minimum" : 0,
"default" : 0,
"append" : "edt_append_pixel",
"propertyOrder" : 9
},
"useXGetImage" :
{
"type" : "boolean",
"title" : "edt_conf_fg_useXGetImage_title",
"default" : false,
"propertyOrder" : 10
},
"horizontalPixelDecimation" :
{
"type" : "integer",
"title" : "edt_conf_fg_horizontalPixelDecimation_title",
"minimum" : 0,
"default" : 8,
"propertyOrder" : 11
},
"verticalPixelDecimation" :
{
"type" : "integer",
"title" : "edt_conf_fg_verticalPixelDecimation_title",
"minimum" : 0,
"default" : 8,
"propertyOrder" : 12
},
"device" :
{
"type" : "string",
"title" : "edt_conf_fg_device_title",
"default" : "/dev/fb0",
"propertyOrder" : 13
},
"display" :
{
"type" : "integer",
"title" : "edt_conf_fg_display_title",
"minimum" : 0,
"propertyOrder" : 14
}
},
"additionalProperties" : false
}

View File

@@ -0,0 +1,34 @@
{
"type" : "object",
"title" : "edt_conf_gen_heading_title",
"required" : true,
"properties" :
{
"name" :
{
"type" : "string",
"title" : "edt_conf_gen_name_title",
"default" : "My Hyperion Config",
"minLength" : 4,
"maxLength" : 20,
"required" : true,
"propertyOrder" : 1
},
"showOptHelp" :
{
"type" : "boolean",
"title" : "edt_conf_gen_showOptHelp_title",
"default" : true,
"required" : true,
"propertyOrder" : 2
},
"configVersion" :
{
"type" : "integer",
"default" : 2,
"minimum" : 1,
"access" : "system",
"required" : true
}
}
}

View File

@@ -0,0 +1,226 @@
{
"type":"array",
"title" : "edt_conf_v4l2_heading_title",
"minItems": 1,
"maxItems": 2,
"items":
{
"type" : "object",
"title" : "edt_conf_v4l2_heading_title",
"properties" :
{
"enable" :
{
"type" : "boolean",
"title" : "edt_conf_general_enable_title",
"default" : false,
"propertyOrder" : 1
},
"device" :
{
"type" : "string",
"title" : "edt_conf_v4l2_device_title",
"default" : "auto",
"propertyOrder" : 2
},
"input" :
{
"type" : "integer",
"title" : "edt_conf_v4l2_input_title",
"minimum" : 0,
"default" : 0,
"propertyOrder" : 3
},
"standard" :
{
"type" : "string",
"title" : "edt_conf_v4l2_standard_title",
"enum" : ["PAL","NTSC"],
"default" : "PAL",
"options" : {
"enum_titles" : ["edt_conf_enum_PAL", "edt_conf_enum_NTSC"]
},
"propertyOrder" : 4
},
"width" :
{
"type" : "integer",
"title" : "edt_conf_v4l2_width_title",
"minimum" : -1,
"default" : -1,
"append" : "edt_append_pixel",
"propertyOrder" : 5
},
"height" :
{
"type" : "integer",
"title" : "edt_conf_v4l2_height_title",
"minimum" : -1,
"default" : -1,
"append" : "edt_append_pixel",
"propertyOrder" : 6
},
"frameDecimation" :
{
"type" : "integer",
"title" : "edt_conf_v4l2_frameDecimation_title",
"minimum" : 0,
"default" : 2,
"propertyOrder" : 7
},
"sizeDecimation" :
{
"type" : "integer",
"title" : "Size decimation",
"minimum" : 0,
"default" : 6,
"propertyOrder" : 8
},
"priority" :
{
"type" : "integer",
"minimum" : 100,
"maximum" : 253,
"title" : "edt_conf_general_priority_title",
"default" : 240,
"propertyOrder" : 9
},
"mode" :
{
"type" : "string",
"title" : "edt_conf_v4l2_mode_title",
"enum" : ["2D","3DSBS","3DTAB"],
"default" : "2D",
"propertyOrder" : 10
},
"useKodiChecker" :
{
"type" : "boolean",
"title" : "edt_conf_v4l2_useKodiChecker_title",
"default" : false,
"propertyOrder" : 11
},
"cropLeft" :
{
"type" : "integer",
"title" : "edt_conf_v4l2_cropLeft_title",
"minimum" : 0,
"default" : 0,
"append" : "edt_append_pixel",
"propertyOrder" : 12
},
"cropRight" :
{
"type" : "integer",
"title" : "edt_conf_v4l2_cropRight_title",
"minimum" : 0,
"default" : 0,
"append" : "edt_append_pixel",
"propertyOrder" : 13
},
"cropTop" :
{
"type" : "integer",
"title" : "edt_conf_v4l2_cropTop_title",
"minimum" : 0,
"default" : 0,
"append" : "edt_append_pixel",
"propertyOrder" : 14
},
"cropBottom" :
{
"type" : "integer",
"title" : "edt_conf_v4l2_cropBottom_title",
"minimum" : 0,
"default" : 0,
"append" : "edt_append_pixel",
"propertyOrder" : 15
},
"signalDetection" :
{
"type" : "boolean",
"title" : "edt_conf_v4l2_signalDetection_title",
"default" : true,
"propertyOrder" : 16
},
"redSignalThreshold" :
{
"type" : "number",
"title" : "edt_conf_v4l2_redSignalThreshold_title",
"minimum" : 0.0,
"maximum" : 1.0,
"default" : 0.1,
"step" : 0.005,
"append" : "edt_append_percent",
"propertyOrder" : 17
},
"greenSignalThreshold" :
{
"type" : "number",
"title" : "edt_conf_v4l2_greenSignalThreshold_title",
"minimum" : 0.0,
"maximum" : 1.0,
"default" : 0.1,
"step" : 0.025,
"append" : "edt_append_percent",
"propertyOrder" : 18
},
"blueSignalThreshold" :
{
"type" : "number",
"title" : "edt_conf_v4l2_blueSignalThreshold_title",
"minimum" : 0.0,
"maximum" : 1.0,
"default" : 0.1,
"step" : 0.005,
"append" : "edt_append_percent",
"propertyOrder" : 19
},
"signalDetectionVerticalOffsetMin" :
{
"type" : "number",
"title" : "edt_conf_v4l2_signalDetectionVerticalOffsetMin_title",
"minimum" : 0.0,
"maximum" : 1.0,
"default" : 0.1,
"step" : 0.005,
"append" : "edt_append_percent",
"propertyOrder" : 20
},
"signalDetectionVerticalOffsetMax" :
{
"type" : "number",
"title" : "edt_conf_v4l2_signalDetectionVerticalOffsetMax_title",
"minimum" : 0.0,
"maximum" : 1.0,
"default" : 0.1,
"step" : 0.005,
"append" : "edt_append_percent",
"propertyOrder" : 21
},
"signalDetectionHorizontalOffsetMin" :
{
"type" : "number",
"title" : "edt_conf_v4l2_signalDetectionHorizontalOffsetMin_title",
"minimum" : 0.0,
"maximum" : 1.0,
"default" : 0.1,
"step" : 0.005,
"append" : "edt_append_percent",
"propertyOrder" : 22
},
"signalDetectionHorizontalOffsetMax" :
{
"type" : "number",
"title" : "edt_conf_v4l2_signalDetectionHorizontalOffsetMax_title",
"minimum" : 0.0,
"maximum" : 1.0,
"default" : 0.1,
"step" : 0.005,
"append" : "edt_append_percent",
"propertyOrder" : 23
}
},
"additionalProperties" : false
}
}

View File

@@ -0,0 +1,18 @@
{
"type" : "object",
"required" : true,
"title" : "edt_conf_js_heading_title",
"properties" :
{
"port" :
{
"type" : "integer",
"required" : true,
"title" : "edt_conf_general_port_title",
"minimum" : 0,
"maximum" : 65535,
"default" : 19444
}
},
"additionalProperties" : false
}

View File

@@ -0,0 +1,80 @@
{
"type" : "object",
"title" : "edt_conf_kodic_heading_title",
"properties" :
{
"enable" :
{
"type" : "boolean",
"title" : "edt_conf_general_enable_title",
"default" : false,
"propertyOrder" : 1
},
"kodiAddress" :
{
"type" : "string",
"title" : "edt_conf_kodic_kodiAddress_title",
"default" : "127.0.0.1",
"propertyOrder" : 2
},
"kodiTcpPort" :
{
"type" : "integer",
"title" : "edt_conf_kodic_kodiTcpPort_title",
"minimum" : 0,
"maximum" : 65535,
"default" : 9090,
"propertyOrder" : 3
},
"grabVideo" :
{
"type" : "boolean",
"title" : "edt_conf_kodic_grabVideo_title",
"default" : true,
"propertyOrder" : 4
},
"grabPictures" :
{
"type" : "boolean",
"title" : "edt_conf_kodic_grabPictures_title",
"default" : true,
"propertyOrder" : 5
},
"grabAudio" :
{
"type" : "boolean",
"title" : "edt_conf_kodic_grabAudio_title",
"default" : true,
"propertyOrder" : 6
},
"grabMenu" :
{
"type" : "boolean",
"title" : "edt_conf_kodic_grabMenu_title",
"default" : false,
"propertyOrder" : 7
},
"grabPause" :
{
"type" : "boolean",
"title" : "edt_conf_kodic_grabPause_title",
"default" : false,
"propertyOrder" : 8
},
"grabScreensaver" :
{
"type" : "boolean",
"title" : "edt_conf_kodic_grabScreensaver_title",
"default" : false,
"propertyOrder" : 9
},
"enable3DDetection" :
{
"type" : "boolean",
"title" : "edt_conf_kodic_enable3DDetection_title",
"default" : false,
"propertyOrder" : 10
}
},
"additionalProperties" : false
}

View File

@@ -0,0 +1,80 @@
{
"type" : "object",
"properties" :
{
"top" :
{
"type" : "integer",
"minimum" : 0,
"default" : 8
},
"bottom" :
{
"type" : "integer",
"minimum" : 0,
"default" : 8
},
"left" :
{
"type" : "integer",
"minimum" : 0,
"default" : 5
},
"right" :
{
"type" : "integer",
"minimum" : 0,
"default" : 5
},
"glength" :
{
"type" : "integer",
"minimum" : 0,
"default" : 0
},
"gpos" :
{
"type" : "integer",
"minimum" : 0,
"default" : 0
},
"position" :
{
"type" : "integer",
"default" : 0
},
"reverse" :
{
"type" : "boolean",
"default" : false
},
"hdepth" :
{
"type" : "integer",
"minimum" : 1,
"maximum" : 100,
"default" : 8
},
"vdepth" :
{
"type" : "integer",
"minimum" : 1,
"maximum" : 100,
"default" : 5
},
"overlap" :
{
"type" : "integer",
"minimum" : 0,
"default" : 0
},
"edgegap" :
{
"type" : "integer",
"minimum" : 0,
"maximum" : 50,
"default" : 0
}
},
"additionalProperties" : false
}

View File

@@ -0,0 +1,70 @@
{
"type":"array",
"required":true,
"items":
{
"type":"object",
"properties":
{
"index":
{
"type":"integer",
"required":true
},
"clone":
{
"type":"integer"
},
"hscan":
{
"type":"object",
"properties":
{
"minimum":
{
"type":"number",
"minimum" : 0,
"maximum" : 1,
"required":true
},
"maximum":
{
"type":"number",
"minimum" : 0,
"maximum" : 1,
"required":true
}
},
"additionalProperties" : false
},
"vscan":
{
"type":"object",
"properties":
{
"minimum":
{
"type":"number",
"minimum" : 0,
"maximum" : 1,
"required":true
},
"maximum":
{
"type":"number",
"minimum" : 0,
"maximum" : 1,
"required":true
}
},
"additionalProperties" : false
},
"colorOrder":
{
"type": "string",
"enum" : ["rgb", "bgr", "rbg", "brg", "gbr", "grb"]
}
},
"additionalProperties" : false
}
}

View File

@@ -0,0 +1,18 @@
{
"type" : "object",
"title" : "edt_conf_log_heading_title",
"properties" :
{
"level" :
{
"type" : "string",
"enum" : ["silent", "warn", "verbose", "debug"],
"title" : "edt_conf_log_level_title",
"options" : {
"enum_titles" : ["edt_conf_enum_logsilent", "edt_conf_enum_logwarn", "edt_conf_enum_logverbose", "edt_conf_enum_logdebug"]
},
"default" : "warn"
}
},
"additionalProperties" : false
}

View File

@@ -0,0 +1,18 @@
{
"type" : "object",
"required" : true,
"title" : "edt_conf_ps_heading_title",
"properties" :
{
"port" :
{
"type" : "integer",
"required" : true,
"title" : "edt_conf_general_port_title",
"minimum" : 0,
"maximum" : 65535,
"default" : 19445
}
},
"additionalProperties" : false
}

View File

@@ -0,0 +1,63 @@
{
"type" : "object",
"title" : "edt_conf_smooth_heading_title",
"properties" :
{
"enable" :
{
"type" : "boolean",
"title" : "edt_conf_general_enable_title",
"default" : true,
"propertyOrder" : 1
},
"type" :
{
"type" : "string",
"title" : "edt_conf_smooth_type_title",
"enum" : ["linear"],
"default" : "linear",
"options" : {
"enum_titles" : ["edt_conf_enum_linear"]
},
"propertyOrder" : 2
},
"time_ms" :
{
"type" : "integer",
"title" : "edt_conf_smooth_time_ms_title",
"minimum" : 25,
"maximum": 600,
"default" : 200,
"append" : "edt_append_ms",
"propertyOrder" : 3
},
"updateFrequency" :
{
"type" : "number",
"title" : "edt_conf_smooth_updateFrequency_title",
"minimum" : 1.0,
"maximum" : 100.0,
"default" : 25.0,
"append" : "edt_append_hz",
"propertyOrder" : 4
},
"updateDelay" :
{
"type" : "integer",
"title" : "edt_conf_smooth_updateDelay_title",
"minimum" : 0,
"maximum": 2048,
"default" : 0,
"append" : "edt_append_ms",
"propertyOrder" : 5
},
"continuousOutput" :
{
"type" : "boolean",
"title" : "edt_conf_smooth_continuousOutput_title",
"default" : true,
"propertyOrder" : 6
}
},
"additionalProperties" : false
}

View File

@@ -0,0 +1,56 @@
{
"type" : "object",
"title" : "edt_conf_udpl_heading_title",
"properties" :
{
"enable" :
{
"type" : "boolean",
"title" : "edt_conf_general_enable_title",
"default" : false,
"propertyOrder" : 1
},
"address" :
{
"type" : "string",
"title" : "edt_conf_udpl_address_title",
"default" : "239.255.28.01",
"propertyOrder" : 2
},
"port" :
{
"type" : "integer",
"title" : "edt_conf_general_port_title",
"minimum" : 0,
"maximum" : 65535,
"default" : 2801,
"propertyOrder" : 3
},
"priority" :
{
"type" : "integer",
"title" : "edt_conf_general_priority_title",
"minimum" : 100,
"maximum" : 254,
"default" : 200,
"propertyOrder" : 4
},
"timeout" :
{
"type" : "integer",
"title" : "edt_conf_udpl_timeout_title",
"minimum" : 1000,
"default" : 10000,
"append" : "edt_append_ms",
"propertyOrder" : 5
},
"shared" :
{
"type" : "boolean",
"title" : "edt_conf_udpl_shared_title",
"default" : false,
"propertyOrder" : 6
}
},
"additionalProperties" : false
}

View File

@@ -0,0 +1,33 @@
{
"type" : "object",
"title" : "edt_conf_webc_heading_title",
"properties" :
{
"enable" :
{
"type" : "boolean",
"title" : "edt_conf_general_enable_title",
"default" : true,
"access" : "expert",
"propertyOrder" : 1
},
"document_root" :
{
"type" : "string",
"title" : "edt_conf_webc_docroot_title",
"access" : "expert",
"propertyOrder" : 2
},
"port" :
{
"type" : "integer",
"title" : "edt_conf_general_port_title",
"minimum" : 0,
"maximum" : 65535,
"default" : 8099,
"access" : "expert",
"propertyOrder" : 3
}
},
"additionalProperties" : false
}

View File

@@ -1,386 +0,0 @@
{
"type" : "object",
"required" : true,
"properties" : {
"device" : {
"type" : "object",
"required" : true,
"properties" : {
"name" : {
"type" : "string",
"required" : true
},
"type" : {
"type" : "string",
"required" : true
},
"output" : {
"type" : "string",
"required" : true
},
"rate" : {
"type" : "integer",
"required" : true,
"minimum" : 0
},
"colorOrder" : {
"type" : "string",
"required" : false
},
"bgr-output" : {
"type" : "boolean",
"required" : false
}
},
"additionalProperties" : false
},
"color": {
"type":"object",
"required":false,
"properties": {
"hsv" : {
"type" : "object",
"required" : false,
"properties" : {
"saturationGain" : {
"type" : "number",
"required" : false,
"minimum" : 0.0
},
"valueGain" : {
"type" : "number",
"required" : false,
"minimum" : 0.0
}
},
"additionalProperties" : false
},
"hsl" : {
"type" : "object",
"required" : false,
"properties" : {
"saturationGain" : {
"type" : "number",
"required" : false,
"minimum" : 0.0
},
"luminanceGain" : {
"type" : "number",
"required" : false,
"minimum" : 0.0
},
"luminanceMinimum" : {
"type" : "number",
"required" : false,
"minimum" : 0.0
}
},
"additionalProperties" : false
},
"red": {
"type":"object",
"required":false,
"properties":{
"gamma": {
"type":"number",
"required":false
},
"blacklevel": {
"type":"number",
"required":false
},
"whitelevel": {
"type":"number",
"required":false
},
"threshold": {
"type":"number",
"required":false,
"minimum" : 0.0,
"maximum" : 1.0
}
},
"additionalProperties" : false
},
"green": {
"type":"object",
"required":false,
"properties":{
"gamma": {
"type":"number",
"required":false
},
"blacklevel": {
"type":"number",
"required":false
},
"whitelevel": {
"type":"number",
"required":false
},
"threshold": {
"type":"number",
"required":false,
"minimum" : 0.0,
"maximum" : 1.0
}
},
"additionalProperties" : false
},
"blue": {
"type":"object",
"required":false,
"properties":{
"gamma": {
"type":"number",
"required":false
},
"whitelevel": {
"type":"number",
"required":false
},
"blacklevel": {
"type":"number",
"required":false
},
"threshold": {
"type":"number",
"required":false,
"minimum" : 0.0,
"maximum" : 1.0
}
},
"additionalProperties" : false
},
"smoothing" : {
"type" : "object",
"required" : false,
"properties" : {
"type" : {
"type" : "enum",
"required" : true,
"values" : ["none", "linear"]
},
"time_ms" : {
"type" : "integer",
"required" : false,
"minimum" : 10
},
"updateFrequency" : {
"type" : "number",
"required" : false,
"minimum" : 0.001
}
},
"additionalProperties" : false
}
},
"additionalProperties" : false
},
"leds": {
"type":"array",
"required":true,
"items": {
"type":"object",
"properties": {
"index": {
"type":"integer",
"required":true
},
"hscan": {
"type":"object",
"required":true,
"properties": {
"minimum": {
"type":"number",
"required":true
},
"maximum": {
"type":"number",
"required":true
}
},
"additionalProperties" : false
},
"vscan": {
"type":"object",
"required":true,
"properties": {
"minimum": {
"type":"number",
"required":true
},
"maximum": {
"type":"number",
"required":true
}
},
"additionalProperties" : false
},
"colorOrder" : {
"type" : "string",
"required" : false
}
},
"additionalProperties" : false
}
},
"effects" :
{
"type" : "object",
"required" : false,
"properties" : {
"paths" : {
"type" : "array",
"required" : false,
"items" : {
"type" : "string"
}
}
},
"additionalProperties" : false
},
"blackborderdetector" :
{
"type" : "object",
"required" : false,
"properties" : {
"enable" : {
"type" : "boolean",
"required" : true
},
"threshold" : {
"type" : "number",
"required" : false,
"minimum" : 0.0,
"maximum" : 1.0
}
},
"additionalProperties" : false
},
"xbmcVideoChecker" :
{
"type" : "object",
"required" : false,
"properties" : {
"xbmcAddress" : {
"type" : "string",
"required" : true
},
"xbmcTcpPort" : {
"type" : "integer",
"required" : true
},
"grabVideo" : {
"type" : "boolean",
"required" : true
},
"grabPictures" : {
"type" : "boolean",
"required" : true
},
"grabAudio" : {
"type" : "boolean",
"required" : true
},
"grabMenu" : {
"type" : "boolean",
"required" : true
},
"grabPause" : {
"type" : "boolean",
"required" : false
},
"grabScreensaver" : {
"type" : "boolean",
"required" : false
},
"enable3DDetection" : {
"type" : "boolean",
"required" : false
}
},
"additionalProperties" : false
},
"bootsequence" :
{
"type" : "object",
"required" : false,
"properties" : {
"path" : {
"type" : "string",
"required" : true
},
"effect" : {
"type" : "string",
"required" : true
}
},
"additionalProperties" : false
},
"framegrabber" :
{
"type" : "object",
"required" : false,
"properties" : {
"width" : {
"type" : "integer",
"required" : true
},
"height" : {
"type" : "integer",
"required" : true
},
"frequency_Hz" : {
"type" : "integer",
"required" : true
}
},
"additionalProperties" : false
},
"jsonServer" :
{
"type" : "object",
"required" : false,
"properties" : {
"port" : {
"type" : "integer",
"required" : true,
"minimum" : 0,
"maximum" : 65535
}
},
"additionalProperties" : false
},
"protoServer" :
{
"type" : "object",
"required" : false,
"properties" : {
"port" : {
"type" : "integer",
"required" : true,
"minimum" : 0,
"maximum" : 65535
}
},
"additionalProperties" : false
},
"boblightServer" :
{
"type" : "object",
"required" : false,
"properties" : {
"port" : {
"type" : "integer",
"required" : true,
"minimum" : 0,
"maximum" : 65535
}
},
"additionalProperties" : false
}
},
"additionalProperties" : false
}

File diff suppressed because it is too large Load Diff

View File

@@ -27,6 +27,7 @@ SET(Utils_HEADERS
${CURRENT_HEADER_DIR}/RgbToRgbw.h
${CURRENT_HEADER_DIR}/jsonschema/QJsonFactory.h
${CURRENT_HEADER_DIR}/jsonschema/QJsonSchemaChecker.h
${CURRENT_HEADER_DIR}/jsonschema/QJsonUtils.h
${CURRENT_HEADER_DIR}/global_defines.h
${CURRENT_HEADER_DIR}/SysInfo.h
)

View File

@@ -15,7 +15,6 @@
#include <QFile>
#include <QFileInfo>
#include <QJsonDocument>
#include <QVariantMap>
#include <QDir>
#include <QImage>
#include <QBuffer>
@@ -594,6 +593,7 @@ void JsonProcessor::handleServerInfoCommand(const QJsonObject&, const QString& c
ledDevices["available"] = availableLedDevices;
info["ledDevices"] = ledDevices;
#if defined(ENABLE_DISPMANX) || defined(ENABLE_V4L2) || defined(ENABLE_FB) || defined(ENABLE_AMLOGIC) || defined(ENABLE_OSX) || defined(ENABLE_X11)
// get available grabbers
QJsonObject grabbers;
//grabbers["active"] = ????;
@@ -605,6 +605,9 @@ void JsonProcessor::handleServerInfoCommand(const QJsonObject&, const QString& c
grabbers["available"] = availableGrabbers;
info["grabbers"] = grabbers;
#else
info["grabbers"] = QString("none");
#endif
// get available components
QJsonArray component;
@@ -844,45 +847,19 @@ void JsonProcessor::handleSchemaGetCommand(const QJsonObject& message, const QSt
// make sure the resources are loaded (they may be left out after static linking)
Q_INIT_RESOURCE(resource);
QJsonParseError error;
// read the hyperion json schema from the resource
QFile schemaData(":/hyperion-schema-"+QString::number(_hyperion->getConfigVersionId()));
QString schemaFile = ":/hyperion-schema";
if (!schemaData.open(QIODevice::ReadOnly))
try
{
std::stringstream error;
error << "Schema not found: " << schemaData.errorString().toStdString();
throw std::runtime_error(error.str());
schemaJson = QJsonFactory::readSchema(schemaFile);
}
QByteArray schema = schemaData.readAll();
QJsonDocument doc = QJsonDocument::fromJson(schema, &error);
schemaData.close();
if (error.error != QJsonParseError::NoError)
catch(const std::runtime_error& error)
{
// report to the user the failure and their locations in the document.
int errorLine(0), errorColumn(0);
for( int i=0, count=qMin( error.offset,schema.size()); i<count; ++i )
{
++errorColumn;
if(schema.at(i) == '\n' )
{
errorColumn = 0;
++errorLine;
}
}
std::stringstream sstream;
sstream << "ERROR: Json schema wrong: " << error.errorString().toStdString() << " at Line: " << errorLine << ", Column: " << errorColumn;
throw std::runtime_error(sstream.str());
throw std::runtime_error(error.what());
}
schemaJson = doc.object();
// collect all LED Devices
properties = schemaJson["properties"].toObject();
alldevices = LedDevice::getLedDeviceSchemas();
@@ -1139,7 +1116,7 @@ bool JsonProcessor::checkJson(const QJsonObject& message, const QString& schemaR
schemaChecker.setSchema(schemaJson.object());
// check the message
if (!schemaChecker.validate(message, ignoreRequired))
if (!schemaChecker.validate(message, ignoreRequired).first)
{
const QStringList & errors = schemaChecker.getMessages();
errorMessage = "{";

View File

@@ -5,6 +5,7 @@
// Utils-Jsonschema includes
#include <utils/jsonschema/QJsonSchemaChecker.h>
#include <utils/jsonschema/QJsonUtils.h>
QJsonSchemaChecker::QJsonSchemaChecker()
{
@@ -25,11 +26,12 @@ bool QJsonSchemaChecker::setSchema(const QJsonObject & schema)
return true;
}
bool QJsonSchemaChecker::validate(const QJsonObject & value, bool ignoreRequired)
QPair<bool, bool> QJsonSchemaChecker::validate(const QJsonObject & value, bool ignoreRequired)
{
// initialize state
_ignoreRequired = ignoreRequired;
_error = false;
_schemaError = false;
_messages.clear();
_currentPath.clear();
_currentPath.append("[root]");
@@ -37,7 +39,27 @@ bool QJsonSchemaChecker::validate(const QJsonObject & value, bool ignoreRequired
// validate
validate(value, _qSchema);
return !_error;
return QPair<bool, bool>(!_error, !_schemaError);
}
QJsonObject QJsonSchemaChecker::getAutoCorrectedConfig(const QJsonObject& value, bool ignoreRequired)
{
_ignoreRequired = ignoreRequired;
QStringList sequence = QStringList() << "remove" << "modify" << "create";
_error = false;
_schemaError = false;
_messages.clear();
_autoCorrected = value;
for(const QString &correct : sequence)
{
_correct = correct;
_currentPath.clear();
_currentPath.append("[root]");
validate(_autoCorrected, _qSchema);
}
return _autoCorrected;
}
void QJsonSchemaChecker::validate(const QJsonValue & value, const QJsonObject &schema)
@@ -48,15 +70,17 @@ void QJsonSchemaChecker::validate(const QJsonValue & value, const QJsonObject &s
QString attribute = i.key();
const QJsonValue & attributeValue = *i;
QJsonObject::const_iterator defaultValue = schema.find("default");
if (attribute == "type")
checkType(value, attributeValue);
checkType(value, attributeValue, (defaultValue != schema.end() ? defaultValue.value() : QJsonValue::Null));
else if (attribute == "properties")
{
if (value.isObject())
checkProperties(value.toObject(), attributeValue.toObject());
else
{
_error = true;
_schemaError = true;
setMessage("properties attribute is only valid for objects");
continue;
}
@@ -76,19 +100,19 @@ void QJsonSchemaChecker::validate(const QJsonValue & value, const QJsonObject &s
}
else
{
_error = true;
_schemaError = true;
setMessage("additional properties attribute is only valid for objects");
continue;
}
}
else if (attribute == "minimum")
checkMinimum(value, attributeValue);
checkMinimum(value, attributeValue, (defaultValue != schema.end() ? defaultValue.value() : QJsonValue::Null));
else if (attribute == "maximum")
checkMaximum(value, attributeValue);
checkMaximum(value, attributeValue, (defaultValue != schema.end() ? defaultValue.value() : QJsonValue::Null));
else if (attribute == "minLength")
checkMinLength(value, attributeValue);
checkMinLength(value, attributeValue, (defaultValue != schema.end() ? defaultValue.value() : QJsonValue::Null));
else if (attribute == "maxLength")
checkMaxLength(value, attributeValue);
checkMaxLength(value, attributeValue, (defaultValue != schema.end() ? defaultValue.value() : QJsonValue::Null));
else if (attribute == "items")
{
if (value.isArray())
@@ -101,13 +125,13 @@ void QJsonSchemaChecker::validate(const QJsonValue & value, const QJsonObject &s
}
}
else if (attribute == "minItems")
checkMinItems(value, attributeValue);
checkMinItems(value, attributeValue, (defaultValue != schema.end() ? defaultValue.value() : QJsonValue::Null));
else if (attribute == "maxItems")
checkMaxItems(value, attributeValue);
checkMaxItems(value, attributeValue, (defaultValue != schema.end() ? defaultValue.value() : QJsonValue::Null));
else if (attribute == "uniqueItems")
checkUniqueItems(value, attributeValue);
else if (attribute == "enum")
checkEnum(value, attributeValue);
checkEnum(value, attributeValue, (defaultValue != schema.end() ? defaultValue.value() : QJsonValue::Null));
else if (attribute == "required")
; // nothing to do. value is present so always oke
else if (attribute == "id")
@@ -118,7 +142,7 @@ void QJsonSchemaChecker::validate(const QJsonValue & value, const QJsonObject &s
else
{
// no check function defined for this attribute
_error = true;
_schemaError = true;
setMessage("No check function defined for attribute " + attribute);
continue;
}
@@ -135,7 +159,7 @@ const QStringList & QJsonSchemaChecker::getMessages() const
return _messages;
}
void QJsonSchemaChecker::checkType(const QJsonValue & value, const QJsonValue & schema)
void QJsonSchemaChecker::checkType(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue)
{
QString type = schema.toString();
@@ -145,7 +169,12 @@ void QJsonSchemaChecker::checkType(const QJsonValue & value, const QJsonValue &
else if (type == "number")
wrongType = !value.isDouble();
else if (type == "integer")
wrongType = (rint(value.toDouble()) != value.toDouble());
{
if (value.isDouble()) //check if value type not boolean (true = 1 && false = 0)
wrongType = (rint(value.toDouble()) != value.toDouble());
else
wrongType = true;
}
else if (type == "double")
wrongType = !value.isDouble();
else if (type == "boolean")
@@ -160,13 +189,16 @@ void QJsonSchemaChecker::checkType(const QJsonValue & value, const QJsonValue &
wrongType = !value.isString();
else if (type == "any")
wrongType = false;
// else
// assert(false);
if (wrongType)
{
_error = true;
setMessage(type + " expected");
if (_correct == "modify")
QJsonUtils::modify(_autoCorrected, _currentPath, defaultValue);
if (_correct == "")
setMessage(type + " expected");
}
}
@@ -176,7 +208,7 @@ void QJsonSchemaChecker::checkProperties(const QJsonObject & value, const QJsonO
{
QString property = i.key();
const QJsonValue & propertyValue = i.value();
const QJsonValue & propertyValue = *i;
_currentPath.append("." + property);
QJsonObject::const_iterator required = propertyValue.toObject().find("required");
@@ -185,11 +217,19 @@ void QJsonSchemaChecker::checkProperties(const QJsonObject & value, const QJsonO
{
validate(value[property], propertyValue.toObject());
}
else if (required != propertyValue.toObject().end() && required.value().toBool() && !_ignoreRequired)
else if (required != propertyValue.toObject().end() && propertyValue.toObject().find("required").value().toBool() && !_ignoreRequired)
{
_error = true;
setMessage("missing member");
if (_correct == "create")
QJsonUtils::modify(_autoCorrected, _currentPath, QJsonUtils::create(propertyValue, _ignoreRequired), property);
if (_correct == "")
setMessage("missing member");
}
else if (_correct == "create" && _ignoreRequired)
QJsonUtils::modify(_autoCorrected, _currentPath, QJsonUtils::create(propertyValue, _ignoreRequired), property);
_currentPath.removeLast();
}
}
@@ -208,7 +248,12 @@ void QJsonSchemaChecker::checkAdditionalProperties(const QJsonObject & value, co
if (schema.toBool() == false)
{
_error = true;
setMessage("no schema definition");
if (_correct == "remove")
QJsonUtils::modify(_autoCorrected, _currentPath);
if (_correct == "")
setMessage("no schema definition");
}
}
else
@@ -220,7 +265,7 @@ void QJsonSchemaChecker::checkAdditionalProperties(const QJsonObject & value, co
}
}
void QJsonSchemaChecker::checkMinimum(const QJsonValue & value, const QJsonValue & schema)
void QJsonSchemaChecker::checkMinimum(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue)
{
if (!value.isDouble())
{
@@ -233,11 +278,18 @@ void QJsonSchemaChecker::checkMinimum(const QJsonValue & value, const QJsonValue
if (value.toDouble() < schema.toDouble())
{
_error = true;
setMessage("value is too small (minimum=" + schema.toString() + ")");
if (_correct == "modify")
(defaultValue != QJsonValue::Null) ?
QJsonUtils::modify(_autoCorrected, _currentPath, defaultValue) :
QJsonUtils::modify(_autoCorrected, _currentPath, schema);
if (_correct == "")
setMessage("value is too small (minimum=" + QString::number(schema.toDouble()) + ")");
}
}
void QJsonSchemaChecker::checkMaximum(const QJsonValue & value, const QJsonValue & schema)
void QJsonSchemaChecker::checkMaximum(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue)
{
if (!value.isDouble())
{
@@ -250,11 +302,18 @@ void QJsonSchemaChecker::checkMaximum(const QJsonValue & value, const QJsonValue
if (value.toDouble() > schema.toDouble())
{
_error = true;
setMessage("value is too large (maximum=" + schema.toString() + ")");
if (_correct == "modify")
(defaultValue != QJsonValue::Null) ?
QJsonUtils::modify(_autoCorrected, _currentPath, defaultValue) :
QJsonUtils::modify(_autoCorrected, _currentPath, schema);
if (_correct == "")
setMessage("value is too large (maximum=" + QString::number(schema.toDouble()) + ")");
}
}
void QJsonSchemaChecker::checkMinLength(const QJsonValue & value, const QJsonValue & schema)
void QJsonSchemaChecker::checkMinLength(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue)
{
if (!value.isString())
{
@@ -267,11 +326,18 @@ void QJsonSchemaChecker::checkMinLength(const QJsonValue & value, const QJsonVal
if (value.toString().size() < schema.toInt())
{
_error = true;
setMessage("value is too short (minLength=" + schema.toString() + ")");
if (_correct == "modify")
(defaultValue != QJsonValue::Null) ?
QJsonUtils::modify(_autoCorrected, _currentPath, defaultValue) :
QJsonUtils::modify(_autoCorrected, _currentPath, schema);
if (_correct == "")
setMessage("value is too short (minLength=" + QString::number(schema.toInt()) + ")");
}
}
void QJsonSchemaChecker::checkMaxLength(const QJsonValue & value, const QJsonValue & schema)
void QJsonSchemaChecker::checkMaxLength(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue)
{
if (!value.isString())
{
@@ -284,7 +350,14 @@ void QJsonSchemaChecker::checkMaxLength(const QJsonValue & value, const QJsonVal
if (value.toString().size() > schema.toInt())
{
_error = true;
setMessage("value is too long (maxLength=" + schema.toString() + ")");
if (_correct == "modify")
(defaultValue != QJsonValue::Null) ?
QJsonUtils::modify(_autoCorrected, _currentPath, defaultValue) :
QJsonUtils::modify(_autoCorrected, _currentPath, schema);
if (_correct == "")
setMessage("value is too long (maxLength=" + QString::number(schema.toInt()) + ")");
}
}
@@ -299,6 +372,11 @@ void QJsonSchemaChecker::checkItems(const QJsonValue & value, const QJsonObject
}
QJsonArray jArray = value.toArray();
if (_correct == "remove")
if (jArray.isEmpty())
QJsonUtils::modify(_autoCorrected, _currentPath);
for(int i = 0; i < jArray.size(); ++i)
{
// validate each item
@@ -308,7 +386,7 @@ void QJsonSchemaChecker::checkItems(const QJsonValue & value, const QJsonObject
}
}
void QJsonSchemaChecker::checkMinItems(const QJsonValue & value, const QJsonValue & schema)
void QJsonSchemaChecker::checkMinItems(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue)
{
if (!value.isArray())
{
@@ -318,17 +396,22 @@ void QJsonSchemaChecker::checkMinItems(const QJsonValue & value, const QJsonValu
return;
}
int minimum = schema.toInt();
QJsonArray jArray = value.toArray();
if (static_cast<int>(jArray.size()) < minimum)
if (jArray.size() < schema.toInt())
{
_error = true;
setMessage("array is too large (minimum=" + QString::number(minimum) + ")");
if (_correct == "modify")
(defaultValue != QJsonValue::Null) ?
QJsonUtils::modify(_autoCorrected, _currentPath, defaultValue) :
QJsonUtils::modify(_autoCorrected, _currentPath, schema);
if (_correct == "")
setMessage("array is too small (minimum=" + QString::number(schema.toInt()) + ")");
}
}
void QJsonSchemaChecker::checkMaxItems(const QJsonValue & value, const QJsonValue & schema)
void QJsonSchemaChecker::checkMaxItems(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue)
{
if (!value.isArray())
{
@@ -338,13 +421,18 @@ void QJsonSchemaChecker::checkMaxItems(const QJsonValue & value, const QJsonValu
return;
}
int maximum = schema.toInt();
QJsonArray jArray = value.toArray();
if (static_cast<int>(jArray.size()) > maximum)
if (jArray.size() > schema.toInt())
{
_error = true;
setMessage("array is too large (maximum=" + QString::number(maximum) + ")");
if (_correct == "modify")
(defaultValue != QJsonValue::Null) ?
QJsonUtils::modify(_autoCorrected, _currentPath, defaultValue) :
QJsonUtils::modify(_autoCorrected, _currentPath, schema);
if (_correct == "")
setMessage("array is too large (maximum=" + QString::number(schema.toInt()) + ")");
}
}
@@ -362,6 +450,8 @@ void QJsonSchemaChecker::checkUniqueItems(const QJsonValue & value, const QJsonV
{
// make sure no two items are identical
bool removeDuplicates = false;
QJsonArray jArray = value.toArray();
for(int i = 0; i < jArray.size(); ++i)
{
@@ -371,14 +461,28 @@ void QJsonSchemaChecker::checkUniqueItems(const QJsonValue & value, const QJsonV
{
// found a value twice
_error = true;
setMessage("array must have unique values");
removeDuplicates = true;
if (_correct == "")
setMessage("array must have unique values");
}
}
}
if (removeDuplicates && _correct == "modify")
{
QJsonArray uniqueItemsArray;
for(int i = 0; i < jArray.size(); ++i)
if (!uniqueItemsArray.contains(jArray[i]))
uniqueItemsArray.append(jArray[i]);
QJsonUtils::modify(_autoCorrected, _currentPath, uniqueItemsArray);
}
}
}
void QJsonSchemaChecker::checkEnum(const QJsonValue & value, const QJsonValue & schema)
void QJsonSchemaChecker::checkEnum(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue)
{
if (schema.isArray())
{
@@ -395,7 +499,16 @@ void QJsonSchemaChecker::checkEnum(const QJsonValue & value, const QJsonValue &
// nothing found
_error = true;
QJsonDocument doc(schema.toArray());
QString strJson(doc.toJson(QJsonDocument::Compact));
setMessage("Unknown enum value (allowed values are: " + schema.toString() + strJson+ ")");
if (_correct == "modify")
(defaultValue != QJsonValue::Null) ?
QJsonUtils::modify(_autoCorrected, _currentPath, defaultValue) :
QJsonUtils::modify(_autoCorrected, _currentPath, schema.toArray().first());
if (_correct == "")
{
QJsonDocument doc(schema.toArray());
QString strJson(doc.toJson(QJsonDocument::Compact));
setMessage("Unknown enum value (allowed values are: " + strJson+ ")");
}
}

View File

@@ -105,14 +105,43 @@ void CgiHandler::cmd_cfg_set()
{
// make sure the resources are loaded (they may be left out after static linking)
Q_INIT_RESOURCE(resource);
QJsonObject schemaJson = QJsonFactory::readSchema(":/hyperion-schema-"+QString::number(_hyperion->getConfigVersionId()));
QString schemaFile = ":/hyperion-schema";
QJsonObject schemaJson;
try
{
schemaJson = QJsonFactory::readSchema(schemaFile);
}
catch(const std::runtime_error& error)
{
throw std::runtime_error(error.what());
}
QJsonSchemaChecker schemaChecker;
schemaChecker.setSchema(schemaJson);
if ( schemaChecker.validate(hyperionConfigJsonObj) )
QPair<bool, bool> validate = schemaChecker.validate(hyperionConfigJsonObj);
if (validate.first && validate.second)
{
QJsonFactory::writeJson(_hyperion->getConfigFileName(), hyperionConfigJsonObj);
}
else
else if (!validate.first && validate.second)
{
Warning(_log,"Errors have been found in the configuration file. Automatic correction is applied");
QStringList schemaErrors = schemaChecker.getMessages();
foreach (auto & schemaError, schemaErrors)
Info(_log, schemaError.toUtf8().constData());
hyperionConfigJsonObj = schemaChecker.getAutoCorrectedConfig(hyperionConfigJsonObj);
if (!QJsonFactory::writeJson(_hyperion->getConfigFileName(), hyperionConfigJsonObj))
throw std::runtime_error("ERROR: can not save configuration file, aborting ");
}
else //Error in Schema
{
QString errorMsg = "ERROR: Json validation failed: \n";
QStringList schemaErrors = schemaChecker.getMessages();
@@ -121,6 +150,7 @@ void CgiHandler::cmd_cfg_set()
Error(_log, "config write validation: %s", QSTRING_CSTR(schemaError));
errorMsg += schemaError + "\n";
}
throw std::runtime_error(errorMsg.toStdString());
}
}