Skip to content

Commit b540616

Browse files
committed
lib/addoninfo.cpp: Add JSON schema validation.
For JSON schema validation in cpp code, valijson (https://github.com/tristanpenman/valijson) is added. It supports picojson and is actively maintained. It is used in one-header-include style, because it seems the simplest solution, for now at least. The header is added, alongside the LICENSE file, in externals/valijson/. Various warnings that are emitted compiling the default code generated by valijson are fixed; these fixes are pushed upstream. As JSON is now validated against a schema, various ad-hoc checks could be safely removed. A simple way to test addon JSON schema validation, is to invoke cppcheck using: cppcheck --addon='{"script":1}' test.c A minor bugfix is that the file specified by "executable" was searched using getFullPath() with fileName as the second argument; it looks like this should have been exename. The fileName argument of parseAddonInfo() is only used for log messages, and is now replaced by the string "inline JSON" instead of the actual JSON string that was parsed. The command as given above will therefore output: Loading inline JSON failed. JSON schema validation failed: <root> [script] Value type not permitted by 'type' constraint., <root> Failed to validate against schema associated with property name 'script'. The addon JSON unit tests are also updated and now operate on JSON specified on the command line.
1 parent 8ebd9bb commit b540616

18 files changed

Lines changed: 10908 additions & 64 deletions

File tree

‎.github/workflows/CI-unixish.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ jobs:
242242
243243
- name: Check syntax with NONNEG
244244
run: |
245-
ls lib/*.cpp | xargs -n 1 -P $(nproc) g++ -fsyntax-only -std=c++0x -Ilib -Iexternals -Iexternals/picojson -Iexternals/simplecpp -Iexternals/tinyxml2 -DNONNEG
245+
ls lib/*.cpp | xargs -n 1 -P $(nproc) g++ -fsyntax-only -std=c++0x -Ilib -Iexternals -Iexternals/picojson -Iexternals/valijson -Iexternals/simplecpp -Iexternals/tinyxml2 -DNONNEG
246246
247247
build_qmake:
248248

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ ifndef PREFIX
168168
endif
169169

170170
ifndef INCLUDE_FOR_LIB
171-
INCLUDE_FOR_LIB=-Ilib -isystem externals -isystem externals/picojson -isystem externals/simplecpp -isystem externals/tinyxml2
171+
INCLUDE_FOR_LIB=-Ilib -isystem externals -isystem externals/picojson -isystem externals/valijson -isystem externals/simplecpp -isystem externals/tinyxml2
172172
endif
173173

174174
ifndef INCLUDE_FOR_CLI

‎createrelease‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# self check, fix critical issues:
1313
# make clean && make CXXFLAGS=-O2 MATCHCOMPILER=yes -j4
14-
# ./cppcheck -D__CPPCHECK__ -D__GNUC__ -DCHECK_INTERNAL -DHAVE_RULES --std=c++11 --library=cppcheck-lib --library=qt --enable=style --inconclusive --inline-suppr --suppress=bitwiseOnBoolean --suppress=shadowFunction --suppress=useStlAlgorithm --suppress=*:externals/picojson.h --suppress=functionConst --suppress=functionStatic --xml cli gui/*.cpp lib 2> selfcheck.xml
14+
# ./cppcheck -D__CPPCHECK__ -D__GNUC__ -DCHECK_INTERNAL -DHAVE_RULES --std=c++11 --library=cppcheck-lib --library=qt --enable=style --inconclusive --inline-suppr --suppress=bitwiseOnBoolean --suppress=shadowFunction --suppress=useStlAlgorithm --suppress=*:externals/picojson.h --suppress=*:externals/valijson/valijson_picojson_bundled.hpp --suppress=functionConst --suppress=functionStatic --xml cli gui/*.cpp lib 2> selfcheck.xml
1515
#
1616
# Generate lib/checkers.cpp (TODO the premium checkers should not be statically coded)
1717
# cd ~/cppchecksolutions/cppcheck && python3 tools/get_checkers.py > lib/checkers.cpp

‎externals/externals.pri‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
INCLUDEPATH += $${PWD} \
22
$${PWD}/picojson \
3+
$${PWD}/valijson \
34
$${PWD}/simplecpp \
45
$${PWD}/tinyxml2
56

67
HEADERS += $${PWD}/picojson/picojson.h \
8+
$${PWD}/valijson/valijson_picojson_bundled.hpp \
79
$${PWD}/simplecpp/simplecpp.h \
810
$${PWD}/tinyxml2/tinyxml2.h
911

‎externals/valijson/LICENSE‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (c) 2016, Tristan Penman
2+
Copyright (c) 2016, Akamai Technologies, Inc.
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)