From 68df397aa2e8c8a6cba4535ca78afa882926c94b Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 4 Dec 2019 13:03:55 -0800 Subject: [PATCH] Remove vtables from JSON library --- BUILD | 4 - BUILD.gn | 8 - CMakeLists.txt | 91 ----- Makefile | 113 ------ build.yaml | 35 -- config.m4 | 1 - config.w32 | 1 - gRPC-C++.podspec | 9 - gRPC-Core.podspec | 7 - grpc.gemspec | 4 - grpc.gyp | 6 - package.xml | 4 - src/core/lib/json/json.h | 12 +- src/core/lib/json/json_common.h | 34 -- src/core/lib/json/json_reader.cc | 234 +++++++++-- src/core/lib/json/json_reader.h | 146 ------- src/core/lib/json/json_string.cc | 367 ------------------ src/core/lib/json/json_writer.cc | 135 +++++-- src/core/lib/json/json_writer.h | 84 ---- src/python/grpcio/grpc_core_dependencies.py | 1 - test/core/json/BUILD | 42 -- test/core/json/json_rewrite.cc | 241 ------------ test/core/json/json_rewrite_test.cc | 294 -------------- test/core/json/json_stream_error_test.cc | 58 --- test/core/json/rewrite_test_input.json | 203 ---------- .../json/rewrite_test_output_condensed.json | 1 - .../json/rewrite_test_output_indented.json | 272 ------------- tools/doxygen/Doxyfile.c++.internal | 4 - tools/doxygen/Doxyfile.core.internal | 4 - tools/run_tests/generated/tests.json | 48 --- 30 files changed, 328 insertions(+), 2135 deletions(-) delete mode 100644 src/core/lib/json/json_common.h delete mode 100644 src/core/lib/json/json_reader.h delete mode 100644 src/core/lib/json/json_string.cc delete mode 100644 src/core/lib/json/json_writer.h delete mode 100644 test/core/json/json_rewrite.cc delete mode 100644 test/core/json/json_rewrite_test.cc delete mode 100644 test/core/json/json_stream_error_test.cc delete mode 100644 test/core/json/rewrite_test_input.json delete mode 100644 test/core/json/rewrite_test_output_condensed.json delete mode 100644 test/core/json/rewrite_test_output_indented.json diff --git a/BUILD b/BUILD index b56c427500e..aae8ed4cab1 100644 --- a/BUILD +++ b/BUILD @@ -775,7 +775,6 @@ grpc_cc_library( "src/core/lib/iomgr/wakeup_fd_posix.cc", "src/core/lib/json/json.cc", "src/core/lib/json/json_reader.cc", - "src/core/lib/json/json_string.cc", "src/core/lib/json/json_writer.cc", "src/core/lib/slice/b64.cc", "src/core/lib/slice/percent_encoding.cc", @@ -918,9 +917,6 @@ grpc_cc_library( "src/core/lib/iomgr/wakeup_fd_pipe.h", "src/core/lib/iomgr/wakeup_fd_posix.h", "src/core/lib/json/json.h", - "src/core/lib/json/json_common.h", - "src/core/lib/json/json_reader.h", - "src/core/lib/json/json_writer.h", "src/core/lib/slice/b64.h", "src/core/lib/slice/percent_encoding.h", "src/core/lib/slice/slice_hash_table.h", diff --git a/BUILD.gn b/BUILD.gn index 0599ae15048..2d84429ad1f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -690,12 +690,8 @@ config("grpc_config") { "src/core/lib/iomgr/wakeup_fd_posix.h", "src/core/lib/json/json.cc", "src/core/lib/json/json.h", - "src/core/lib/json/json_common.h", "src/core/lib/json/json_reader.cc", - "src/core/lib/json/json_reader.h", - "src/core/lib/json/json_string.cc", "src/core/lib/json/json_writer.cc", - "src/core/lib/json/json_writer.h", "src/core/lib/security/context/security_context.cc", "src/core/lib/security/context/security_context.h", "src/core/lib/security/credentials/alts/alts_credentials.cc", @@ -1528,12 +1524,8 @@ config("grpc_config") { "src/core/lib/iomgr/wakeup_fd_posix.h", "src/core/lib/json/json.cc", "src/core/lib/json/json.h", - "src/core/lib/json/json_common.h", "src/core/lib/json/json_reader.cc", - "src/core/lib/json/json_reader.h", - "src/core/lib/json/json_string.cc", "src/core/lib/json/json_writer.cc", - "src/core/lib/json/json_writer.h", "src/core/lib/profiling/timers.h", "src/core/lib/slice/b64.cc", "src/core/lib/slice/b64.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index bb67af6010c..32add78b99b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -478,9 +478,6 @@ if(gRPC_BUILD_TESTS) add_dependencies(buildtests_c init_test) add_dependencies(buildtests_c inproc_callback_test) add_dependencies(buildtests_c invalid_call_argument_test) - add_dependencies(buildtests_c json_rewrite) - add_dependencies(buildtests_c json_rewrite_test) - add_dependencies(buildtests_c json_stream_error_test) add_dependencies(buildtests_c json_test) add_dependencies(buildtests_c lame_client_test) add_dependencies(buildtests_c load_file_test) @@ -1222,7 +1219,6 @@ add_library(grpc src/core/lib/iomgr/wakeup_fd_posix.cc src/core/lib/json/json.cc src/core/lib/json/json_reader.cc - src/core/lib/json/json_string.cc src/core/lib/json/json_writer.cc src/core/lib/slice/b64.cc src/core/lib/slice/percent_encoding.cc @@ -1695,7 +1691,6 @@ add_library(grpc_cronet src/core/lib/iomgr/wakeup_fd_posix.cc src/core/lib/json/json.cc src/core/lib/json/json_reader.cc - src/core/lib/json/json_string.cc src/core/lib/json/json_writer.cc src/core/lib/slice/b64.cc src/core/lib/slice/percent_encoding.cc @@ -2124,7 +2119,6 @@ add_library(grpc_test_util src/core/lib/iomgr/wakeup_fd_posix.cc src/core/lib/json/json.cc src/core/lib/json/json_reader.cc - src/core/lib/json/json_string.cc src/core/lib/json/json_writer.cc src/core/lib/slice/b64.cc src/core/lib/slice/percent_encoding.cc @@ -2467,7 +2461,6 @@ add_library(grpc_test_util_unsecure src/core/lib/iomgr/wakeup_fd_posix.cc src/core/lib/json/json.cc src/core/lib/json/json_reader.cc - src/core/lib/json/json_string.cc src/core/lib/json/json_writer.cc src/core/lib/slice/b64.cc src/core/lib/slice/percent_encoding.cc @@ -2786,7 +2779,6 @@ add_library(grpc_unsecure src/core/lib/iomgr/wakeup_fd_posix.cc src/core/lib/json/json.cc src/core/lib/json/json_reader.cc - src/core/lib/json/json_string.cc src/core/lib/json/json_writer.cc src/core/lib/slice/b64.cc src/core/lib/slice/percent_encoding.cc @@ -3442,7 +3434,6 @@ add_library(grpc++ src/core/lib/iomgr/wakeup_fd_posix.cc src/core/lib/json/json.cc src/core/lib/json/json_reader.cc - src/core/lib/json/json_string.cc src/core/lib/json/json_writer.cc src/core/lib/slice/b64.cc src/core/lib/slice/percent_encoding.cc @@ -4707,7 +4698,6 @@ add_library(grpc++_unsecure src/core/lib/iomgr/wakeup_fd_posix.cc src/core/lib/json/json.cc src/core/lib/json/json_reader.cc - src/core/lib/json/json_string.cc src/core/lib/json/json_writer.cc src/core/lib/slice/b64.cc src/core/lib/slice/percent_encoding.cc @@ -8462,87 +8452,6 @@ target_link_libraries(invalid_call_argument_test ) -endif() -if(gRPC_BUILD_TESTS) - -add_executable(json_rewrite - test/core/json/json_rewrite.cc -) - -target_include_directories(json_rewrite - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} - ${_gRPC_SSL_INCLUDE_DIR} - ${_gRPC_UPB_GENERATED_DIR} - ${_gRPC_UPB_GRPC_GENERATED_DIR} - ${_gRPC_UPB_INCLUDE_DIR} - ${_gRPC_ZLIB_INCLUDE_DIR} -) - -target_link_libraries(json_rewrite - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util - grpc - gpr -) - - -endif() -if(gRPC_BUILD_TESTS) - -add_executable(json_rewrite_test - test/core/json/json_rewrite_test.cc -) - -target_include_directories(json_rewrite_test - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} - ${_gRPC_SSL_INCLUDE_DIR} - ${_gRPC_UPB_GENERATED_DIR} - ${_gRPC_UPB_GRPC_GENERATED_DIR} - ${_gRPC_UPB_INCLUDE_DIR} - ${_gRPC_ZLIB_INCLUDE_DIR} -) - -target_link_libraries(json_rewrite_test - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util - grpc - gpr -) - - -endif() -if(gRPC_BUILD_TESTS) - -add_executable(json_stream_error_test - test/core/json/json_stream_error_test.cc -) - -target_include_directories(json_stream_error_test - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} - ${_gRPC_SSL_INCLUDE_DIR} - ${_gRPC_UPB_GENERATED_DIR} - ${_gRPC_UPB_GRPC_GENERATED_DIR} - ${_gRPC_UPB_INCLUDE_DIR} - ${_gRPC_ZLIB_INCLUDE_DIR} -) - -target_link_libraries(json_stream_error_test - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util - grpc - gpr -) - - endif() if(gRPC_BUILD_TESTS) diff --git a/Makefile b/Makefile index 25b89a680fb..5f591c4361f 100644 --- a/Makefile +++ b/Makefile @@ -1094,9 +1094,6 @@ init_test: $(BINDIR)/$(CONFIG)/init_test inproc_callback_test: $(BINDIR)/$(CONFIG)/inproc_callback_test invalid_call_argument_test: $(BINDIR)/$(CONFIG)/invalid_call_argument_test json_fuzzer_test: $(BINDIR)/$(CONFIG)/json_fuzzer_test -json_rewrite: $(BINDIR)/$(CONFIG)/json_rewrite -json_rewrite_test: $(BINDIR)/$(CONFIG)/json_rewrite_test -json_stream_error_test: $(BINDIR)/$(CONFIG)/json_stream_error_test json_test: $(BINDIR)/$(CONFIG)/json_test lame_client_test: $(BINDIR)/$(CONFIG)/lame_client_test load_file_test: $(BINDIR)/$(CONFIG)/load_file_test @@ -1526,9 +1523,6 @@ buildtests_c: privatelibs_c \ $(BINDIR)/$(CONFIG)/init_test \ $(BINDIR)/$(CONFIG)/inproc_callback_test \ $(BINDIR)/$(CONFIG)/invalid_call_argument_test \ - $(BINDIR)/$(CONFIG)/json_rewrite \ - $(BINDIR)/$(CONFIG)/json_rewrite_test \ - $(BINDIR)/$(CONFIG)/json_stream_error_test \ $(BINDIR)/$(CONFIG)/json_test \ $(BINDIR)/$(CONFIG)/lame_client_test \ $(BINDIR)/$(CONFIG)/load_file_test \ @@ -2135,10 +2129,6 @@ test_c: buildtests_c $(Q) $(BINDIR)/$(CONFIG)/inproc_callback_test || ( echo test inproc_callback_test failed ; exit 1 ) $(E) "[RUN] Testing invalid_call_argument_test" $(Q) $(BINDIR)/$(CONFIG)/invalid_call_argument_test || ( echo test invalid_call_argument_test failed ; exit 1 ) - $(E) "[RUN] Testing json_rewrite_test" - $(Q) $(BINDIR)/$(CONFIG)/json_rewrite_test || ( echo test json_rewrite_test failed ; exit 1 ) - $(E) "[RUN] Testing json_stream_error_test" - $(Q) $(BINDIR)/$(CONFIG)/json_stream_error_test || ( echo test json_stream_error_test failed ; exit 1 ) $(E) "[RUN] Testing json_test" $(Q) $(BINDIR)/$(CONFIG)/json_test || ( echo test json_test failed ; exit 1 ) $(E) "[RUN] Testing lame_client_test" @@ -3711,7 +3701,6 @@ LIBGRPC_SRC = \ src/core/lib/iomgr/wakeup_fd_posix.cc \ src/core/lib/json/json.cc \ src/core/lib/json/json_reader.cc \ - src/core/lib/json/json_string.cc \ src/core/lib/json/json_writer.cc \ src/core/lib/slice/b64.cc \ src/core/lib/slice/percent_encoding.cc \ @@ -4176,7 +4165,6 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/iomgr/wakeup_fd_posix.cc \ src/core/lib/json/json.cc \ src/core/lib/json/json_reader.cc \ - src/core/lib/json/json_string.cc \ src/core/lib/json/json_writer.cc \ src/core/lib/slice/b64.cc \ src/core/lib/slice/percent_encoding.cc \ @@ -4596,7 +4584,6 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/iomgr/wakeup_fd_posix.cc \ src/core/lib/json/json.cc \ src/core/lib/json/json_reader.cc \ - src/core/lib/json/json_string.cc \ src/core/lib/json/json_writer.cc \ src/core/lib/slice/b64.cc \ src/core/lib/slice/percent_encoding.cc \ @@ -4925,7 +4912,6 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/iomgr/wakeup_fd_posix.cc \ src/core/lib/json/json.cc \ src/core/lib/json/json_reader.cc \ - src/core/lib/json/json_string.cc \ src/core/lib/json/json_writer.cc \ src/core/lib/slice/b64.cc \ src/core/lib/slice/percent_encoding.cc \ @@ -5217,7 +5203,6 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/iomgr/wakeup_fd_posix.cc \ src/core/lib/json/json.cc \ src/core/lib/json/json_reader.cc \ - src/core/lib/json/json_string.cc \ src/core/lib/json/json_writer.cc \ src/core/lib/slice/b64.cc \ src/core/lib/slice/percent_encoding.cc \ @@ -5838,7 +5823,6 @@ LIBGRPC++_SRC = \ src/core/lib/iomgr/wakeup_fd_posix.cc \ src/core/lib/json/json.cc \ src/core/lib/json/json_reader.cc \ - src/core/lib/json/json_string.cc \ src/core/lib/json/json_writer.cc \ src/core/lib/slice/b64.cc \ src/core/lib/slice/percent_encoding.cc \ @@ -7069,7 +7053,6 @@ LIBGRPC++_UNSECURE_SRC = \ src/core/lib/iomgr/wakeup_fd_posix.cc \ src/core/lib/json/json.cc \ src/core/lib/json/json_reader.cc \ - src/core/lib/json/json_string.cc \ src/core/lib/json/json_writer.cc \ src/core/lib/slice/b64.cc \ src/core/lib/slice/percent_encoding.cc \ @@ -11857,102 +11840,6 @@ endif endif -JSON_REWRITE_SRC = \ - test/core/json/json_rewrite.cc \ - -JSON_REWRITE_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(JSON_REWRITE_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/json_rewrite: openssl_dep_error - -else - - - -$(BINDIR)/$(CONFIG)/json_rewrite: $(JSON_REWRITE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(JSON_REWRITE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/json_rewrite - -endif - -$(OBJDIR)/$(CONFIG)/test/core/json/json_rewrite.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_json_rewrite: $(JSON_REWRITE_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(JSON_REWRITE_OBJS:.o=.dep) -endif -endif - - -JSON_REWRITE_TEST_SRC = \ - test/core/json/json_rewrite_test.cc \ - -JSON_REWRITE_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(JSON_REWRITE_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/json_rewrite_test: openssl_dep_error - -else - - - -$(BINDIR)/$(CONFIG)/json_rewrite_test: $(JSON_REWRITE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(JSON_REWRITE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/json_rewrite_test - -endif - -$(OBJDIR)/$(CONFIG)/test/core/json/json_rewrite_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_json_rewrite_test: $(JSON_REWRITE_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(JSON_REWRITE_TEST_OBJS:.o=.dep) -endif -endif - - -JSON_STREAM_ERROR_TEST_SRC = \ - test/core/json/json_stream_error_test.cc \ - -JSON_STREAM_ERROR_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(JSON_STREAM_ERROR_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/json_stream_error_test: openssl_dep_error - -else - - - -$(BINDIR)/$(CONFIG)/json_stream_error_test: $(JSON_STREAM_ERROR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(JSON_STREAM_ERROR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/json_stream_error_test - -endif - -$(OBJDIR)/$(CONFIG)/test/core/json/json_stream_error_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_json_stream_error_test: $(JSON_STREAM_ERROR_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(JSON_STREAM_ERROR_TEST_OBJS:.o=.dep) -endif -endif - - JSON_TEST_SRC = \ test/core/json/json_test.cc \ diff --git a/build.yaml b/build.yaml index 8c70a455bd5..d29dc2b5499 100644 --- a/build.yaml +++ b/build.yaml @@ -746,7 +746,6 @@ filegroups: - src/core/lib/iomgr/wakeup_fd_posix.cc - src/core/lib/json/json.cc - src/core/lib/json/json_reader.cc - - src/core/lib/json/json_string.cc - src/core/lib/json/json_writer.cc - src/core/lib/slice/b64.cc - src/core/lib/slice/percent_encoding.cc @@ -912,9 +911,6 @@ filegroups: - src/core/lib/iomgr/wakeup_fd_pipe.h - src/core/lib/iomgr/wakeup_fd_posix.h - src/core/lib/json/json.h - - src/core/lib/json/json_common.h - - src/core/lib/json/json_reader.h - - src/core/lib/json/json_writer.h - src/core/lib/slice/b64.h - src/core/lib/slice/percent_encoding.h - src/core/lib/slice/slice_hash_table.h @@ -3251,37 +3247,6 @@ targets: corpus_dirs: - test/core/json/corpus maxlen: 512 -- name: json_rewrite - build: test - run: false - language: c - src: - - test/core/json/json_rewrite.cc - deps: - - grpc_test_util - - grpc - - gpr - uses_polling: false -- name: json_rewrite_test - build: test - language: c - src: - - test/core/json/json_rewrite_test.cc - deps: - - grpc_test_util - - grpc - - gpr - uses_polling: false -- name: json_stream_error_test - build: test - language: c - src: - - test/core/json/json_stream_error_test.cc - deps: - - grpc_test_util - - grpc - - gpr - uses_polling: false - name: json_test build: test language: c diff --git a/config.m4 b/config.m4 index 5f320d21b27..e0e85f3e09f 100644 --- a/config.m4 +++ b/config.m4 @@ -335,7 +335,6 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/iomgr/wakeup_fd_posix.cc \ src/core/lib/json/json.cc \ src/core/lib/json/json_reader.cc \ - src/core/lib/json/json_string.cc \ src/core/lib/json/json_writer.cc \ src/core/lib/profiling/basic_timers.cc \ src/core/lib/profiling/stap_timers.cc \ diff --git a/config.w32 b/config.w32 index 1f4d768a4b7..2da55d6085f 100644 --- a/config.w32 +++ b/config.w32 @@ -178,7 +178,6 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\iomgr\\wakeup_fd_posix.cc " + "src\\core\\lib\\json\\json.cc " + "src\\core\\lib\\json\\json_reader.cc " + - "src\\core\\lib\\json\\json_string.cc " + "src\\core\\lib\\json\\json_writer.cc " + "src\\core\\lib\\slice\\b64.cc " + "src\\core\\lib\\slice\\percent_encoding.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 9dc4788d69f..80495bf319d 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -527,9 +527,6 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/wakeup_fd_pipe.h', 'src/core/lib/iomgr/wakeup_fd_posix.h', 'src/core/lib/json/json.h', - 'src/core/lib/json/json_common.h', - 'src/core/lib/json/json_reader.h', - 'src/core/lib/json/json_writer.h', 'src/core/lib/profiling/timers.h', 'src/core/lib/security/context/security_context.h', 'src/core/lib/security/credentials/alts/alts_credentials.h', @@ -817,9 +814,6 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/wakeup_fd_pipe.h', 'src/core/lib/iomgr/wakeup_fd_posix.h', 'src/core/lib/json/json.h', - 'src/core/lib/json/json_common.h', - 'src/core/lib/json/json_reader.h', - 'src/core/lib/json/json_writer.h', 'src/core/lib/profiling/timers.h', 'src/core/lib/slice/b64.h', 'src/core/lib/slice/percent_encoding.h', @@ -1121,9 +1115,6 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/wakeup_fd_pipe.h', 'src/core/lib/iomgr/wakeup_fd_posix.h', 'src/core/lib/json/json.h', - 'src/core/lib/json/json_common.h', - 'src/core/lib/json/json_reader.h', - 'src/core/lib/json/json_writer.h', 'src/core/lib/profiling/timers.h', 'src/core/lib/security/context/security_context.h', 'src/core/lib/security/credentials/alts/alts_credentials.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 943387a249b..0f2d193e63e 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -739,12 +739,8 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/wakeup_fd_posix.h', 'src/core/lib/json/json.cc', 'src/core/lib/json/json.h', - 'src/core/lib/json/json_common.h', 'src/core/lib/json/json_reader.cc', - 'src/core/lib/json/json_reader.h', - 'src/core/lib/json/json_string.cc', 'src/core/lib/json/json_writer.cc', - 'src/core/lib/json/json_writer.h', 'src/core/lib/profiling/basic_timers.cc', 'src/core/lib/profiling/stap_timers.cc', 'src/core/lib/profiling/timers.h', @@ -1224,9 +1220,6 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/wakeup_fd_pipe.h', 'src/core/lib/iomgr/wakeup_fd_posix.h', 'src/core/lib/json/json.h', - 'src/core/lib/json/json_common.h', - 'src/core/lib/json/json_reader.h', - 'src/core/lib/json/json_writer.h', 'src/core/lib/profiling/timers.h', 'src/core/lib/security/context/security_context.h', 'src/core/lib/security/credentials/alts/alts_credentials.h', diff --git a/grpc.gemspec b/grpc.gemspec index 379f00376c6..a91cf0d9eb3 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -651,12 +651,8 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/wakeup_fd_posix.h ) s.files += %w( src/core/lib/json/json.cc ) s.files += %w( src/core/lib/json/json.h ) - s.files += %w( src/core/lib/json/json_common.h ) s.files += %w( src/core/lib/json/json_reader.cc ) - s.files += %w( src/core/lib/json/json_reader.h ) - s.files += %w( src/core/lib/json/json_string.cc ) s.files += %w( src/core/lib/json/json_writer.cc ) - s.files += %w( src/core/lib/json/json_writer.h ) s.files += %w( src/core/lib/profiling/basic_timers.cc ) s.files += %w( src/core/lib/profiling/stap_timers.cc ) s.files += %w( src/core/lib/profiling/timers.h ) diff --git a/grpc.gyp b/grpc.gyp index 1dbb8e61295..e4e4aff7ddf 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -347,7 +347,6 @@ 'src/core/lib/iomgr/wakeup_fd_posix.cc', 'src/core/lib/json/json.cc', 'src/core/lib/json/json_reader.cc', - 'src/core/lib/json/json_string.cc', 'src/core/lib/json/json_writer.cc', 'src/core/lib/slice/b64.cc', 'src/core/lib/slice/percent_encoding.cc', @@ -759,7 +758,6 @@ 'src/core/lib/iomgr/wakeup_fd_posix.cc', 'src/core/lib/json/json.cc', 'src/core/lib/json/json_reader.cc', - 'src/core/lib/json/json_string.cc', 'src/core/lib/json/json_writer.cc', 'src/core/lib/slice/b64.cc', 'src/core/lib/slice/percent_encoding.cc', @@ -1022,7 +1020,6 @@ 'src/core/lib/iomgr/wakeup_fd_posix.cc', 'src/core/lib/json/json.cc', 'src/core/lib/json/json_reader.cc', - 'src/core/lib/json/json_string.cc', 'src/core/lib/json/json_writer.cc', 'src/core/lib/slice/b64.cc', 'src/core/lib/slice/percent_encoding.cc', @@ -1261,7 +1258,6 @@ 'src/core/lib/iomgr/wakeup_fd_posix.cc', 'src/core/lib/json/json.cc', 'src/core/lib/json/json_reader.cc', - 'src/core/lib/json/json_string.cc', 'src/core/lib/json/json_writer.cc', 'src/core/lib/slice/b64.cc', 'src/core/lib/slice/percent_encoding.cc', @@ -1690,7 +1686,6 @@ 'src/core/lib/iomgr/wakeup_fd_posix.cc', 'src/core/lib/json/json.cc', 'src/core/lib/json/json_reader.cc', - 'src/core/lib/json/json_string.cc', 'src/core/lib/json/json_writer.cc', 'src/core/lib/slice/b64.cc', 'src/core/lib/slice/percent_encoding.cc', @@ -2044,7 +2039,6 @@ 'src/core/lib/iomgr/wakeup_fd_posix.cc', 'src/core/lib/json/json.cc', 'src/core/lib/json/json_reader.cc', - 'src/core/lib/json/json_string.cc', 'src/core/lib/json/json_writer.cc', 'src/core/lib/slice/b64.cc', 'src/core/lib/slice/percent_encoding.cc', diff --git a/package.xml b/package.xml index 30c7998d38e..3066eca92b7 100644 --- a/package.xml +++ b/package.xml @@ -634,12 +634,8 @@ - - - - diff --git a/src/core/lib/json/json.h b/src/core/lib/json/json.h index 2f61034efbc..d7ac989026e 100644 --- a/src/core/lib/json/json.h +++ b/src/core/lib/json/json.h @@ -24,7 +24,17 @@ #include #include -#include "src/core/lib/json/json_common.h" +/* The various json types. */ +typedef enum { + GRPC_JSON_OBJECT, + GRPC_JSON_ARRAY, + GRPC_JSON_STRING, + GRPC_JSON_NUMBER, + GRPC_JSON_TRUE, + GRPC_JSON_FALSE, + GRPC_JSON_NULL, + GRPC_JSON_TOP_LEVEL +} grpc_json_type; /* A tree-like structure to hold json values. The key and value pointers * are not owned by it. diff --git a/src/core/lib/json/json_common.h b/src/core/lib/json/json_common.h deleted file mode 100644 index bfa2ba32bea..00000000000 --- a/src/core/lib/json/json_common.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_LIB_JSON_JSON_COMMON_H -#define GRPC_CORE_LIB_JSON_JSON_COMMON_H - -/* The various json types. */ -typedef enum { - GRPC_JSON_OBJECT, - GRPC_JSON_ARRAY, - GRPC_JSON_STRING, - GRPC_JSON_NUMBER, - GRPC_JSON_TRUE, - GRPC_JSON_FALSE, - GRPC_JSON_NULL, - GRPC_JSON_TOP_LEVEL -} grpc_json_type; - -#endif /* GRPC_CORE_LIB_JSON_JSON_COMMON_H */ diff --git a/src/core/lib/json/json_reader.cc b/src/core/lib/json/json_reader.cc index 819572e4dea..0e7caec1714 100644 --- a/src/core/lib/json/json_reader.cc +++ b/src/core/lib/json/json_reader.cc @@ -22,76 +22,227 @@ #include -#include "src/core/lib/json/json_reader.h" +#include "src/core/lib/json/json.h" + +typedef enum { + GRPC_JSON_STATE_OBJECT_KEY_BEGIN, + GRPC_JSON_STATE_OBJECT_KEY_STRING, + GRPC_JSON_STATE_OBJECT_KEY_END, + GRPC_JSON_STATE_VALUE_BEGIN, + GRPC_JSON_STATE_VALUE_STRING, + GRPC_JSON_STATE_STRING_ESCAPE, + GRPC_JSON_STATE_STRING_ESCAPE_U1, + GRPC_JSON_STATE_STRING_ESCAPE_U2, + GRPC_JSON_STATE_STRING_ESCAPE_U3, + GRPC_JSON_STATE_STRING_ESCAPE_U4, + GRPC_JSON_STATE_VALUE_NUMBER, + GRPC_JSON_STATE_VALUE_NUMBER_WITH_DECIMAL, + GRPC_JSON_STATE_VALUE_NUMBER_ZERO, + GRPC_JSON_STATE_VALUE_NUMBER_DOT, + GRPC_JSON_STATE_VALUE_NUMBER_E, + GRPC_JSON_STATE_VALUE_NUMBER_EPM, + GRPC_JSON_STATE_VALUE_TRUE_R, + GRPC_JSON_STATE_VALUE_TRUE_U, + GRPC_JSON_STATE_VALUE_TRUE_E, + GRPC_JSON_STATE_VALUE_FALSE_A, + GRPC_JSON_STATE_VALUE_FALSE_L, + GRPC_JSON_STATE_VALUE_FALSE_S, + GRPC_JSON_STATE_VALUE_FALSE_E, + GRPC_JSON_STATE_VALUE_NULL_U, + GRPC_JSON_STATE_VALUE_NULL_L1, + GRPC_JSON_STATE_VALUE_NULL_L2, + GRPC_JSON_STATE_VALUE_END, + GRPC_JSON_STATE_END +} grpc_json_reader_state; + +enum { + /* The first non-unicode value is 0x110000. But let's pick + * a value high enough to start our error codes from. These + * values are safe to return from the read_char function. + */ + GRPC_JSON_READ_CHAR_EOF = 0x7ffffff0, + GRPC_JSON_READ_CHAR_EAGAIN, + GRPC_JSON_READ_CHAR_ERROR +}; + +typedef struct grpc_json_reader { + /* That structure is fully private, and initialized by grpc_json_reader_init. + * The definition is public so you can put it on your stack. + */ + + int depth; + int in_object; + int in_array; + int escaped_string_was_key; + int container_just_begun; + uint16_t unicode_char, unicode_high_surrogate; + grpc_json_reader_state state; + + grpc_json* top; + grpc_json* current_container; + grpc_json* current_value; + uint8_t* input; + uint8_t* key; + uint8_t* string; + uint8_t* string_ptr; + size_t remaining_input; +} grpc_json_reader; + +/* The return type of the parser. */ +typedef enum { + GRPC_JSON_DONE, /* The parser finished successfully. */ + GRPC_JSON_EAGAIN, /* The parser yields to get more data. */ + GRPC_JSON_READ_ERROR, /* The parser passes through a read error. */ + GRPC_JSON_PARSE_ERROR, /* The parser found an error in the json stream. */ + GRPC_JSON_INTERNAL_ERROR /* The parser got an internal error. */ +} grpc_json_reader_status; static void json_reader_string_clear(grpc_json_reader* reader) { - reader->vtable->string_clear(reader->userdata); + if (reader->string) { + GPR_ASSERT(reader->string_ptr < reader->input); + *reader->string_ptr++ = 0; + } + reader->string = reader->string_ptr; } static void json_reader_string_add_char(grpc_json_reader* reader, uint32_t c) { - reader->vtable->string_add_char(reader->userdata, c); + GPR_ASSERT(reader->string_ptr < reader->input); + GPR_ASSERT(c <= 0xff); + *reader->string_ptr++ = static_cast(c); } -static void json_reader_string_add_utf32(grpc_json_reader* reader, - uint32_t utf32) { - reader->vtable->string_add_utf32(reader->userdata, utf32); +static void json_reader_string_add_utf32(grpc_json_reader* reader, uint32_t c) { + if (c <= 0x7f) { + json_reader_string_add_char(reader, c); + } else if (c <= 0x7ff) { + uint32_t b1 = 0xc0 | ((c >> 6) & 0x1f); + uint32_t b2 = 0x80 | (c & 0x3f); + json_reader_string_add_char(reader, b1); + json_reader_string_add_char(reader, b2); + } else if (c <= 0xffff) { + uint32_t b1 = 0xe0 | ((c >> 12) & 0x0f); + uint32_t b2 = 0x80 | ((c >> 6) & 0x3f); + uint32_t b3 = 0x80 | (c & 0x3f); + json_reader_string_add_char(reader, b1); + json_reader_string_add_char(reader, b2); + json_reader_string_add_char(reader, b3); + } else if (c <= 0x1fffff) { + uint32_t b1 = 0xf0 | ((c >> 18) & 0x07); + uint32_t b2 = 0x80 | ((c >> 12) & 0x3f); + uint32_t b3 = 0x80 | ((c >> 6) & 0x3f); + uint32_t b4 = 0x80 | (c & 0x3f); + json_reader_string_add_char(reader, b1); + json_reader_string_add_char(reader, b2); + json_reader_string_add_char(reader, b3); + json_reader_string_add_char(reader, b4); + } } static uint32_t grpc_json_reader_read_char(grpc_json_reader* reader) { - return reader->vtable->read_char(reader->userdata); + if (reader->remaining_input == 0) return GRPC_JSON_READ_CHAR_EOF; + uint32_t r = *reader->input++; + reader->remaining_input--; + if (r == 0) { + reader->remaining_input = 0; + return GRPC_JSON_READ_CHAR_EOF; + } + return r; +} + +/* Helper function to create a new grpc_json object and link it into + * our tree-in-progress inside our opaque structure. + */ +static grpc_json* json_create_and_link(grpc_json_reader* reader, + grpc_json_type type) { + grpc_json* json = grpc_json_create(type); + json->parent = reader->current_container; + json->prev = reader->current_value; + reader->current_value = json; + if (json->prev) { + json->prev->next = json; + } + if (json->parent) { + if (!json->parent->child) { + json->parent->child = json; + } + if (json->parent->type == GRPC_JSON_OBJECT) { + json->key = reinterpret_cast(reader->key); + } + } + if (!reader->top) { + reader->top = json; + } + return json; } static void json_reader_container_begins(grpc_json_reader* reader, grpc_json_type type) { - reader->vtable->container_begins(reader->userdata, type); + GPR_ASSERT(type == GRPC_JSON_ARRAY || type == GRPC_JSON_OBJECT); + grpc_json* container = json_create_and_link(reader, type); + reader->current_container = container; + reader->current_value = nullptr; } static grpc_json_type grpc_json_reader_container_ends( grpc_json_reader* reader) { - return reader->vtable->container_ends(reader->userdata); + grpc_json_type container_type = GRPC_JSON_TOP_LEVEL; + GPR_ASSERT(reader->current_container); + reader->current_value = reader->current_container; + reader->current_container = reader->current_container->parent; + if (reader->current_container) { + container_type = reader->current_container->type; + } + return container_type; } static void json_reader_set_key(grpc_json_reader* reader) { - reader->vtable->set_key(reader->userdata); + reader->key = reader->string; } static void json_reader_set_string(grpc_json_reader* reader) { - reader->vtable->set_string(reader->userdata); + grpc_json* json = json_create_and_link(reader, GRPC_JSON_STRING); + json->value = reinterpret_cast(reader->string); } static int json_reader_set_number(grpc_json_reader* reader) { - return reader->vtable->set_number(reader->userdata); + grpc_json* json = json_create_and_link(reader, GRPC_JSON_NUMBER); + json->value = reinterpret_cast(reader->string); + return 1; } static void json_reader_set_true(grpc_json_reader* reader) { - reader->vtable->set_true(reader->userdata); + json_create_and_link(reader, GRPC_JSON_TRUE); } static void json_reader_set_false(grpc_json_reader* reader) { - reader->vtable->set_false(reader->userdata); + json_create_and_link(reader, GRPC_JSON_FALSE); } static void json_reader_set_null(grpc_json_reader* reader) { - reader->vtable->set_null(reader->userdata); -} - -/* Call this function to initialize the reader structure. */ -void grpc_json_reader_init(grpc_json_reader* reader, - grpc_json_reader_vtable* vtable, void* userdata) { - memset(reader, 0, sizeof(*reader)); - reader->vtable = vtable; - reader->userdata = userdata; - json_reader_string_clear(reader); - reader->state = GRPC_JSON_STATE_VALUE_BEGIN; + json_create_and_link(reader, GRPC_JSON_NULL); } -int grpc_json_reader_is_complete(grpc_json_reader* reader) { +static int json_reader_is_complete(grpc_json_reader* reader) { return ((reader->depth == 0) && ((reader->state == GRPC_JSON_STATE_END) || (reader->state == GRPC_JSON_STATE_VALUE_END))); } -grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { +/* Call this function to start parsing the input. It will return the following: + * . GRPC_JSON_DONE if the input got eof, and the parsing finished + * successfully. + * . GRPC_JSON_EAGAIN if the read_char function returned again. Call the + * parser again as needed. It is okay to call the parser in polling mode, + * although a bit dull. + * . GRPC_JSON_READ_ERROR if the read_char function returned an error. The + * state isn't broken however, and the function can be called again if the + * error has been corrected. But please use the EAGAIN feature instead for + * consistency. + * . GRPC_JSON_PARSE_ERROR if the input was somehow invalid. + * . GRPC_JSON_INTERNAL_ERROR if the parser somehow ended into an invalid + * internal state. + */ +static grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { uint32_t c, success; /* This state-machine is a strict implementation of ECMA-404 */ @@ -106,7 +257,7 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { return GRPC_JSON_EAGAIN; case GRPC_JSON_READ_CHAR_EOF: - if (grpc_json_reader_is_complete(reader)) { + if (json_reader_is_complete(reader)) { return GRPC_JSON_DONE; } else { return GRPC_JSON_PARSE_ERROR; @@ -661,3 +812,30 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { GPR_UNREACHABLE_CODE(return GRPC_JSON_INTERNAL_ERROR); } + +/* And finally, let's define our public API. */ +grpc_json* grpc_json_parse_string_with_len(char* input, size_t size) { + if (input == nullptr) return nullptr; + // Initialize reader. + grpc_json_reader reader; + memset(&reader, 0, sizeof(reader)); + reader.string_ptr = reader.input = reinterpret_cast(input); + reader.remaining_input = size; + json_reader_string_clear(&reader); + reader.state = GRPC_JSON_STATE_VALUE_BEGIN; + // Perform read. + grpc_json_reader_status status = grpc_json_reader_run(&reader); + // Process results. + grpc_json* json = reader.top; + if ((status != GRPC_JSON_DONE) && json != nullptr) { + grpc_json_destroy(json); + json = nullptr; + } + return json; +} + +#define UNBOUND_JSON_STRING_LENGTH 0x7fffffff + +grpc_json* grpc_json_parse_string(char* input) { + return grpc_json_parse_string_with_len(input, UNBOUND_JSON_STRING_LENGTH); +} diff --git a/src/core/lib/json/json_reader.h b/src/core/lib/json/json_reader.h deleted file mode 100644 index 78f7ad9f3a8..00000000000 --- a/src/core/lib/json/json_reader.h +++ /dev/null @@ -1,146 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_LIB_JSON_JSON_READER_H -#define GRPC_CORE_LIB_JSON_JSON_READER_H - -#include - -#include "src/core/lib/json/json_common.h" - -typedef enum { - GRPC_JSON_STATE_OBJECT_KEY_BEGIN, - GRPC_JSON_STATE_OBJECT_KEY_STRING, - GRPC_JSON_STATE_OBJECT_KEY_END, - GRPC_JSON_STATE_VALUE_BEGIN, - GRPC_JSON_STATE_VALUE_STRING, - GRPC_JSON_STATE_STRING_ESCAPE, - GRPC_JSON_STATE_STRING_ESCAPE_U1, - GRPC_JSON_STATE_STRING_ESCAPE_U2, - GRPC_JSON_STATE_STRING_ESCAPE_U3, - GRPC_JSON_STATE_STRING_ESCAPE_U4, - GRPC_JSON_STATE_VALUE_NUMBER, - GRPC_JSON_STATE_VALUE_NUMBER_WITH_DECIMAL, - GRPC_JSON_STATE_VALUE_NUMBER_ZERO, - GRPC_JSON_STATE_VALUE_NUMBER_DOT, - GRPC_JSON_STATE_VALUE_NUMBER_E, - GRPC_JSON_STATE_VALUE_NUMBER_EPM, - GRPC_JSON_STATE_VALUE_TRUE_R, - GRPC_JSON_STATE_VALUE_TRUE_U, - GRPC_JSON_STATE_VALUE_TRUE_E, - GRPC_JSON_STATE_VALUE_FALSE_A, - GRPC_JSON_STATE_VALUE_FALSE_L, - GRPC_JSON_STATE_VALUE_FALSE_S, - GRPC_JSON_STATE_VALUE_FALSE_E, - GRPC_JSON_STATE_VALUE_NULL_U, - GRPC_JSON_STATE_VALUE_NULL_L1, - GRPC_JSON_STATE_VALUE_NULL_L2, - GRPC_JSON_STATE_VALUE_END, - GRPC_JSON_STATE_END -} grpc_json_reader_state; - -enum { - /* The first non-unicode value is 0x110000. But let's pick - * a value high enough to start our error codes from. These - * values are safe to return from the read_char function. - */ - GRPC_JSON_READ_CHAR_EOF = 0x7ffffff0, - GRPC_JSON_READ_CHAR_EAGAIN, - GRPC_JSON_READ_CHAR_ERROR -}; - -struct grpc_json_reader; - -typedef struct grpc_json_reader_vtable { - /* Clears your internal string scratchpad. */ - void (*string_clear)(void* userdata); - /* Adds a char to the string scratchpad. */ - void (*string_add_char)(void* userdata, uint32_t c); - /* Adds a utf32 char to the string scratchpad. */ - void (*string_add_utf32)(void* userdata, uint32_t c); - /* Reads a character from your input. May be utf-8, 16 or 32. */ - uint32_t (*read_char)(void* userdata); - /* Starts a container of type GRPC_JSON_ARRAY or GRPC_JSON_OBJECT. */ - void (*container_begins)(void* userdata, grpc_json_type type); - /* Ends the current container. Must return the type of its parent. */ - grpc_json_type (*container_ends)(void* userdata); - /* Your internal string scratchpad is an object's key. */ - void (*set_key)(void* userdata); - /* Your internal string scratchpad is a string value. */ - void (*set_string)(void* userdata); - /* Your internal string scratchpad is a numerical value. Return 1 if valid. */ - int (*set_number)(void* userdata); - /* Sets the values true, false or null. */ - void (*set_true)(void* userdata); - void (*set_false)(void* userdata); - void (*set_null)(void* userdata); -} grpc_json_reader_vtable; - -typedef struct grpc_json_reader { - /* That structure is fully private, and initialized by grpc_json_reader_init. - * The definition is public so you can put it on your stack. - */ - - void* userdata; - grpc_json_reader_vtable* vtable; - int depth; - int in_object; - int in_array; - int escaped_string_was_key; - int container_just_begun; - uint16_t unicode_char, unicode_high_surrogate; - grpc_json_reader_state state; -} grpc_json_reader; - -/* The return type of the parser. */ -typedef enum { - GRPC_JSON_DONE, /* The parser finished successfully. */ - GRPC_JSON_EAGAIN, /* The parser yields to get more data. */ - GRPC_JSON_READ_ERROR, /* The parser passes through a read error. */ - GRPC_JSON_PARSE_ERROR, /* The parser found an error in the json stream. */ - GRPC_JSON_INTERNAL_ERROR /* The parser got an internal error. */ -} grpc_json_reader_status; - -/* Call this function to start parsing the input. It will return the following: - * . GRPC_JSON_DONE if the input got eof, and the parsing finished - * successfully. - * . GRPC_JSON_EAGAIN if the read_char function returned again. Call the - * parser again as needed. It is okay to call the parser in polling mode, - * although a bit dull. - * . GRPC_JSON_READ_ERROR if the read_char function returned an error. The - * state isn't broken however, and the function can be called again if the - * error has been corrected. But please use the EAGAIN feature instead for - * consistency. - * . GRPC_JSON_PARSE_ERROR if the input was somehow invalid. - * . GRPC_JSON_INTERNAL_ERROR if the parser somehow ended into an invalid - * internal state. - */ -grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader); - -/* Call this function to initialize the reader structure. */ -void grpc_json_reader_init(grpc_json_reader* reader, - grpc_json_reader_vtable* vtable, void* userdata); - -/* You may call this from the read_char callback if you don't know where is the - * end of your input stream, and you'd like the json reader to hint you that it - * has completed reading its input, so you can return an EOF to it. Note that - * there might still be trailing whitespaces after that point. - */ -int grpc_json_reader_is_complete(grpc_json_reader* reader); - -#endif /* GRPC_CORE_LIB_JSON_JSON_READER_H */ diff --git a/src/core/lib/json/json_string.cc b/src/core/lib/json/json_string.cc deleted file mode 100644 index a1f1a6a84e5..00000000000 --- a/src/core/lib/json/json_string.cc +++ /dev/null @@ -1,367 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include -#include - -#include -#include - -#include "src/core/lib/json/json.h" -#include "src/core/lib/json/json_reader.h" -#include "src/core/lib/json/json_writer.h" - -/* The json reader will construct a bunch of grpc_json objects and - * link them all up together in a tree-like structure that will represent - * the json data in memory. - * - * It also uses its own input as a scratchpad to store all of the decoded, - * unescaped strings. So we need to keep track of all these pointers in - * that opaque structure the reader will carry for us. - * - * Note that this works because the act of parsing json always reduces its - * input size, and never expands it. - */ -typedef struct { - grpc_json* top; - grpc_json* current_container; - grpc_json* current_value; - uint8_t* input; - uint8_t* key; - uint8_t* string; - uint8_t* string_ptr; - size_t remaining_input; -} json_reader_userdata; - -/* This json writer will put everything in a big string. - * The point is that we allocate that string in chunks of 256 bytes. - */ -typedef struct { - char* output; - size_t free_space; - size_t string_len; - size_t allocated; -} json_writer_userdata; - -/* This function checks if there's enough space left in the output buffer, - * and will enlarge it if necessary. We're only allocating chunks of 256 - * bytes at a time (or multiples thereof). - */ -static void json_writer_output_check(void* userdata, size_t needed) { - json_writer_userdata* state = static_cast(userdata); - if (state->free_space >= needed) return; - needed -= state->free_space; - /* Round up by 256 bytes. */ - needed = (needed + 0xff) & ~0xffU; - state->output = - static_cast(gpr_realloc(state->output, state->allocated + needed)); - state->free_space += needed; - state->allocated += needed; -} - -/* These are needed by the writer's implementation. */ -static void json_writer_output_char(void* userdata, char c) { - json_writer_userdata* state = static_cast(userdata); - json_writer_output_check(userdata, 1); - state->output[state->string_len++] = c; - state->free_space--; -} - -static void json_writer_output_string_with_len(void* userdata, const char* str, - size_t len) { - json_writer_userdata* state = static_cast(userdata); - json_writer_output_check(userdata, len); - memcpy(state->output + state->string_len, str, len); - state->string_len += len; - state->free_space -= len; -} - -static void json_writer_output_string(void* userdata, const char* str) { - size_t len = strlen(str); - json_writer_output_string_with_len(userdata, str, len); -} - -/* The reader asks us to clear our scratchpad. In our case, we'll simply mark - * the end of the current string, and advance our output pointer. - */ -static void json_reader_string_clear(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - if (state->string) { - GPR_ASSERT(state->string_ptr < state->input); - *state->string_ptr++ = 0; - } - state->string = state->string_ptr; -} - -static void json_reader_string_add_char(void* userdata, uint32_t c) { - json_reader_userdata* state = static_cast(userdata); - GPR_ASSERT(state->string_ptr < state->input); - GPR_ASSERT(c <= 0xff); - *state->string_ptr++ = static_cast(c); -} - -/* We are converting a UTF-32 character into UTF-8 here, - * as described by RFC3629. - */ -static void json_reader_string_add_utf32(void* userdata, uint32_t c) { - if (c <= 0x7f) { - json_reader_string_add_char(userdata, c); - } else if (c <= 0x7ff) { - uint32_t b1 = 0xc0 | ((c >> 6) & 0x1f); - uint32_t b2 = 0x80 | (c & 0x3f); - json_reader_string_add_char(userdata, b1); - json_reader_string_add_char(userdata, b2); - } else if (c <= 0xffff) { - uint32_t b1 = 0xe0 | ((c >> 12) & 0x0f); - uint32_t b2 = 0x80 | ((c >> 6) & 0x3f); - uint32_t b3 = 0x80 | (c & 0x3f); - json_reader_string_add_char(userdata, b1); - json_reader_string_add_char(userdata, b2); - json_reader_string_add_char(userdata, b3); - } else if (c <= 0x1fffff) { - uint32_t b1 = 0xf0 | ((c >> 18) & 0x07); - uint32_t b2 = 0x80 | ((c >> 12) & 0x3f); - uint32_t b3 = 0x80 | ((c >> 6) & 0x3f); - uint32_t b4 = 0x80 | (c & 0x3f); - json_reader_string_add_char(userdata, b1); - json_reader_string_add_char(userdata, b2); - json_reader_string_add_char(userdata, b3); - json_reader_string_add_char(userdata, b4); - } -} - -/* We consider that the input may be a zero-terminated string. So we - * can end up hitting eof before the end of the alleged string length. - */ -static uint32_t json_reader_read_char(void* userdata) { - uint32_t r; - json_reader_userdata* state = static_cast(userdata); - - if (state->remaining_input == 0) return GRPC_JSON_READ_CHAR_EOF; - - r = *state->input++; - state->remaining_input--; - - if (r == 0) { - state->remaining_input = 0; - return GRPC_JSON_READ_CHAR_EOF; - } - - return r; -} - -/* Helper function to create a new grpc_json object and link it into - * our tree-in-progress inside our opaque structure. - */ -static grpc_json* json_create_and_link(void* userdata, grpc_json_type type) { - json_reader_userdata* state = static_cast(userdata); - grpc_json* json = grpc_json_create(type); - - json->parent = state->current_container; - json->prev = state->current_value; - state->current_value = json; - - if (json->prev) { - json->prev->next = json; - } - if (json->parent) { - if (!json->parent->child) { - json->parent->child = json; - } - if (json->parent->type == GRPC_JSON_OBJECT) { - json->key = reinterpret_cast(state->key); - } - } - if (!state->top) { - state->top = json; - } - - return json; -} - -static void json_reader_container_begins(void* userdata, grpc_json_type type) { - json_reader_userdata* state = static_cast(userdata); - grpc_json* container; - - GPR_ASSERT(type == GRPC_JSON_ARRAY || type == GRPC_JSON_OBJECT); - - container = json_create_and_link(userdata, type); - state->current_container = container; - state->current_value = nullptr; -} - -/* It's important to remember that the reader is mostly stateless, so it - * isn't trying to remember what the container was prior the one that just - * ends. Since we're keeping track of these for our own purpose, we are - * able to return that information back, which is useful for it to validate - * the input json stream. - * - * Also note that if we're at the top of the tree, and the last container - * ends, we have to return GRPC_JSON_TOP_LEVEL. - */ -static grpc_json_type json_reader_container_ends(void* userdata) { - grpc_json_type container_type = GRPC_JSON_TOP_LEVEL; - json_reader_userdata* state = static_cast(userdata); - - GPR_ASSERT(state->current_container); - - state->current_value = state->current_container; - state->current_container = state->current_container->parent; - - if (state->current_container) { - container_type = state->current_container->type; - } - - return container_type; -} - -/* The next 3 functions basically are the reader asking us to use our string - * scratchpad for one of these 3 purposes. - * - * Note that in the set_number case, we're not going to try interpreting it. - * We'll keep it as a string, and leave it to the caller to evaluate it. - */ -static void json_reader_set_key(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - state->key = state->string; -} - -static void json_reader_set_string(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - grpc_json* json = json_create_and_link(userdata, GRPC_JSON_STRING); - json->value = reinterpret_cast(state->string); -} - -static int json_reader_set_number(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - grpc_json* json = json_create_and_link(userdata, GRPC_JSON_NUMBER); - json->value = reinterpret_cast(state->string); - return 1; -} - -/* The object types true, false and null are self-sufficient, and don't need - * any more information beside their type. - */ -static void json_reader_set_true(void* userdata) { - json_create_and_link(userdata, GRPC_JSON_TRUE); -} - -static void json_reader_set_false(void* userdata) { - json_create_and_link(userdata, GRPC_JSON_FALSE); -} - -static void json_reader_set_null(void* userdata) { - json_create_and_link(userdata, GRPC_JSON_NULL); -} - -static grpc_json_reader_vtable reader_vtable = { - json_reader_string_clear, json_reader_string_add_char, - json_reader_string_add_utf32, json_reader_read_char, - json_reader_container_begins, json_reader_container_ends, - json_reader_set_key, json_reader_set_string, - json_reader_set_number, json_reader_set_true, - json_reader_set_false, json_reader_set_null}; - -/* And finally, let's define our public API. */ -grpc_json* grpc_json_parse_string_with_len(char* input, size_t size) { - grpc_json_reader reader; - json_reader_userdata state; - grpc_json* json = nullptr; - grpc_json_reader_status status; - - if (!input) return nullptr; - - state.top = state.current_container = state.current_value = nullptr; - state.string = state.key = nullptr; - state.string_ptr = state.input = reinterpret_cast(input); - state.remaining_input = size; - grpc_json_reader_init(&reader, &reader_vtable, &state); - - status = grpc_json_reader_run(&reader); - json = state.top; - - if ((status != GRPC_JSON_DONE) && json) { - grpc_json_destroy(json); - json = nullptr; - } - - return json; -} - -#define UNBOUND_JSON_STRING_LENGTH 0x7fffffff - -grpc_json* grpc_json_parse_string(char* input) { - return grpc_json_parse_string_with_len(input, UNBOUND_JSON_STRING_LENGTH); -} - -static void json_dump_recursive(grpc_json_writer* writer, const grpc_json* json, - int in_object) { - while (json) { - if (in_object) grpc_json_writer_object_key(writer, json->key); - - switch (json->type) { - case GRPC_JSON_OBJECT: - case GRPC_JSON_ARRAY: - grpc_json_writer_container_begins(writer, json->type); - if (json->child) - json_dump_recursive(writer, json->child, - json->type == GRPC_JSON_OBJECT); - grpc_json_writer_container_ends(writer, json->type); - break; - case GRPC_JSON_STRING: - grpc_json_writer_value_string(writer, json->value); - break; - case GRPC_JSON_NUMBER: - grpc_json_writer_value_raw(writer, json->value); - break; - case GRPC_JSON_TRUE: - grpc_json_writer_value_raw_with_len(writer, "true", 4); - break; - case GRPC_JSON_FALSE: - grpc_json_writer_value_raw_with_len(writer, "false", 5); - break; - case GRPC_JSON_NULL: - grpc_json_writer_value_raw_with_len(writer, "null", 4); - break; - default: - GPR_UNREACHABLE_CODE(abort()); - } - json = json->next; - } -} - -static grpc_json_writer_vtable writer_vtable = { - json_writer_output_char, json_writer_output_string, - json_writer_output_string_with_len}; - -char* grpc_json_dump_to_string(const grpc_json* json, int indent) { - grpc_json_writer writer; - json_writer_userdata state; - - state.output = nullptr; - state.free_space = state.string_len = state.allocated = 0; - grpc_json_writer_init(&writer, indent, &writer_vtable, &state); - - json_dump_recursive(&writer, json, 0); - - json_writer_output_char(&state, 0); - - return state.output; -} diff --git a/src/core/lib/json/json_writer.cc b/src/core/lib/json/json_writer.cc index 7bbdccc7a37..6dbb08ccd1e 100644 --- a/src/core/lib/json/json_writer.cc +++ b/src/core/lib/json/json_writer.cc @@ -18,31 +18,70 @@ #include +#include #include -#include "src/core/lib/json/json_writer.h" +#include +#include -static void json_writer_output_char(grpc_json_writer* writer, char c) { - writer->vtable->output_char(writer->userdata, c); +#include "src/core/lib/json/json.h" + +/* The idea of the writer is basically symmetrical of the reader. While the + * reader emits various calls to your code, the writer takes basically the + * same calls and emit json out of it. It doesn't try to make any check on + * the order of the calls you do on it. Meaning you can theorically force + * it to generate invalid json. + * + * Also, unlike the reader, the writer expects UTF-8 encoded input strings. + * These strings will be UTF-8 validated, and any invalid character will + * cut the conversion short, before any invalid UTF-8 sequence, thus forming + * a valid UTF-8 string overall. + */ + +typedef struct grpc_json_writer { + int indent; + int depth; + int container_empty; + int got_key; + char* output; + size_t free_space; + size_t string_len; + size_t allocated; +} grpc_json_writer; + +/* This function checks if there's enough space left in the output buffer, + * and will enlarge it if necessary. We're only allocating chunks of 256 + * bytes at a time (or multiples thereof). + */ +static void json_writer_output_check(grpc_json_writer* writer, size_t needed) { + if (writer->free_space >= needed) return; + needed -= writer->free_space; + /* Round up by 256 bytes. */ + needed = (needed + 0xff) & ~0xffU; + writer->output = static_cast( + gpr_realloc(writer->output, writer->allocated + needed)); + writer->free_space += needed; + writer->allocated += needed; } -static void json_writer_output_string(grpc_json_writer* writer, - const char* str) { - writer->vtable->output_string(writer->userdata, str); +static void json_writer_output_char(grpc_json_writer* writer, char c) { + json_writer_output_check(writer, 1); + writer->output[writer->string_len++] = c; + writer->free_space--; } static void json_writer_output_string_with_len(grpc_json_writer* writer, const char* str, size_t len) { - writer->vtable->output_string_with_len(writer->userdata, str, len); + json_writer_output_check(writer, len); + memcpy(writer->output + writer->string_len, str, len); + writer->string_len += len; + writer->free_space -= len; } -void grpc_json_writer_init(grpc_json_writer* writer, int indent, - grpc_json_writer_vtable* vtable, void* userdata) { - memset(writer, 0, sizeof(*writer)); - writer->container_empty = 1; - writer->indent = indent; - writer->vtable = vtable; - writer->userdata = userdata; +static void json_writer_output_string(grpc_json_writer* writer, + const char* str) { + size_t len = strlen(str); + json_writer_output_string_with_len(writer, str, len); } static void json_writer_output_indent(grpc_json_writer* writer) { @@ -192,8 +231,8 @@ static void json_writer_escape_string(grpc_json_writer* writer, json_writer_output_char(writer, '"'); } -void grpc_json_writer_container_begins(grpc_json_writer* writer, - grpc_json_type type) { +static void grpc_json_writer_container_begins(grpc_json_writer* writer, + grpc_json_type type) { if (!writer->got_key) json_writer_value_end(writer); json_writer_output_indent(writer); json_writer_output_char(writer, type == GRPC_JSON_OBJECT ? '{' : '['); @@ -202,8 +241,8 @@ void grpc_json_writer_container_begins(grpc_json_writer* writer, writer->depth++; } -void grpc_json_writer_container_ends(grpc_json_writer* writer, - grpc_json_type type) { +static void grpc_json_writer_container_ends(grpc_json_writer* writer, + grpc_json_type type) { if (writer->indent && !writer->container_empty) json_writer_output_char(writer, '\n'); writer->depth--; @@ -213,7 +252,8 @@ void grpc_json_writer_container_ends(grpc_json_writer* writer, writer->got_key = 0; } -void grpc_json_writer_object_key(grpc_json_writer* writer, const char* string) { +static void grpc_json_writer_object_key(grpc_json_writer* writer, + const char* string) { json_writer_value_end(writer); json_writer_output_indent(writer); json_writer_escape_string(writer, string); @@ -221,25 +261,72 @@ void grpc_json_writer_object_key(grpc_json_writer* writer, const char* string) { writer->got_key = 1; } -void grpc_json_writer_value_raw(grpc_json_writer* writer, const char* string) { +static void grpc_json_writer_value_raw(grpc_json_writer* writer, + const char* string) { if (!writer->got_key) json_writer_value_end(writer); json_writer_output_indent(writer); json_writer_output_string(writer, string); writer->got_key = 0; } -void grpc_json_writer_value_raw_with_len(grpc_json_writer* writer, - const char* string, size_t len) { +static void grpc_json_writer_value_raw_with_len(grpc_json_writer* writer, + const char* string, + size_t len) { if (!writer->got_key) json_writer_value_end(writer); json_writer_output_indent(writer); json_writer_output_string_with_len(writer, string, len); writer->got_key = 0; } -void grpc_json_writer_value_string(grpc_json_writer* writer, - const char* string) { +static void grpc_json_writer_value_string(grpc_json_writer* writer, + const char* string) { if (!writer->got_key) json_writer_value_end(writer); json_writer_output_indent(writer); json_writer_escape_string(writer, string); writer->got_key = 0; } + +static void json_dump_recursive(grpc_json_writer* writer, const grpc_json* json, + int in_object) { + while (json) { + if (in_object) grpc_json_writer_object_key(writer, json->key); + switch (json->type) { + case GRPC_JSON_OBJECT: + case GRPC_JSON_ARRAY: + grpc_json_writer_container_begins(writer, json->type); + if (json->child) + json_dump_recursive(writer, json->child, + json->type == GRPC_JSON_OBJECT); + grpc_json_writer_container_ends(writer, json->type); + break; + case GRPC_JSON_STRING: + grpc_json_writer_value_string(writer, json->value); + break; + case GRPC_JSON_NUMBER: + grpc_json_writer_value_raw(writer, json->value); + break; + case GRPC_JSON_TRUE: + grpc_json_writer_value_raw_with_len(writer, "true", 4); + break; + case GRPC_JSON_FALSE: + grpc_json_writer_value_raw_with_len(writer, "false", 5); + break; + case GRPC_JSON_NULL: + grpc_json_writer_value_raw_with_len(writer, "null", 4); + break; + default: + GPR_UNREACHABLE_CODE(abort()); + } + json = json->next; + } +} + +char* grpc_json_dump_to_string(const grpc_json* json, int indent) { + grpc_json_writer writer; + memset(&writer, 0, sizeof(writer)); + writer.container_empty = 1; + writer.indent = indent; + json_dump_recursive(&writer, json, 0); + json_writer_output_char(&writer, 0); + return writer.output; +} diff --git a/src/core/lib/json/json_writer.h b/src/core/lib/json/json_writer.h deleted file mode 100644 index ba0bedde7fa..00000000000 --- a/src/core/lib/json/json_writer.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/* The idea of the writer is basically symmetrical of the reader. While the - * reader emits various calls to your code, the writer takes basically the - * same calls and emit json out of it. It doesn't try to make any check on - * the order of the calls you do on it. Meaning you can theorically force - * it to generate invalid json. - * - * Also, unlike the reader, the writer expects UTF-8 encoded input strings. - * These strings will be UTF-8 validated, and any invalid character will - * cut the conversion short, before any invalid UTF-8 sequence, thus forming - * a valid UTF-8 string overall. - */ - -#ifndef GRPC_CORE_LIB_JSON_JSON_WRITER_H -#define GRPC_CORE_LIB_JSON_JSON_WRITER_H - -#include - -#include - -#include "src/core/lib/json/json_common.h" - -typedef struct grpc_json_writer_vtable { - /* Adds a character to the output stream. */ - void (*output_char)(void* userdata, char); - /* Adds a zero-terminated string to the output stream. */ - void (*output_string)(void* userdata, const char* str); - /* Adds a fixed-length string to the output stream. */ - void (*output_string_with_len)(void* userdata, const char* str, size_t len); - -} grpc_json_writer_vtable; - -typedef struct grpc_json_writer { - void* userdata; - grpc_json_writer_vtable* vtable; - int indent; - int depth; - int container_empty; - int got_key; -} grpc_json_writer; - -/* Call this to initialize your writer structure. The indent parameter is - * specifying the number of spaces to use for indenting the output. If you - * use indent=0, then the output will not have any newlines either, thus - * emitting a condensed json output. - */ -void grpc_json_writer_init(grpc_json_writer* writer, int indent, - grpc_json_writer_vtable* vtable, void* userdata); - -/* Signals the beginning of a container. */ -void grpc_json_writer_container_begins(grpc_json_writer* writer, - grpc_json_type type); -/* Signals the end of a container. */ -void grpc_json_writer_container_ends(grpc_json_writer* writer, - grpc_json_type type); -/* Writes down an object key for the next value. */ -void grpc_json_writer_object_key(grpc_json_writer* writer, const char* string); -/* Sets a raw value. Useful for numbers. */ -void grpc_json_writer_value_raw(grpc_json_writer* writer, const char* string); -/* Sets a raw value with its length. Useful for values like true or false. */ -void grpc_json_writer_value_raw_with_len(grpc_json_writer* writer, - const char* string, size_t len); -/* Sets a string value. It'll be escaped, and utf-8 validated. */ -void grpc_json_writer_value_string(grpc_json_writer* writer, - const char* string); - -#endif /* GRPC_CORE_LIB_JSON_JSON_WRITER_H */ diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 2e8c9c951b0..31458933f5f 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -314,7 +314,6 @@ CORE_SOURCE_FILES = [ 'src/core/lib/iomgr/wakeup_fd_posix.cc', 'src/core/lib/json/json.cc', 'src/core/lib/json/json_reader.cc', - 'src/core/lib/json/json_string.cc', 'src/core/lib/json/json_writer.cc', 'src/core/lib/profiling/basic_timers.cc', 'src/core/lib/profiling/stap_timers.cc', diff --git a/test/core/json/BUILD b/test/core/json/BUILD index 0bc75b5a13a..45c1c412448 100644 --- a/test/core/json/BUILD +++ b/test/core/json/BUILD @@ -33,48 +33,6 @@ grpc_fuzzer( ], ) -grpc_cc_binary( - name = "json_rewrite", - testonly = 1, - srcs = ["json_rewrite.cc"], - language = "C++", - deps = [ - "//:gpr", - "//:grpc", - "//test/core/util:grpc_test_util", - ], -) - -grpc_cc_test( - name = "json_rewrite_test", - srcs = ["json_rewrite_test.cc"], - data = [ - "rewrite_test_input.json", - "rewrite_test_output_condensed.json", - "rewrite_test_output_indented.json", - ":json_stream_error_test", - ], - language = "C++", - uses_polling = False, - deps = [ - "//:gpr", - "//:grpc", - "//test/core/util:grpc_test_util", - ], -) - -grpc_cc_test( - name = "json_stream_error_test", - srcs = ["json_stream_error_test.cc"], - language = "C++", - uses_polling = False, - deps = [ - "//:gpr", - "//:grpc", - "//test/core/util:grpc_test_util", - ], -) - grpc_cc_test( name = "json_test", srcs = ["json_test.cc"], diff --git a/test/core/json/json_rewrite.cc b/test/core/json/json_rewrite.cc deleted file mode 100644 index da2f50ec59f..00000000000 --- a/test/core/json/json_rewrite.cc +++ /dev/null @@ -1,241 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -#include -#include - -#include "src/core/lib/json/json_reader.h" -#include "src/core/lib/json/json_writer.h" -#include "test/core/util/cmdline.h" - -typedef struct json_writer_userdata { - FILE* out; -} json_writer_userdata; - -typedef struct stacked_container { - grpc_json_type type; - struct stacked_container* next; -} stacked_container; - -typedef struct json_reader_userdata { - FILE* in; - grpc_json_writer* writer; - char* scratchpad; - char* ptr; - size_t free_space; - size_t allocated; - size_t string_len; - stacked_container* top; -} json_reader_userdata; - -static void json_writer_output_char(void* userdata, char c) { - json_writer_userdata* state = static_cast(userdata); - fputc(c, state->out); -} - -static void json_writer_output_string(void* userdata, const char* str) { - json_writer_userdata* state = static_cast(userdata); - fputs(str, state->out); -} - -static void json_writer_output_string_with_len(void* userdata, const char* str, - size_t len) { - json_writer_userdata* state = static_cast(userdata); - fwrite(str, len, 1, state->out); -} - -grpc_json_writer_vtable writer_vtable = {json_writer_output_char, - json_writer_output_string, - json_writer_output_string_with_len}; - -static void check_string(json_reader_userdata* state, size_t needed) { - if (state->free_space >= needed) return; - needed -= state->free_space; - needed = (needed + 0xffu) & ~0xffu; - state->scratchpad = static_cast( - gpr_realloc(state->scratchpad, state->allocated + needed)); - state->free_space += needed; - state->allocated += needed; -} - -static void json_reader_string_clear(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - state->free_space = state->allocated; - state->string_len = 0; -} - -static void json_reader_string_add_char(void* userdata, uint32_t c) { - json_reader_userdata* state = static_cast(userdata); - check_string(state, 1); - GPR_ASSERT(c < 256); - state->scratchpad[state->string_len++] = static_cast(c); -} - -static void json_reader_string_add_utf32(void* userdata, uint32_t c) { - if (c <= 0x7f) { - json_reader_string_add_char(userdata, c); - } else if (c <= 0x7ff) { - uint32_t b1 = 0xc0u | ((c >> 6u) & 0x1fu); - uint32_t b2 = 0x80u | (c & 0x3fu); - json_reader_string_add_char(userdata, b1); - json_reader_string_add_char(userdata, b2); - } else if (c <= 0xffffu) { - uint32_t b1 = 0xe0u | ((c >> 12u) & 0x0fu); - uint32_t b2 = 0x80u | ((c >> 6u) & 0x3fu); - uint32_t b3 = 0x80u | (c & 0x3fu); - json_reader_string_add_char(userdata, b1); - json_reader_string_add_char(userdata, b2); - json_reader_string_add_char(userdata, b3); - } else if (c <= 0x1fffffu) { - uint32_t b1 = 0xf0u | ((c >> 18u) & 0x07u); - uint32_t b2 = 0x80u | ((c >> 12u) & 0x3fu); - uint32_t b3 = 0x80u | ((c >> 6u) & 0x3fu); - uint32_t b4 = 0x80u | (c & 0x3fu); - json_reader_string_add_char(userdata, b1); - json_reader_string_add_char(userdata, b2); - json_reader_string_add_char(userdata, b3); - json_reader_string_add_char(userdata, b4); - } -} - -static uint32_t json_reader_read_char(void* userdata) { - int r; - json_reader_userdata* state = static_cast(userdata); - - r = fgetc(state->in); - if (r == EOF) r = GRPC_JSON_READ_CHAR_EOF; - return static_cast(r); -} - -static void json_reader_container_begins(void* userdata, grpc_json_type type) { - json_reader_userdata* state = static_cast(userdata); - stacked_container* container = - static_cast(gpr_malloc(sizeof(stacked_container))); - - container->type = type; - container->next = state->top; - state->top = container; - - grpc_json_writer_container_begins(state->writer, type); -} - -static grpc_json_type json_reader_container_ends(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - stacked_container* container = state->top; - - grpc_json_writer_container_ends(state->writer, container->type); - state->top = container->next; - gpr_free(container); - return state->top ? state->top->type : GRPC_JSON_TOP_LEVEL; -} - -static void json_reader_set_key(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - json_reader_string_add_char(userdata, 0); - - grpc_json_writer_object_key(state->writer, state->scratchpad); -} - -static void json_reader_set_string(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - json_reader_string_add_char(userdata, 0); - - grpc_json_writer_value_string(state->writer, state->scratchpad); -} - -static int json_reader_set_number(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - - grpc_json_writer_value_raw_with_len(state->writer, state->scratchpad, - state->string_len); - - return 1; -} - -static void json_reader_set_true(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - - grpc_json_writer_value_raw_with_len(state->writer, "true", 4); -} - -static void json_reader_set_false(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - - grpc_json_writer_value_raw_with_len(state->writer, "false", 5); -} - -static void json_reader_set_null(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - - grpc_json_writer_value_raw_with_len(state->writer, "null", 4); -} - -static grpc_json_reader_vtable reader_vtable = { - json_reader_string_clear, json_reader_string_add_char, - json_reader_string_add_utf32, json_reader_read_char, - json_reader_container_begins, json_reader_container_ends, - json_reader_set_key, json_reader_set_string, - json_reader_set_number, json_reader_set_true, - json_reader_set_false, json_reader_set_null}; - -int rewrite(FILE* in, FILE* out, int indent) { - grpc_json_writer writer; - grpc_json_reader reader; - grpc_json_reader_status status; - json_writer_userdata writer_user; - json_reader_userdata reader_user; - - reader_user.writer = &writer; - reader_user.in = in; - reader_user.top = nullptr; - reader_user.scratchpad = nullptr; - reader_user.string_len = 0; - reader_user.free_space = 0; - reader_user.allocated = 0; - - writer_user.out = out; - - grpc_json_writer_init(&writer, indent, &writer_vtable, &writer_user); - grpc_json_reader_init(&reader, &reader_vtable, &reader_user); - - status = grpc_json_reader_run(&reader); - - free(reader_user.scratchpad); - while (reader_user.top) { - stacked_container* container = reader_user.top; - reader_user.top = container->next; - free(container); - } - - return status == GRPC_JSON_DONE; -} - -int main(int argc, char** argv) { - int indent = 2; - gpr_cmdline* cl; - - cl = gpr_cmdline_create(nullptr); - gpr_cmdline_add_int(cl, "indent", nullptr, &indent); - gpr_cmdline_parse(cl, argc, argv); - gpr_cmdline_destroy(cl); - - return rewrite(stdin, stdout, indent) ? 0 : 1; -} diff --git a/test/core/json/json_rewrite_test.cc b/test/core/json/json_rewrite_test.cc deleted file mode 100644 index b7e89cdb1a3..00000000000 --- a/test/core/json/json_rewrite_test.cc +++ /dev/null @@ -1,294 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -#include -#include -#include "test/core/util/test_config.h" - -#include "src/core/lib/gpr/useful.h" -#include "src/core/lib/json/json_reader.h" -#include "src/core/lib/json/json_writer.h" - -typedef struct json_writer_userdata { - FILE* cmp; -} json_writer_userdata; - -typedef struct stacked_container { - grpc_json_type type; - struct stacked_container* next; -} stacked_container; - -typedef struct json_reader_userdata { - FILE* in; - grpc_json_writer* writer; - char* scratchpad; - char* ptr; - size_t free_space; - size_t allocated; - size_t string_len; - stacked_container* top; - int did_eagain; -} json_reader_userdata; - -static void json_writer_output_char(void* userdata, char c) { - json_writer_userdata* state = static_cast(userdata); - int cmp = fgetc(state->cmp); - - /* treat CRLF as LF */ - if (cmp == '\r' && c == '\n') { - cmp = fgetc(state->cmp); - } - GPR_ASSERT(cmp == c); -} - -static void json_writer_output_string(void* userdata, const char* str) { - while (*str) { - json_writer_output_char(userdata, *str++); - } -} - -static void json_writer_output_string_with_len(void* userdata, const char* str, - size_t len) { - size_t i; - for (i = 0; i < len; i++) { - json_writer_output_char(userdata, str[i]); - } -} - -grpc_json_writer_vtable writer_vtable = {json_writer_output_char, - json_writer_output_string, - json_writer_output_string_with_len}; - -static void check_string(json_reader_userdata* state, size_t needed) { - if (state->free_space >= needed) return; - needed -= state->free_space; - needed = (needed + 0xffu) & ~0xffu; - state->scratchpad = static_cast( - gpr_realloc(state->scratchpad, state->allocated + needed)); - state->free_space += needed; - state->allocated += needed; -} - -static void json_reader_string_clear(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - state->free_space = state->allocated; - state->string_len = 0; -} - -static void json_reader_string_add_char(void* userdata, uint32_t c) { - json_reader_userdata* state = static_cast(userdata); - check_string(state, 1); - GPR_ASSERT(c <= 256); - state->scratchpad[state->string_len++] = static_cast(c); -} - -static void json_reader_string_add_utf32(void* userdata, uint32_t c) { - if (c <= 0x7f) { - json_reader_string_add_char(userdata, c); - } else if (c <= 0x7ffu) { - uint32_t b1 = 0xc0u | ((c >> 6u) & 0x1fu); - uint32_t b2 = 0x80u | (c & 0x3fu); - json_reader_string_add_char(userdata, b1); - json_reader_string_add_char(userdata, b2); - } else if (c <= 0xffffu) { - uint32_t b1 = 0xe0u | ((c >> 12u) & 0x0fu); - uint32_t b2 = 0x80u | ((c >> 6u) & 0x3fu); - uint32_t b3 = 0x80u | (c & 0x3fu); - json_reader_string_add_char(userdata, b1); - json_reader_string_add_char(userdata, b2); - json_reader_string_add_char(userdata, b3); - } else if (c <= 0x1fffffu) { - uint32_t b1 = 0xf0u | ((c >> 18u) & 0x07u); - uint32_t b2 = 0x80u | ((c >> 12u) & 0x3fu); - uint32_t b3 = 0x80u | ((c >> 6u) & 0x3fu); - uint32_t b4 = 0x80u | (c & 0x3fu); - json_reader_string_add_char(userdata, b1); - json_reader_string_add_char(userdata, b2); - json_reader_string_add_char(userdata, b3); - json_reader_string_add_char(userdata, b4); - } -} - -static uint32_t json_reader_read_char(void* userdata) { - int r; - json_reader_userdata* state = static_cast(userdata); - - if (!state->did_eagain) { - state->did_eagain = 1; - return GRPC_JSON_READ_CHAR_EAGAIN; - } - - state->did_eagain = 0; - - r = fgetc(state->in); - if (r == EOF) r = GRPC_JSON_READ_CHAR_EOF; - return static_cast(r); -} - -static void json_reader_container_begins(void* userdata, grpc_json_type type) { - json_reader_userdata* state = static_cast(userdata); - stacked_container* container = - static_cast(gpr_malloc(sizeof(stacked_container))); - - container->type = type; - container->next = state->top; - state->top = container; - - grpc_json_writer_container_begins(state->writer, type); -} - -static grpc_json_type json_reader_container_ends(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - stacked_container* container = state->top; - - grpc_json_writer_container_ends(state->writer, container->type); - state->top = container->next; - gpr_free(container); - return state->top ? state->top->type : GRPC_JSON_TOP_LEVEL; -} - -static void json_reader_set_key(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - json_reader_string_add_char(userdata, 0); - - grpc_json_writer_object_key(state->writer, state->scratchpad); -} - -static void json_reader_set_string(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - json_reader_string_add_char(userdata, 0); - - grpc_json_writer_value_string(state->writer, state->scratchpad); -} - -static int json_reader_set_number(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - - grpc_json_writer_value_raw_with_len(state->writer, state->scratchpad, - state->string_len); - - return 1; -} - -static void json_reader_set_true(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - - grpc_json_writer_value_raw_with_len(state->writer, "true", 4); -} - -static void json_reader_set_false(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - - grpc_json_writer_value_raw_with_len(state->writer, "false", 5); -} - -static void json_reader_set_null(void* userdata) { - json_reader_userdata* state = static_cast(userdata); - - grpc_json_writer_value_raw_with_len(state->writer, "null", 4); -} - -static grpc_json_reader_vtable reader_vtable = { - json_reader_string_clear, json_reader_string_add_char, - json_reader_string_add_utf32, json_reader_read_char, - json_reader_container_begins, json_reader_container_ends, - json_reader_set_key, json_reader_set_string, - json_reader_set_number, json_reader_set_true, - json_reader_set_false, json_reader_set_null}; - -int rewrite_and_compare(FILE* in, FILE* cmp, int indent) { - grpc_json_writer writer; - grpc_json_reader reader; - grpc_json_reader_status status; - json_writer_userdata writer_user; - json_reader_userdata reader_user; - - GPR_ASSERT(in); - GPR_ASSERT(cmp); - - reader_user.writer = &writer; - reader_user.in = in; - reader_user.top = nullptr; - reader_user.scratchpad = nullptr; - reader_user.string_len = 0; - reader_user.free_space = 0; - reader_user.allocated = 0; - reader_user.did_eagain = 0; - - writer_user.cmp = cmp; - - grpc_json_writer_init(&writer, indent, &writer_vtable, &writer_user); - grpc_json_reader_init(&reader, &reader_vtable, &reader_user); - - do { - status = grpc_json_reader_run(&reader); - } while (status == GRPC_JSON_EAGAIN); - - free(reader_user.scratchpad); - while (reader_user.top) { - stacked_container* container = reader_user.top; - reader_user.top = container->next; - free(container); - } - - return status == GRPC_JSON_DONE; -} - -typedef struct test_file { - const char* input; - const char* cmp; - int indent; -} test_file; - -static test_file test_files[] = { - {"test/core/json/rewrite_test_input.json", - "test/core/json/rewrite_test_output_condensed.json", 0}, - {"test/core/json/rewrite_test_input.json", - "test/core/json/rewrite_test_output_indented.json", 2}, - {"test/core/json/rewrite_test_output_indented.json", - "test/core/json/rewrite_test_output_condensed.json", 0}, - {"test/core/json/rewrite_test_output_condensed.json", - "test/core/json/rewrite_test_output_indented.json", 2}, -}; - -void test_rewrites() { - unsigned i; - - for (i = 0; i < GPR_ARRAY_SIZE(test_files); i++) { - test_file* test = test_files + i; - FILE* input = fopen(test->input, "rb"); - FILE* cmp = fopen(test->cmp, "rb"); - int status; - gpr_log(GPR_INFO, "Testing file %s against %s using indent=%i", test->input, - test->cmp, test->indent); - status = rewrite_and_compare(input, cmp, test->indent); - GPR_ASSERT(status); - fclose(input); - fclose(cmp); - } -} - -int main(int argc, char** argv) { - grpc::testing::TestEnvironment env(argc, argv); - test_rewrites(); - gpr_log(GPR_INFO, "json_rewrite_test success"); - return 0; -} diff --git a/test/core/json/json_stream_error_test.cc b/test/core/json/json_stream_error_test.cc deleted file mode 100644 index f31e9c95d86..00000000000 --- a/test/core/json/json_stream_error_test.cc +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -#include -#include -#include "test/core/util/test_config.h" - -#include "src/core/lib/json/json_reader.h" -#include "src/core/lib/json/json_writer.h" - -static int g_string_clear_once = 0; - -static void string_clear(void* /*userdata*/) { - GPR_ASSERT(!g_string_clear_once); - g_string_clear_once = 1; -} - -static uint32_t read_char(void* /*userdata*/) { - return GRPC_JSON_READ_CHAR_ERROR; -} - -static grpc_json_reader_vtable reader_vtable = { - string_clear, nullptr, nullptr, read_char, nullptr, nullptr, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}; - -static void read_error() { - grpc_json_reader reader; - grpc_json_reader_status status; - grpc_json_reader_init(&reader, &reader_vtable, nullptr); - - status = grpc_json_reader_run(&reader); - GPR_ASSERT(status == GRPC_JSON_READ_ERROR); -} - -int main(int argc, char** argv) { - grpc::testing::TestEnvironment env(argc, argv); - read_error(); - gpr_log(GPR_INFO, "json_stream_error success"); - return 0; -} diff --git a/test/core/json/rewrite_test_input.json b/test/core/json/rewrite_test_input.json deleted file mode 100644 index 568891474f7..00000000000 --- a/test/core/json/rewrite_test_input.json +++ /dev/null @@ -1,203 +0,0 @@ -{ -"unicode, escape and empty test": { "a\tb": "\u00eb", "empty": [{},[],{}] }, -"some more unicode tests": { - "typical utf-8 input (plane 0)": "ßâñć⇒", - "atypical utf-8 input (plane 1)": "𝄞" -}, - -"whitespace test": { "trying" : -"to" - , - - "break" - : - "the" , - "parser": "a bit" } , - -"#": "All these examples are from http://json.org/example", -"test1": -{ - "glossary": { - "title": "example glossary", - "GlossDiv": { - "title": "S", - "GlossList": { - "GlossEntry": { - "ID": "SGML", - "SortAs": "SGML", - "GlossTerm": "Standard Generalized Markup Language", - "Acronym": "SGML", - "Abbrev": "ISO 8879:1986", - "GlossDef": { - "para": "A meta-markup language, used to create markup languages such as DocBook.", - "GlossSeeAlso": ["GML", "XML"] - }, - "GlossSee": "markup" - } - } - } - } -}, - -"test2": -{"menu": { - "id": "file", - "value": "File", - "popup": { - "menuitem": [ - {"value": "New", "onclick": "CreateNewDoc()"}, - {"value": "Open", "onclick": "OpenDoc()"}, - {"value": "Close", "onclick": "CloseDoc()"} - ] - } -}}, - -"test3": -{"widget": { - "debug": "on", - "window": { - "title": "Sample Konfabulator Widget", - "name": "main_window", - "width": 500, - "height": 500 - }, - "image": { - "src": "Images/Sun.png", - "name": "sun1", - "hOffset": 250, - "vOffset": 250, - "alignment": "center" - }, - "text": { - "data": "Click Here", - "size": 36, - "style": "bold", - "name": "text1", - "hOffset": 250, - "vOffset": 100, - "alignment": "center", - "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" - } -}}, - -"test4": -{"web-app": { - "servlet": [ - { - "servlet-name": "cofaxCDS", - "servlet-class": "org.cofax.cds.CDSServlet", - "init-param": { - "configGlossary:installationAt": "Philadelphia, PA", - "configGlossary:adminEmail": "ksm@pobox.com", - "configGlossary:poweredBy": "Cofax", - "configGlossary:poweredByIcon": "/images/cofax.gif", - "configGlossary:staticPath": "/content/static", - "templateProcessorClass": "org.cofax.WysiwygTemplate", - "templateLoaderClass": "org.cofax.FilesTemplateLoader", - "templatePath": "templates", - "templateOverridePath": "", - "defaultListTemplate": "listTemplate.htm", - "defaultFileTemplate": "articleTemplate.htm", - "useJSP": false, - "jspListTemplate": "listTemplate.jsp", - "jspFileTemplate": "articleTemplate.jsp", - "cachePackageTagsTrack": 200, - "cachePackageTagsStore": 200, - "cachePackageTagsRefresh": 60, - "cacheTemplatesTrack": 100, - "cacheTemplatesStore": 50, - "cacheTemplatesRefresh": 15, - "cachePagesTrack": 200, - "cachePagesStore": 100, - "cachePagesRefresh": 10, - "cachePagesDirtyRead": 10, - "searchEngineListTemplate": "forSearchEnginesList.htm", - "searchEngineFileTemplate": "forSearchEngines.htm", - "searchEngineRobotsDb": "WEB-INF/robots.db", - "useDataStore": true, - "dataStoreClass": "org.cofax.SqlDataStore", - "redirectionClass": "org.cofax.SqlRedirection", - "dataStoreName": "cofax", - "dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver", - "dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon", - "dataStoreUser": "sa", - "dataStorePassword": "dataStoreTestQuery", - "dataStoreTestQuery": "SET NOCOUNT ON;select test='test';", - "dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log", - "dataStoreInitConns": 10, - "dataStoreMaxConns": 100, - "dataStoreConnUsageLimit": 100, - "dataStoreLogLevel": "debug", - "maxUrlLength": 500}}, - { - "servlet-name": "cofaxEmail", - "servlet-class": "org.cofax.cds.EmailServlet", - "init-param": { - "mailHost": "mail1", - "mailHostOverride": "mail2"}}, - { - "servlet-name": "cofaxAdmin", - "servlet-class": "org.cofax.cds.AdminServlet"}, - - { - "servlet-name": "fileServlet", - "servlet-class": "org.cofax.cds.FileServlet"}, - { - "servlet-name": "cofaxTools", - "servlet-class": "org.cofax.cms.CofaxToolsServlet", - "init-param": { - "templatePath": "toolstemplates/", - "log": 1, - "logLocation": "/usr/local/tomcat/logs/CofaxTools.log", - "logMaxSize": "", - "dataLog": 1, - "dataLogLocation": "/usr/local/tomcat/logs/dataLog.log", - "dataLogMaxSize": "", - "removePageCache": "/content/admin/remove?cache=pages&id=", - "removeTemplateCache": "/content/admin/remove?cache=templates&id=", - "fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder", - "lookInContext": 1, - "adminGroupID": 4, - "betaServer": true}}], - "servlet-mapping": { - "cofaxCDS": "/", - "cofaxEmail": "/cofaxutil/aemail/*", - "cofaxAdmin": "/admin/*", - "fileServlet": "/static/*", - "cofaxTools": "/tools/*"}, - - "taglib": { - "taglib-uri": "cofax.tld", - "taglib-location": "/WEB-INF/tlds/cofax.tld"}}}, - -"test5": -{"menu": { - "header": "SVG Viewer", - "items": [ - {"id": "Open"}, - {"id": "OpenNew", "label": "Open New"}, - null, - {"id": "ZoomIn", "label": "Zoom In"}, - {"id": "ZoomOut", "label": "Zoom Out"}, - {"id": "OriginalView", "label": "Original View"}, - null, - {"id": "Quality"}, - {"id": "Pause"}, - {"id": "Mute"}, - null, - {"id": "Find", "label": "Find..."}, - {"id": "FindAgain", "label": "Find Again"}, - {"id": "Copy"}, - {"id": "CopyAgain", "label": "Copy Again"}, - {"id": "CopySVG", "label": "Copy SVG"}, - {"id": "ViewSVG", "label": "View SVG"}, - {"id": "ViewSource", "label": "View Source"}, - {"id": "SaveAs", "label": "Save As"}, - null, - {"id": "Help"}, - {"id": "About", "label": "About Adobe CVG Viewer..."} - ] -}} - - -} diff --git a/test/core/json/rewrite_test_output_condensed.json b/test/core/json/rewrite_test_output_condensed.json deleted file mode 100644 index 3adbbd99d66..00000000000 --- a/test/core/json/rewrite_test_output_condensed.json +++ /dev/null @@ -1 +0,0 @@ -{"unicode, escape and empty test":{"a\tb":"\u00eb","empty":[{},[],{}]},"some more unicode tests":{"typical utf-8 input (plane 0)":"\u00df\u00e2\u00f1\u0107\u21d2","atypical utf-8 input (plane 1)":"\ud834\udd1e"},"whitespace test":{"trying":"to","break":"the","parser":"a bit"},"#":"All these examples are from http://json.org/example","test1":{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}},"test2":{"menu":{"id":"file","value":"File","popup":{"menuitem":[{"value":"New","onclick":"CreateNewDoc()"},{"value":"Open","onclick":"OpenDoc()"},{"value":"Close","onclick":"CloseDoc()"}]}}},"test3":{"widget":{"debug":"on","window":{"title":"Sample Konfabulator Widget","name":"main_window","width":500,"height":500},"image":{"src":"Images/Sun.png","name":"sun1","hOffset":250,"vOffset":250,"alignment":"center"},"text":{"data":"Click Here","size":36,"style":"bold","name":"text1","hOffset":250,"vOffset":100,"alignment":"center","onMouseUp":"sun1.opacity = (sun1.opacity / 100) * 90;"}}},"test4":{"web-app":{"servlet":[{"servlet-name":"cofaxCDS","servlet-class":"org.cofax.cds.CDSServlet","init-param":{"configGlossary:installationAt":"Philadelphia, PA","configGlossary:adminEmail":"ksm@pobox.com","configGlossary:poweredBy":"Cofax","configGlossary:poweredByIcon":"/images/cofax.gif","configGlossary:staticPath":"/content/static","templateProcessorClass":"org.cofax.WysiwygTemplate","templateLoaderClass":"org.cofax.FilesTemplateLoader","templatePath":"templates","templateOverridePath":"","defaultListTemplate":"listTemplate.htm","defaultFileTemplate":"articleTemplate.htm","useJSP":false,"jspListTemplate":"listTemplate.jsp","jspFileTemplate":"articleTemplate.jsp","cachePackageTagsTrack":200,"cachePackageTagsStore":200,"cachePackageTagsRefresh":60,"cacheTemplatesTrack":100,"cacheTemplatesStore":50,"cacheTemplatesRefresh":15,"cachePagesTrack":200,"cachePagesStore":100,"cachePagesRefresh":10,"cachePagesDirtyRead":10,"searchEngineListTemplate":"forSearchEnginesList.htm","searchEngineFileTemplate":"forSearchEngines.htm","searchEngineRobotsDb":"WEB-INF/robots.db","useDataStore":true,"dataStoreClass":"org.cofax.SqlDataStore","redirectionClass":"org.cofax.SqlRedirection","dataStoreName":"cofax","dataStoreDriver":"com.microsoft.jdbc.sqlserver.SQLServerDriver","dataStoreUrl":"jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon","dataStoreUser":"sa","dataStorePassword":"dataStoreTestQuery","dataStoreTestQuery":"SET NOCOUNT ON;select test='test';","dataStoreLogFile":"/usr/local/tomcat/logs/datastore.log","dataStoreInitConns":10,"dataStoreMaxConns":100,"dataStoreConnUsageLimit":100,"dataStoreLogLevel":"debug","maxUrlLength":500}},{"servlet-name":"cofaxEmail","servlet-class":"org.cofax.cds.EmailServlet","init-param":{"mailHost":"mail1","mailHostOverride":"mail2"}},{"servlet-name":"cofaxAdmin","servlet-class":"org.cofax.cds.AdminServlet"},{"servlet-name":"fileServlet","servlet-class":"org.cofax.cds.FileServlet"},{"servlet-name":"cofaxTools","servlet-class":"org.cofax.cms.CofaxToolsServlet","init-param":{"templatePath":"toolstemplates/","log":1,"logLocation":"/usr/local/tomcat/logs/CofaxTools.log","logMaxSize":"","dataLog":1,"dataLogLocation":"/usr/local/tomcat/logs/dataLog.log","dataLogMaxSize":"","removePageCache":"/content/admin/remove?cache=pages&id=","removeTemplateCache":"/content/admin/remove?cache=templates&id=","fileTransferFolder":"/usr/local/tomcat/webapps/content/fileTransferFolder","lookInContext":1,"adminGroupID":4,"betaServer":true}}],"servlet-mapping":{"cofaxCDS":"/","cofaxEmail":"/cofaxutil/aemail/*","cofaxAdmin":"/admin/*","fileServlet":"/static/*","cofaxTools":"/tools/*"},"taglib":{"taglib-uri":"cofax.tld","taglib-location":"/WEB-INF/tlds/cofax.tld"}}},"test5":{"menu":{"header":"SVG Viewer","items":[{"id":"Open"},{"id":"OpenNew","label":"Open New"},null,{"id":"ZoomIn","label":"Zoom In"},{"id":"ZoomOut","label":"Zoom Out"},{"id":"OriginalView","label":"Original View"},null,{"id":"Quality"},{"id":"Pause"},{"id":"Mute"},null,{"id":"Find","label":"Find..."},{"id":"FindAgain","label":"Find Again"},{"id":"Copy"},{"id":"CopyAgain","label":"Copy Again"},{"id":"CopySVG","label":"Copy SVG"},{"id":"ViewSVG","label":"View SVG"},{"id":"ViewSource","label":"View Source"},{"id":"SaveAs","label":"Save As"},null,{"id":"Help"},{"id":"About","label":"About Adobe CVG Viewer..."}]}}} \ No newline at end of file diff --git a/test/core/json/rewrite_test_output_indented.json b/test/core/json/rewrite_test_output_indented.json deleted file mode 100644 index 7ac9f49f229..00000000000 --- a/test/core/json/rewrite_test_output_indented.json +++ /dev/null @@ -1,272 +0,0 @@ -{ - "unicode, escape and empty test": { - "a\tb": "\u00eb", - "empty": [ - {}, - [], - {} - ] - }, - "some more unicode tests": { - "typical utf-8 input (plane 0)": "\u00df\u00e2\u00f1\u0107\u21d2", - "atypical utf-8 input (plane 1)": "\ud834\udd1e" - }, - "whitespace test": { - "trying": "to", - "break": "the", - "parser": "a bit" - }, - "#": "All these examples are from http://json.org/example", - "test1": { - "glossary": { - "title": "example glossary", - "GlossDiv": { - "title": "S", - "GlossList": { - "GlossEntry": { - "ID": "SGML", - "SortAs": "SGML", - "GlossTerm": "Standard Generalized Markup Language", - "Acronym": "SGML", - "Abbrev": "ISO 8879:1986", - "GlossDef": { - "para": "A meta-markup language, used to create markup languages such as DocBook.", - "GlossSeeAlso": [ - "GML", - "XML" - ] - }, - "GlossSee": "markup" - } - } - } - } - }, - "test2": { - "menu": { - "id": "file", - "value": "File", - "popup": { - "menuitem": [ - { - "value": "New", - "onclick": "CreateNewDoc()" - }, - { - "value": "Open", - "onclick": "OpenDoc()" - }, - { - "value": "Close", - "onclick": "CloseDoc()" - } - ] - } - } - }, - "test3": { - "widget": { - "debug": "on", - "window": { - "title": "Sample Konfabulator Widget", - "name": "main_window", - "width": 500, - "height": 500 - }, - "image": { - "src": "Images/Sun.png", - "name": "sun1", - "hOffset": 250, - "vOffset": 250, - "alignment": "center" - }, - "text": { - "data": "Click Here", - "size": 36, - "style": "bold", - "name": "text1", - "hOffset": 250, - "vOffset": 100, - "alignment": "center", - "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" - } - } - }, - "test4": { - "web-app": { - "servlet": [ - { - "servlet-name": "cofaxCDS", - "servlet-class": "org.cofax.cds.CDSServlet", - "init-param": { - "configGlossary:installationAt": "Philadelphia, PA", - "configGlossary:adminEmail": "ksm@pobox.com", - "configGlossary:poweredBy": "Cofax", - "configGlossary:poweredByIcon": "/images/cofax.gif", - "configGlossary:staticPath": "/content/static", - "templateProcessorClass": "org.cofax.WysiwygTemplate", - "templateLoaderClass": "org.cofax.FilesTemplateLoader", - "templatePath": "templates", - "templateOverridePath": "", - "defaultListTemplate": "listTemplate.htm", - "defaultFileTemplate": "articleTemplate.htm", - "useJSP": false, - "jspListTemplate": "listTemplate.jsp", - "jspFileTemplate": "articleTemplate.jsp", - "cachePackageTagsTrack": 200, - "cachePackageTagsStore": 200, - "cachePackageTagsRefresh": 60, - "cacheTemplatesTrack": 100, - "cacheTemplatesStore": 50, - "cacheTemplatesRefresh": 15, - "cachePagesTrack": 200, - "cachePagesStore": 100, - "cachePagesRefresh": 10, - "cachePagesDirtyRead": 10, - "searchEngineListTemplate": "forSearchEnginesList.htm", - "searchEngineFileTemplate": "forSearchEngines.htm", - "searchEngineRobotsDb": "WEB-INF/robots.db", - "useDataStore": true, - "dataStoreClass": "org.cofax.SqlDataStore", - "redirectionClass": "org.cofax.SqlRedirection", - "dataStoreName": "cofax", - "dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver", - "dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon", - "dataStoreUser": "sa", - "dataStorePassword": "dataStoreTestQuery", - "dataStoreTestQuery": "SET NOCOUNT ON;select test='test';", - "dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log", - "dataStoreInitConns": 10, - "dataStoreMaxConns": 100, - "dataStoreConnUsageLimit": 100, - "dataStoreLogLevel": "debug", - "maxUrlLength": 500 - } - }, - { - "servlet-name": "cofaxEmail", - "servlet-class": "org.cofax.cds.EmailServlet", - "init-param": { - "mailHost": "mail1", - "mailHostOverride": "mail2" - } - }, - { - "servlet-name": "cofaxAdmin", - "servlet-class": "org.cofax.cds.AdminServlet" - }, - { - "servlet-name": "fileServlet", - "servlet-class": "org.cofax.cds.FileServlet" - }, - { - "servlet-name": "cofaxTools", - "servlet-class": "org.cofax.cms.CofaxToolsServlet", - "init-param": { - "templatePath": "toolstemplates/", - "log": 1, - "logLocation": "/usr/local/tomcat/logs/CofaxTools.log", - "logMaxSize": "", - "dataLog": 1, - "dataLogLocation": "/usr/local/tomcat/logs/dataLog.log", - "dataLogMaxSize": "", - "removePageCache": "/content/admin/remove?cache=pages&id=", - "removeTemplateCache": "/content/admin/remove?cache=templates&id=", - "fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder", - "lookInContext": 1, - "adminGroupID": 4, - "betaServer": true - } - } - ], - "servlet-mapping": { - "cofaxCDS": "/", - "cofaxEmail": "/cofaxutil/aemail/*", - "cofaxAdmin": "/admin/*", - "fileServlet": "/static/*", - "cofaxTools": "/tools/*" - }, - "taglib": { - "taglib-uri": "cofax.tld", - "taglib-location": "/WEB-INF/tlds/cofax.tld" - } - } - }, - "test5": { - "menu": { - "header": "SVG Viewer", - "items": [ - { - "id": "Open" - }, - { - "id": "OpenNew", - "label": "Open New" - }, - null, - { - "id": "ZoomIn", - "label": "Zoom In" - }, - { - "id": "ZoomOut", - "label": "Zoom Out" - }, - { - "id": "OriginalView", - "label": "Original View" - }, - null, - { - "id": "Quality" - }, - { - "id": "Pause" - }, - { - "id": "Mute" - }, - null, - { - "id": "Find", - "label": "Find..." - }, - { - "id": "FindAgain", - "label": "Find Again" - }, - { - "id": "Copy" - }, - { - "id": "CopyAgain", - "label": "Copy Again" - }, - { - "id": "CopySVG", - "label": "Copy SVG" - }, - { - "id": "ViewSVG", - "label": "View SVG" - }, - { - "id": "ViewSource", - "label": "View Source" - }, - { - "id": "SaveAs", - "label": "Save As" - }, - null, - { - "id": "Help" - }, - { - "id": "About", - "label": "About Adobe CVG Viewer..." - } - ] - } - } -} \ No newline at end of file diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index c0c92d91480..914f5714943 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1400,12 +1400,8 @@ src/core/lib/iomgr/wakeup_fd_posix.cc \ src/core/lib/iomgr/wakeup_fd_posix.h \ src/core/lib/json/json.cc \ src/core/lib/json/json.h \ -src/core/lib/json/json_common.h \ src/core/lib/json/json_reader.cc \ -src/core/lib/json/json_reader.h \ -src/core/lib/json/json_string.cc \ src/core/lib/json/json_writer.cc \ -src/core/lib/json/json_writer.h \ src/core/lib/profiling/timers.h \ src/core/lib/slice/b64.cc \ src/core/lib/slice/b64.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 202ff52630b..82538fe6883 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1441,12 +1441,8 @@ src/core/lib/iomgr/wakeup_fd_posix.cc \ src/core/lib/iomgr/wakeup_fd_posix.h \ src/core/lib/json/json.cc \ src/core/lib/json/json.h \ -src/core/lib/json/json_common.h \ src/core/lib/json/json_reader.cc \ -src/core/lib/json/json_reader.h \ -src/core/lib/json/json_string.cc \ src/core/lib/json/json_writer.cc \ -src/core/lib/json/json_writer.h \ src/core/lib/profiling/basic_timers.cc \ src/core/lib/profiling/stap_timers.cc \ src/core/lib/profiling/timers.h \ diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index ccb6102ba2a..8c4283846b1 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -1797,54 +1797,6 @@ ], "uses_polling": true }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c", - "name": "json_rewrite_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": false - }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c", - "name": "json_stream_error_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": false - }, { "args": [], "benchmark": false,