Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
json-schema-validator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IOPSYS
json-schema-validator
Commits
015d998d
Commit
015d998d
authored
5 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
parse definitions as blob
parent
b3eae44a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/json-validator.cpp
+30
-12
30 additions, 12 deletions
src/json-validator.cpp
src/schema.cpp
+8
-5
8 additions, 5 deletions
src/schema.cpp
src/schema.h
+2
-2
2 additions, 2 deletions
src/schema.h
with
40 additions
and
19 deletions
src/json-validator.cpp
+
30
−
12
View file @
015d998d
...
@@ -84,8 +84,7 @@ bool schema_validator_validate_blob(struct blob_attr *msg, const char *object, c
...
@@ -84,8 +84,7 @@ bool schema_validator_validate_blob(struct blob_attr *msg, const char *object, c
struct
schema_method
*
s_method
;
struct
schema_method
*
s_method
;
json
schema
,
obj
;
json
schema
,
obj
;
int
rv
=
1
;
int
rv
=
1
;
char
*
str
,
*
s
;
char
*
arg_str
,
*
schema_str
;
if
(
!
initialized
)
if
(
!
initialized
)
return
true
;
return
true
;
...
@@ -101,28 +100,37 @@ bool schema_validator_validate_blob(struct blob_attr *msg, const char *object, c
...
@@ -101,28 +100,37 @@ bool schema_validator_validate_blob(struct blob_attr *msg, const char *object, c
goto
out
;
goto
out
;
if
(
type
==
SCHEMA_INPUT_CALL
)
if
(
type
==
SCHEMA_INPUT_CALL
)
s
=
blobmsg_format_json
(
s_method
->
b_input
,
true
);
s
chema_str
=
blobmsg_format_json
(
s_method
->
b_input
,
true
);
else
if
(
type
==
SCHEMA_OUTPUT_CALL
)
else
if
(
type
==
SCHEMA_OUTPUT_CALL
)
s
=
blobmsg_format_json
(
s_method
->
b_output
,
true
);
s
chema_str
=
blobmsg_format_json
(
s_method
->
b_output
,
true
);
else
else
goto
out
;
goto
out
;
if
(
!
s
)
if
(
!
s
chema_str
)
goto
out
;
goto
out
;
schema
=
json
::
parse
(
s
);
schema
=
json
::
parse
(
s
chema_str
);
str
=
blobmsg_format_json
(
msg
,
true
);
arg_
str
=
blobmsg_format_json
(
msg
,
true
);
obj
=
json
::
parse
(
str
);
obj
=
json
::
parse
(
arg_
str
);
if
(
s_object
->
definitions
)
{
if
(
s_object
->
definitions
)
{
json
definitions
=
json
::
parse
(
s_object
->
definitions
);
char
*
def_str
;
def_str
=
blobmsg_format_json
(
s_object
->
definitions
,
true
);
if
(
!
def_str
)
goto
out_definitions
;
json
definitions
=
json
::
parse
(
def_str
);
schema
+=
json
::
object_t
::
value_type
(
"definitions"
,
definitions
);
schema
+=
json
::
object_t
::
value_type
(
"definitions"
,
definitions
);
free
(
def_str
);
}
}
rv
=
json_object_validate_schema
(
obj
,
schema
);
rv
=
json_object_validate_schema
(
obj
,
schema
);
free
(
str
);
out_definitions
:
free
(
s
);
free
(
arg_str
);
free
(
schema_str
);
out
:
out
:
return
rv
;
return
rv
;
}
}
...
@@ -158,14 +166,24 @@ bool schema_validator_validate_jobj(struct json_object *j_object, const char *ob
...
@@ -158,14 +166,24 @@ bool schema_validator_validate_jobj(struct json_object *j_object, const char *ob
sch
=
json
::
parse
(
s
);
sch
=
json
::
parse
(
s
);
if
(
s_object
->
definitions
)
{
if
(
s_object
->
definitions
)
{
json
definitions
=
json
::
parse
(
s_object
->
definitions
);
char
*
def_str
;
def_str
=
blobmsg_format_json
(
s_object
->
definitions
,
true
);
if
(
!
def_str
)
goto
out_definitions
;
json
definitions
=
json
::
parse
(
def_str
);
sch
+=
json
::
object_t
::
value_type
(
"definitions"
,
definitions
);
sch
+=
json
::
object_t
::
value_type
(
"definitions"
,
definitions
);
free
(
def_str
);
}
}
obj
=
json
::
parse
(
json_object_get_string
(
j_object
));
obj
=
json
::
parse
(
json_object_get_string
(
j_object
));
rv
=
json_object_validate_schema
(
obj
,
sch
);
rv
=
json_object_validate_schema
(
obj
,
sch
);
out_definitions
:
free
(
s
);
out
:
out
:
return
rv
;
return
rv
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/schema.cpp
+
8
−
5
View file @
015d998d
...
@@ -124,7 +124,6 @@ schema_setup_file(const char *path)
...
@@ -124,7 +124,6 @@ schema_setup_file(const char *path)
struct
blob_attr
*
root
,
*
object
;
struct
blob_attr
*
root
,
*
object
;
int
rem
,
rem2
;
int
rem
,
rem2
;
struct
schema_object
*
schema_object
;
struct
schema_object
*
schema_object
;
char
*
definitions
=
NULL
;
memset
(
&
acl
,
0
,
sizeof
(
acl
));
memset
(
&
acl
,
0
,
sizeof
(
acl
));
blob_buf_init
(
&
acl
,
0
);
blob_buf_init
(
&
acl
,
0
);
...
@@ -154,8 +153,12 @@ schema_setup_file(const char *path)
...
@@ -154,8 +153,12 @@ schema_setup_file(const char *path)
goto
out_flush
;
goto
out_flush
;
}
}
if
(
!
strncmp
(
blobmsg_name
(
root
),
"definitions"
,
12
))
if
(
!
strncmp
(
blobmsg_name
(
root
),
"definitions"
,
12
))
{
definitions
=
blobmsg_format_json
(
root
,
true
);
int
len
=
blob_raw_len
(
root
);
schema_object
->
definitions
=
(
struct
blob_attr
*
)
calloc
(
1
,
sizeof
(
struct
blob_attr
)
+
len
);
memcpy
(
schema_object
->
definitions
,
root
,
len
);
}
if
(
strncmp
(
blobmsg_name
(
root
),
"properties"
,
11
))
if
(
strncmp
(
blobmsg_name
(
root
),
"properties"
,
11
))
continue
;
continue
;
...
@@ -183,7 +186,6 @@ schema_setup_file(const char *path)
...
@@ -183,7 +186,6 @@ schema_setup_file(const char *path)
if
(
!
schema_object
->
avl
.
key
)
if
(
!
schema_object
->
avl
.
key
)
goto
out_flush
;
goto
out_flush
;
schema_object
->
definitions
=
definitions
;
avl_insert
(
&
s_ctx
.
schema_objects
,
&
schema_object
->
avl
);
avl_insert
(
&
s_ctx
.
schema_objects
,
&
schema_object
->
avl
);
out
:
out
:
...
@@ -191,6 +193,7 @@ out:
...
@@ -191,6 +193,7 @@ out:
return
;
return
;
out_flush
:
out_flush
:
schema_flush_object
(
schema_object
);
schema_flush_object
(
schema_object
);
blob_buf_free
(
&
acl
);
}
}
struct
schema_method
*
schema_get_method_schema
(
const
char
*
object
,
const
char
*
method
)
struct
schema_method
*
schema_get_method_schema
(
const
char
*
object
,
const
char
*
method
)
...
@@ -212,7 +215,7 @@ struct schema_method *schema_get_method_schema(const char *object, const char *m
...
@@ -212,7 +215,7 @@ struct schema_method *schema_get_method_schema(const char *object, const char *m
return
NULL
;
return
NULL
;
}
}
const
cha
r
*
schema_get_definitions_schema
(
const
char
*
object
)
struct
blob_att
r
*
schema_get_definitions_schema
(
const
char
*
object
)
{
{
struct
schema_object
*
s_object
;
struct
schema_object
*
s_object
;
...
...
This diff is collapsed.
Click to expand it.
src/schema.h
+
2
−
2
View file @
015d998d
...
@@ -25,7 +25,7 @@ struct schema_method {
...
@@ -25,7 +25,7 @@ struct schema_method {
struct
schema_object
{
struct
schema_object
{
char
object_name
[
OBJECT_NAME_MAX_LEN
];
char
object_name
[
OBJECT_NAME_MAX_LEN
];
cha
r
*
definitions
;
struct
blob_att
r
*
definitions
;
bool
regex
;
bool
regex
;
regex_t
regex_exp
;
regex_t
regex_exp
;
...
@@ -35,7 +35,7 @@ struct schema_object {
...
@@ -35,7 +35,7 @@ struct schema_object {
};
};
struct
schema_method
*
schema_get_method_schema
(
const
char
*
object
,
const
char
*
method
);
struct
schema_method
*
schema_get_method_schema
(
const
char
*
object
,
const
char
*
method
);
const
cha
r
*
schema_get_definitions_schema
(
const
char
*
object
);
struct
blob_att
r
*
schema_get_definitions_schema
(
const
char
*
object
);
struct
schema_object
*
schema_get_object_schema
(
const
char
*
object
);
struct
schema_object
*
schema_get_object_schema
(
const
char
*
object
);
void
schema_setup_json
();
void
schema_setup_json
();
void
schema_flush_objects
();
void
schema_flush_objects
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment