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
32eabbd1
Commit
32eabbd1
authored
5 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
compile validator wrapper as shared library
parent
79013e1f
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#174
failed
5 years ago
Stage: build
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CMakeLists.txt
+74
-0
74 additions, 0 deletions
CMakeLists.txt
json-validator.h
+4
-0
4 additions, 0 deletions
json-validator.h
validator.c
+57
-0
57 additions, 0 deletions
validator.c
with
135 additions
and
0 deletions
CMakeLists.txt
0 → 100644
+
74
−
0
View file @
32eabbd1
CMAKE_MINIMUM_REQUIRED
(
VERSION 3.0
)
PROJECT
(
json-validator
)
#set version
SET
(
MAJOR_VERSION 1
)
SET
(
MINOR_VERSION 0
)
SET
(
PATCH_VERSION 0
)
#EXEC_PROGRAM("git" ${CMAKE_CURRENT_SOURCE_DIR} ARGS "log HEAD --format=format:%H -1" OUTPUT_VARIABLE GIT_SHA1)
#ADD_DEFINITIONS(-D_PROJECT_NAME="${PROJECT_NAME}")
#ADD_DEFINITIONS(-D_PROJECT_VERSION="${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}")
#ADD_DEFINITIONS(-D_GIT_SHA1="${GIT_SHA1}")
#set compile flags
SET
(
DEFAULT_FLAGS
"--std=gnu99"
)
SET
(
RELEASE_FLAGS
"-Wno-long-long -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Werror-implicit-function-declaration -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute -fno-common -Wsign-compare -Wunused-result"
)
include
(
GNUInstallDirs
)
SET
(
CMAKE_C_FLAGS_DEBUG
"
${
CMAKE_C_FLAGS_DEBUG
}
${
DEFAULT_FLAGS
}
-Wall"
)
SET
(
CMAKE_C_FLAGS_RELEASE
"
${
CMAKE_C_FLAGS_RELEASE
}
-Os
${
DEFAULT_FLAGS
}
${
RELEASE_FLAGS
}
"
)
SET
(
CMAKE_C_FLAGS_RELWITHDEBINFO
"
${
CMAKE_C_FLAGS_RELWITHDEBINFO
}
${
DEFAULT_FLAGS
}
${
RELEASE_FLAGS
}
"
)
SET
(
CMAKE_C_FLAGS_MINSIZEREL
"
${
CMAKE_C_FLAGS_MINSIZEREL
}
${
DEFAULT_FLAGS
}
${
RELEASE_FLAGS
}
"
)
#INCLUDE(LogOptions.cmake)
#create executable
FILE
(
GLOB SOURCES
"*.c"
"*.h"
)
set
(
PUBLIC_HEADERS
${
PROJECT_SOURCE_DIR
}
/src/json-validator.h
)
#ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCES})
ADD_LIBRARY
(
${
PROJECT_NAME
}
SHARED
${
SOURCES
}
)
#link libraries
SET
(
CMAKE_MODULE_PATH
${
CMAKE_MODULE_PATH
}
"
${
CMAKE_SOURCE_DIR
}
/cmake/modules"
)
find_library
(
JSON_LIBRARIES NAMES json-c
)
TARGET_LINK_LIBRARIES
(
${
PROJECT_NAME
}
${
JSON_LIBRARIES
}
)
#testing
#IF(CMAKE_BUILD_TYPE STREQUAL Debug)
# OPTION(ENABLE_BUILD_TESTS "Build tests" ON)
# OPTION(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON)
#ELSE()
# OPTION(ENABLE_BUILD_TESTS "Build tests" OFF)
# OPTION(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF)
#ENDIF()
#
#IF(ENABLE_BUILD_TESTS)
# FIND_PACKAGE(CMocka)
# if(CMOCKA_FOUND)
# INCLUDE(CodeCoverage)
# APPEND_COVERAGE_COMPILER_FLAGS()
# #ADD_LIBRARY(${PROJECT_NAME}-api SHARED ${SOURCES})
# MESSAGE("-- Building tests")
# ENABLE_TESTING()
# ADD_SUBDIRECTORY(test)
# ELSE(CMOCKA_FOUND)
# MESSAGE("-- CMocka not found")
# ENDIF(CMOCKA_FOUND)
#ENDIF(ENABLE_BUILD_TESTS)
install
(
TARGETS
${
PROJECT_NAME
}
EXPORT
${
PROJECT_NAME
}
RUNTIME DESTINATION
${
CMAKE_INSTALL_BINDIR
}
LIBRARY DESTINATION
${
CMAKE_INSTALL_LIBDIR
}
ARCHIVE DESTINATION
${
CMAKE_INSTALL_LIBDIR
}
INCLUDES DESTINATION
${
CMAKE_INSTALL_INCLUDEDIR
}
)
#install
#INSTALL(TARGETS imonitor RUNTIME DESTINATION bin)
install
(
FILES
${
PUBLIC_HEADERS
}
DESTINATION
${
CMAKE_INSTALL_PREFIX
}
/include/
)
This diff is collapsed.
Click to expand it.
json-validator.h
0 → 100644
+
4
−
0
View file @
32eabbd1
#ifndef JSON_VALIDATOR_H
bool
json_object_validate_schema
(
struct
json_object
*
j_obj
,
struct
json_object
*
j_schema
);
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
validator.c
0 → 100644
+
57
−
0
View file @
32eabbd1
#include
<stdio.h>
#include
<wjelement.h>
#include
<unistd.h>
#include
<json-c/json.h>
#include
<stdbool.h>
#include
<string.h>
#include
"json-validator.h"
/*
callback: plop validation errors to stderr
*/
static
void
schema_error
(
void
*
client
,
const
char
*
format
,
...)
{
(
void
)
client
;
va_list
ap
;
va_start
(
ap
,
format
);
vfprintf
(
stderr
,
format
,
ap
);
va_end
(
ap
);
fprintf
(
stderr
,
"
\n
"
);
}
/*
callback: cleanup/free open schema
*/
static
void
schema_free
(
WJElement
schema
,
void
*
client
)
{
(
void
)
client
;
WJECloseDocument
(
schema
);
return
;
}
bool
json_object_validate_schema
(
struct
json_object
*
j_obj
,
struct
json_object
*
j_schema
)
{
WJElement
json
;
WJElement
schema
;
bool
rv
=
false
;
if
(
!
j_obj
||
!
j_schema
)
return
rv
;
json
=
WJEParse
(
json_object_get_string
(
j_obj
));
if
(
!
json
)
return
rv
;
schema
=
WJEParse
(
json_object_get_string
(
j_schema
));
if
(
!
schema
)
goto
out_schema
;
rv
=
WJESchemaValidate
(
schema
,
json
,
schema_error
,
NULL
,
schema_free
,
NULL
);
WJECloseDocument
(
schema
);
out_schema:
WJECloseDocument
(
json
);
return
rv
;
}
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