Revert "Revert "Introduce string_view and use it for gpr_split_host_port.""
This reverts commit 80c177d4c4.
This commit is contained in:
parent
3a33fccb3a
commit
dbf88dd66f
8
BUILD
8
BUILD
|
|
@ -559,7 +559,6 @@ grpc_cc_library(
|
|||
"src/core/lib/gpr/env_linux.cc",
|
||||
"src/core/lib/gpr/env_posix.cc",
|
||||
"src/core/lib/gpr/env_windows.cc",
|
||||
"src/core/lib/gpr/host_port.cc",
|
||||
"src/core/lib/gpr/log.cc",
|
||||
"src/core/lib/gpr/log_android.cc",
|
||||
"src/core/lib/gpr/log_linux.cc",
|
||||
|
|
@ -586,6 +585,7 @@ grpc_cc_library(
|
|||
"src/core/lib/gprpp/arena.cc",
|
||||
"src/core/lib/gprpp/fork.cc",
|
||||
"src/core/lib/gprpp/global_config_env.cc",
|
||||
"src/core/lib/gprpp/host_port.cc",
|
||||
"src/core/lib/gprpp/thd_posix.cc",
|
||||
"src/core/lib/gprpp/thd_windows.cc",
|
||||
"src/core/lib/profiling/basic_timers.cc",
|
||||
|
|
@ -595,7 +595,6 @@ grpc_cc_library(
|
|||
"src/core/lib/gpr/alloc.h",
|
||||
"src/core/lib/gpr/arena.h",
|
||||
"src/core/lib/gpr/env.h",
|
||||
"src/core/lib/gpr/host_port.h",
|
||||
"src/core/lib/gpr/mpscq.h",
|
||||
"src/core/lib/gpr/murmur_hash.h",
|
||||
"src/core/lib/gpr/spinlock.h",
|
||||
|
|
@ -612,14 +611,16 @@ grpc_cc_library(
|
|||
"src/core/lib/gprpp/arena.h",
|
||||
"src/core/lib/gprpp/atomic.h",
|
||||
"src/core/lib/gprpp/fork.h",
|
||||
"src/core/lib/gprpp/global_config.h",
|
||||
"src/core/lib/gprpp/global_config_custom.h",
|
||||
"src/core/lib/gprpp/global_config_env.h",
|
||||
"src/core/lib/gprpp/global_config_generic.h",
|
||||
"src/core/lib/gprpp/global_config.h",
|
||||
"src/core/lib/gprpp/host_port.h",
|
||||
"src/core/lib/gprpp/manual_constructor.h",
|
||||
"src/core/lib/gprpp/map.h",
|
||||
"src/core/lib/gprpp/memory.h",
|
||||
"src/core/lib/gprpp/pair.h",
|
||||
"src/core/lib/gprpp/string_view.h",
|
||||
"src/core/lib/gprpp/sync.h",
|
||||
"src/core/lib/gprpp/thd.h",
|
||||
"src/core/lib/profiling/timers.h",
|
||||
|
|
@ -628,6 +629,7 @@ grpc_cc_library(
|
|||
public_hdrs = GPR_PUBLIC_HDRS,
|
||||
deps = [
|
||||
"gpr_codegen",
|
||||
"grpc_codegen",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
|
|||
8
BUILD.gn
8
BUILD.gn
|
|
@ -141,8 +141,6 @@ config("grpc_config") {
|
|||
"src/core/lib/gpr/env_linux.cc",
|
||||
"src/core/lib/gpr/env_posix.cc",
|
||||
"src/core/lib/gpr/env_windows.cc",
|
||||
"src/core/lib/gpr/host_port.cc",
|
||||
"src/core/lib/gpr/host_port.h",
|
||||
"src/core/lib/gpr/log.cc",
|
||||
"src/core/lib/gpr/log_android.cc",
|
||||
"src/core/lib/gpr/log_linux.cc",
|
||||
|
|
@ -189,6 +187,8 @@ config("grpc_config") {
|
|||
"src/core/lib/gprpp/global_config_env.cc",
|
||||
"src/core/lib/gprpp/global_config_env.h",
|
||||
"src/core/lib/gprpp/global_config_generic.h",
|
||||
"src/core/lib/gprpp/host_port.cc",
|
||||
"src/core/lib/gprpp/host_port.h",
|
||||
"src/core/lib/gprpp/manual_constructor.h",
|
||||
"src/core/lib/gprpp/map.h",
|
||||
"src/core/lib/gprpp/memory.h",
|
||||
|
|
@ -480,6 +480,7 @@ config("grpc_config") {
|
|||
"src/core/lib/gprpp/orphanable.h",
|
||||
"src/core/lib/gprpp/ref_counted.h",
|
||||
"src/core/lib/gprpp/ref_counted_ptr.h",
|
||||
"src/core/lib/gprpp/string_view.h",
|
||||
"src/core/lib/http/format_request.cc",
|
||||
"src/core/lib/http/format_request.h",
|
||||
"src/core/lib/http/httpcli.cc",
|
||||
|
|
@ -1172,7 +1173,6 @@ config("grpc_config") {
|
|||
"src/core/lib/gpr/alloc.h",
|
||||
"src/core/lib/gpr/arena.h",
|
||||
"src/core/lib/gpr/env.h",
|
||||
"src/core/lib/gpr/host_port.h",
|
||||
"src/core/lib/gpr/mpscq.h",
|
||||
"src/core/lib/gpr/murmur_hash.h",
|
||||
"src/core/lib/gpr/spinlock.h",
|
||||
|
|
@ -1194,6 +1194,7 @@ config("grpc_config") {
|
|||
"src/core/lib/gprpp/global_config_custom.h",
|
||||
"src/core/lib/gprpp/global_config_env.h",
|
||||
"src/core/lib/gprpp/global_config_generic.h",
|
||||
"src/core/lib/gprpp/host_port.h",
|
||||
"src/core/lib/gprpp/inlined_vector.h",
|
||||
"src/core/lib/gprpp/manual_constructor.h",
|
||||
"src/core/lib/gprpp/map.h",
|
||||
|
|
@ -1203,6 +1204,7 @@ config("grpc_config") {
|
|||
"src/core/lib/gprpp/pair.h",
|
||||
"src/core/lib/gprpp/ref_counted.h",
|
||||
"src/core/lib/gprpp/ref_counted_ptr.h",
|
||||
"src/core/lib/gprpp/string_view.h",
|
||||
"src/core/lib/gprpp/sync.h",
|
||||
"src/core/lib/gprpp/thd.h",
|
||||
"src/core/lib/http/format_request.h",
|
||||
|
|
|
|||
|
|
@ -713,6 +713,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
|
|||
add_dependencies(buildtests_cxx streaming_throughput_test)
|
||||
endif()
|
||||
add_dependencies(buildtests_cxx stress_test)
|
||||
add_dependencies(buildtests_cxx string_view_test)
|
||||
add_dependencies(buildtests_cxx thread_manager_test)
|
||||
add_dependencies(buildtests_cxx thread_stress_test)
|
||||
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
|
||||
|
|
@ -861,7 +862,6 @@ add_library(gpr
|
|||
src/core/lib/gpr/env_linux.cc
|
||||
src/core/lib/gpr/env_posix.cc
|
||||
src/core/lib/gpr/env_windows.cc
|
||||
src/core/lib/gpr/host_port.cc
|
||||
src/core/lib/gpr/log.cc
|
||||
src/core/lib/gpr/log_android.cc
|
||||
src/core/lib/gpr/log_linux.cc
|
||||
|
|
@ -888,6 +888,7 @@ add_library(gpr
|
|||
src/core/lib/gprpp/arena.cc
|
||||
src/core/lib/gprpp/fork.cc
|
||||
src/core/lib/gprpp/global_config_env.cc
|
||||
src/core/lib/gprpp/host_port.cc
|
||||
src/core/lib/gprpp/thd_posix.cc
|
||||
src/core/lib/gprpp/thd_windows.cc
|
||||
src/core/lib/profiling/basic_timers.cc
|
||||
|
|
@ -7509,7 +7510,7 @@ endif (gRPC_BUILD_TESTS)
|
|||
if (gRPC_BUILD_TESTS)
|
||||
|
||||
add_executable(gpr_host_port_test
|
||||
test/core/gpr/host_port_test.cc
|
||||
test/core/gprpp/host_port_test.cc
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -16642,6 +16643,45 @@ target_link_libraries(stress_test
|
|||
)
|
||||
|
||||
|
||||
endif (gRPC_BUILD_TESTS)
|
||||
if (gRPC_BUILD_TESTS)
|
||||
|
||||
add_executable(string_view_test
|
||||
test/core/gprpp/string_view_test.cc
|
||||
third_party/googletest/googletest/src/gtest-all.cc
|
||||
third_party/googletest/googlemock/src/gmock-all.cc
|
||||
)
|
||||
|
||||
|
||||
target_include_directories(string_view_test
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
PRIVATE ${_gRPC_SSL_INCLUDE_DIR}
|
||||
PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR}
|
||||
PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR}
|
||||
PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR}
|
||||
PRIVATE ${_gRPC_CARES_INCLUDE_DIR}
|
||||
PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR}
|
||||
PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
|
||||
PRIVATE ${_gRPC_NANOPB_INCLUDE_DIR}
|
||||
PRIVATE third_party/googletest/googletest/include
|
||||
PRIVATE third_party/googletest/googletest
|
||||
PRIVATE third_party/googletest/googlemock/include
|
||||
PRIVATE third_party/googletest/googlemock
|
||||
PRIVATE ${_gRPC_PROTO_GENS_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(string_view_test
|
||||
${_gRPC_PROTOBUF_LIBRARIES}
|
||||
${_gRPC_ALLTARGETS_LIBRARIES}
|
||||
grpc_test_util
|
||||
grpc++
|
||||
grpc
|
||||
gpr
|
||||
${_gRPC_GFLAGS_LIBRARIES}
|
||||
)
|
||||
|
||||
|
||||
endif (gRPC_BUILD_TESTS)
|
||||
if (gRPC_BUILD_TESTS)
|
||||
|
||||
|
|
|
|||
54
Makefile
54
Makefile
|
|
@ -1278,6 +1278,7 @@ status_metadata_test: $(BINDIR)/$(CONFIG)/status_metadata_test
|
|||
status_util_test: $(BINDIR)/$(CONFIG)/status_util_test
|
||||
streaming_throughput_test: $(BINDIR)/$(CONFIG)/streaming_throughput_test
|
||||
stress_test: $(BINDIR)/$(CONFIG)/stress_test
|
||||
string_view_test: $(BINDIR)/$(CONFIG)/string_view_test
|
||||
thread_manager_test: $(BINDIR)/$(CONFIG)/thread_manager_test
|
||||
thread_stress_test: $(BINDIR)/$(CONFIG)/thread_stress_test
|
||||
time_change_test: $(BINDIR)/$(CONFIG)/time_change_test
|
||||
|
|
@ -1744,6 +1745,7 @@ buildtests_cxx: privatelibs_cxx \
|
|||
$(BINDIR)/$(CONFIG)/status_util_test \
|
||||
$(BINDIR)/$(CONFIG)/streaming_throughput_test \
|
||||
$(BINDIR)/$(CONFIG)/stress_test \
|
||||
$(BINDIR)/$(CONFIG)/string_view_test \
|
||||
$(BINDIR)/$(CONFIG)/thread_manager_test \
|
||||
$(BINDIR)/$(CONFIG)/thread_stress_test \
|
||||
$(BINDIR)/$(CONFIG)/time_change_test \
|
||||
|
|
@ -1907,6 +1909,7 @@ buildtests_cxx: privatelibs_cxx \
|
|||
$(BINDIR)/$(CONFIG)/status_util_test \
|
||||
$(BINDIR)/$(CONFIG)/streaming_throughput_test \
|
||||
$(BINDIR)/$(CONFIG)/stress_test \
|
||||
$(BINDIR)/$(CONFIG)/string_view_test \
|
||||
$(BINDIR)/$(CONFIG)/thread_manager_test \
|
||||
$(BINDIR)/$(CONFIG)/thread_stress_test \
|
||||
$(BINDIR)/$(CONFIG)/time_change_test \
|
||||
|
|
@ -2433,6 +2436,8 @@ test_cxx: buildtests_cxx
|
|||
$(Q) $(BINDIR)/$(CONFIG)/status_util_test || ( echo test status_util_test failed ; exit 1 )
|
||||
$(E) "[RUN] Testing streaming_throughput_test"
|
||||
$(Q) $(BINDIR)/$(CONFIG)/streaming_throughput_test || ( echo test streaming_throughput_test failed ; exit 1 )
|
||||
$(E) "[RUN] Testing string_view_test"
|
||||
$(Q) $(BINDIR)/$(CONFIG)/string_view_test || ( echo test string_view_test failed ; exit 1 )
|
||||
$(E) "[RUN] Testing thread_manager_test"
|
||||
$(Q) $(BINDIR)/$(CONFIG)/thread_manager_test || ( echo test thread_manager_test failed ; exit 1 )
|
||||
$(E) "[RUN] Testing thread_stress_test"
|
||||
|
|
@ -3379,7 +3384,6 @@ LIBGPR_SRC = \
|
|||
src/core/lib/gpr/env_linux.cc \
|
||||
src/core/lib/gpr/env_posix.cc \
|
||||
src/core/lib/gpr/env_windows.cc \
|
||||
src/core/lib/gpr/host_port.cc \
|
||||
src/core/lib/gpr/log.cc \
|
||||
src/core/lib/gpr/log_android.cc \
|
||||
src/core/lib/gpr/log_linux.cc \
|
||||
|
|
@ -3406,6 +3410,7 @@ LIBGPR_SRC = \
|
|||
src/core/lib/gprpp/arena.cc \
|
||||
src/core/lib/gprpp/fork.cc \
|
||||
src/core/lib/gprpp/global_config_env.cc \
|
||||
src/core/lib/gprpp/host_port.cc \
|
||||
src/core/lib/gprpp/thd_posix.cc \
|
||||
src/core/lib/gprpp/thd_windows.cc \
|
||||
src/core/lib/profiling/basic_timers.cc \
|
||||
|
|
@ -10221,7 +10226,7 @@ endif
|
|||
|
||||
|
||||
GPR_HOST_PORT_TEST_SRC = \
|
||||
test/core/gpr/host_port_test.cc \
|
||||
test/core/gprpp/host_port_test.cc \
|
||||
|
||||
GPR_HOST_PORT_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GPR_HOST_PORT_TEST_SRC))))
|
||||
ifeq ($(NO_SECURE),true)
|
||||
|
|
@ -10241,7 +10246,7 @@ $(BINDIR)/$(CONFIG)/gpr_host_port_test: $(GPR_HOST_PORT_TEST_OBJS) $(LIBDIR)/$(C
|
|||
|
||||
endif
|
||||
|
||||
$(OBJDIR)/$(CONFIG)/test/core/gpr/host_port_test.o: $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a
|
||||
$(OBJDIR)/$(CONFIG)/test/core/gprpp/host_port_test.o: $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a
|
||||
|
||||
deps_gpr_host_port_test: $(GPR_HOST_PORT_TEST_OBJS:.o=.dep)
|
||||
|
||||
|
|
@ -19669,6 +19674,49 @@ $(OBJDIR)/$(CONFIG)/test/cpp/interop/stress_test.o: $(GENDIR)/src/proto/grpc/tes
|
|||
$(OBJDIR)/$(CONFIG)/test/cpp/util/metrics_server.o: $(GENDIR)/src/proto/grpc/testing/empty.pb.cc $(GENDIR)/src/proto/grpc/testing/empty.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/test.pb.cc $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc
|
||||
|
||||
|
||||
STRING_VIEW_TEST_SRC = \
|
||||
test/core/gprpp/string_view_test.cc \
|
||||
|
||||
STRING_VIEW_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(STRING_VIEW_TEST_SRC))))
|
||||
ifeq ($(NO_SECURE),true)
|
||||
|
||||
# You can't build secure targets if you don't have OpenSSL.
|
||||
|
||||
$(BINDIR)/$(CONFIG)/string_view_test: openssl_dep_error
|
||||
|
||||
else
|
||||
|
||||
|
||||
|
||||
|
||||
ifeq ($(NO_PROTOBUF),true)
|
||||
|
||||
# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.5.0+.
|
||||
|
||||
$(BINDIR)/$(CONFIG)/string_view_test: protobuf_dep_error
|
||||
|
||||
else
|
||||
|
||||
$(BINDIR)/$(CONFIG)/string_view_test: $(PROTOBUF_DEP) $(STRING_VIEW_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
|
||||
$(E) "[LD] Linking $@"
|
||||
$(Q) mkdir -p `dirname $@`
|
||||
$(Q) $(LDXX) $(LDFLAGS) $(STRING_VIEW_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/string_view_test
|
||||
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
$(OBJDIR)/$(CONFIG)/test/core/gprpp/string_view_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
|
||||
|
||||
deps_string_view_test: $(STRING_VIEW_TEST_OBJS:.o=.dep)
|
||||
|
||||
ifneq ($(NO_SECURE),true)
|
||||
ifneq ($(NO_DEPS),true)
|
||||
-include $(STRING_VIEW_TEST_OBJS:.o=.dep)
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
THREAD_MANAGER_TEST_SRC = \
|
||||
test/cpp/thread_manager/thread_manager_test.cc \
|
||||
|
||||
|
|
|
|||
20
build.yaml
20
build.yaml
|
|
@ -122,7 +122,6 @@ filegroups:
|
|||
- src/core/lib/gpr/env_linux.cc
|
||||
- src/core/lib/gpr/env_posix.cc
|
||||
- src/core/lib/gpr/env_windows.cc
|
||||
- src/core/lib/gpr/host_port.cc
|
||||
- src/core/lib/gpr/log.cc
|
||||
- src/core/lib/gpr/log_android.cc
|
||||
- src/core/lib/gpr/log_linux.cc
|
||||
|
|
@ -149,6 +148,7 @@ filegroups:
|
|||
- src/core/lib/gprpp/arena.cc
|
||||
- src/core/lib/gprpp/fork.cc
|
||||
- src/core/lib/gprpp/global_config_env.cc
|
||||
- src/core/lib/gprpp/host_port.cc
|
||||
- src/core/lib/gprpp/thd_posix.cc
|
||||
- src/core/lib/gprpp/thd_windows.cc
|
||||
- src/core/lib/profiling/basic_timers.cc
|
||||
|
|
@ -178,7 +178,6 @@ filegroups:
|
|||
- src/core/lib/gpr/alloc.h
|
||||
- src/core/lib/gpr/arena.h
|
||||
- src/core/lib/gpr/env.h
|
||||
- src/core/lib/gpr/host_port.h
|
||||
- src/core/lib/gpr/mpscq.h
|
||||
- src/core/lib/gpr/murmur_hash.h
|
||||
- src/core/lib/gpr/spinlock.h
|
||||
|
|
@ -199,6 +198,7 @@ filegroups:
|
|||
- src/core/lib/gprpp/global_config_custom.h
|
||||
- src/core/lib/gprpp/global_config_env.h
|
||||
- src/core/lib/gprpp/global_config_generic.h
|
||||
- src/core/lib/gprpp/host_port.h
|
||||
- src/core/lib/gprpp/manual_constructor.h
|
||||
- src/core/lib/gprpp/map.h
|
||||
- src/core/lib/gprpp/memory.h
|
||||
|
|
@ -444,6 +444,7 @@ filegroups:
|
|||
- src/core/lib/gprpp/orphanable.h
|
||||
- src/core/lib/gprpp/ref_counted.h
|
||||
- src/core/lib/gprpp/ref_counted_ptr.h
|
||||
- src/core/lib/gprpp/string_view.h
|
||||
- src/core/lib/http/format_request.h
|
||||
- src/core/lib/http/httpcli.h
|
||||
- src/core/lib/http/parser.h
|
||||
|
|
@ -2626,7 +2627,7 @@ targets:
|
|||
build: test
|
||||
language: c
|
||||
src:
|
||||
- test/core/gpr/host_port_test.cc
|
||||
- test/core/gprpp/host_port_test.cc
|
||||
deps:
|
||||
- gpr
|
||||
- grpc_test_util_unsecure
|
||||
|
|
@ -5761,6 +5762,19 @@ targets:
|
|||
- grpc
|
||||
- gpr
|
||||
- grpc++_test_config
|
||||
- name: string_view_test
|
||||
gtest: true
|
||||
build: test
|
||||
language: c++
|
||||
src:
|
||||
- test/core/gprpp/string_view_test.cc
|
||||
deps:
|
||||
- grpc_test_util
|
||||
- grpc++
|
||||
- grpc
|
||||
- gpr
|
||||
uses:
|
||||
- grpc++_test
|
||||
- name: thread_manager_test
|
||||
build: test
|
||||
language: c++
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ if test "$PHP_GRPC" != "no"; then
|
|||
src/core/lib/gpr/env_linux.cc \
|
||||
src/core/lib/gpr/env_posix.cc \
|
||||
src/core/lib/gpr/env_windows.cc \
|
||||
src/core/lib/gpr/host_port.cc \
|
||||
src/core/lib/gpr/log.cc \
|
||||
src/core/lib/gpr/log_android.cc \
|
||||
src/core/lib/gpr/log_linux.cc \
|
||||
|
|
@ -80,6 +79,7 @@ if test "$PHP_GRPC" != "no"; then
|
|||
src/core/lib/gprpp/arena.cc \
|
||||
src/core/lib/gprpp/fork.cc \
|
||||
src/core/lib/gprpp/global_config_env.cc \
|
||||
src/core/lib/gprpp/host_port.cc \
|
||||
src/core/lib/gprpp/thd_posix.cc \
|
||||
src/core/lib/gprpp/thd_windows.cc \
|
||||
src/core/lib/profiling/basic_timers.cc \
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ if (PHP_GRPC != "no") {
|
|||
"src\\core\\lib\\gpr\\env_linux.cc " +
|
||||
"src\\core\\lib\\gpr\\env_posix.cc " +
|
||||
"src\\core\\lib\\gpr\\env_windows.cc " +
|
||||
"src\\core\\lib\\gpr\\host_port.cc " +
|
||||
"src\\core\\lib\\gpr\\log.cc " +
|
||||
"src\\core\\lib\\gpr\\log_android.cc " +
|
||||
"src\\core\\lib\\gpr\\log_linux.cc " +
|
||||
|
|
@ -55,6 +54,7 @@ if (PHP_GRPC != "no") {
|
|||
"src\\core\\lib\\gprpp\\arena.cc " +
|
||||
"src\\core\\lib\\gprpp\\fork.cc " +
|
||||
"src\\core\\lib\\gprpp\\global_config_env.cc " +
|
||||
"src\\core\\lib\\gprpp\\host_port.cc " +
|
||||
"src\\core\\lib\\gprpp\\thd_posix.cc " +
|
||||
"src\\core\\lib\\gprpp\\thd_windows.cc " +
|
||||
"src\\core\\lib\\profiling\\basic_timers.cc " +
|
||||
|
|
|
|||
|
|
@ -262,7 +262,6 @@ Pod::Spec.new do |s|
|
|||
'src/core/lib/gpr/alloc.h',
|
||||
'src/core/lib/gpr/arena.h',
|
||||
'src/core/lib/gpr/env.h',
|
||||
'src/core/lib/gpr/host_port.h',
|
||||
'src/core/lib/gpr/mpscq.h',
|
||||
'src/core/lib/gpr/murmur_hash.h',
|
||||
'src/core/lib/gpr/spinlock.h',
|
||||
|
|
@ -283,6 +282,7 @@ Pod::Spec.new do |s|
|
|||
'src/core/lib/gprpp/global_config_custom.h',
|
||||
'src/core/lib/gprpp/global_config_env.h',
|
||||
'src/core/lib/gprpp/global_config_generic.h',
|
||||
'src/core/lib/gprpp/host_port.h',
|
||||
'src/core/lib/gprpp/manual_constructor.h',
|
||||
'src/core/lib/gprpp/map.h',
|
||||
'src/core/lib/gprpp/memory.h',
|
||||
|
|
@ -445,6 +445,7 @@ Pod::Spec.new do |s|
|
|||
'src/core/lib/gprpp/orphanable.h',
|
||||
'src/core/lib/gprpp/ref_counted.h',
|
||||
'src/core/lib/gprpp/ref_counted_ptr.h',
|
||||
'src/core/lib/gprpp/string_view.h',
|
||||
'src/core/lib/http/format_request.h',
|
||||
'src/core/lib/http/httpcli.h',
|
||||
'src/core/lib/http/parser.h',
|
||||
|
|
@ -592,7 +593,6 @@ Pod::Spec.new do |s|
|
|||
'src/core/lib/gpr/alloc.h',
|
||||
'src/core/lib/gpr/arena.h',
|
||||
'src/core/lib/gpr/env.h',
|
||||
'src/core/lib/gpr/host_port.h',
|
||||
'src/core/lib/gpr/mpscq.h',
|
||||
'src/core/lib/gpr/murmur_hash.h',
|
||||
'src/core/lib/gpr/spinlock.h',
|
||||
|
|
@ -613,6 +613,7 @@ Pod::Spec.new do |s|
|
|||
'src/core/lib/gprpp/global_config_custom.h',
|
||||
'src/core/lib/gprpp/global_config_env.h',
|
||||
'src/core/lib/gprpp/global_config_generic.h',
|
||||
'src/core/lib/gprpp/host_port.h',
|
||||
'src/core/lib/gprpp/manual_constructor.h',
|
||||
'src/core/lib/gprpp/map.h',
|
||||
'src/core/lib/gprpp/memory.h',
|
||||
|
|
@ -649,6 +650,7 @@ Pod::Spec.new do |s|
|
|||
'src/core/lib/gprpp/orphanable.h',
|
||||
'src/core/lib/gprpp/ref_counted.h',
|
||||
'src/core/lib/gprpp/ref_counted_ptr.h',
|
||||
'src/core/lib/gprpp/string_view.h',
|
||||
'src/core/lib/http/format_request.h',
|
||||
'src/core/lib/http/httpcli.h',
|
||||
'src/core/lib/http/parser.h',
|
||||
|
|
|
|||
|
|
@ -191,7 +191,6 @@ Pod::Spec.new do |s|
|
|||
ss.source_files = 'src/core/lib/gpr/alloc.h',
|
||||
'src/core/lib/gpr/arena.h',
|
||||
'src/core/lib/gpr/env.h',
|
||||
'src/core/lib/gpr/host_port.h',
|
||||
'src/core/lib/gpr/mpscq.h',
|
||||
'src/core/lib/gpr/murmur_hash.h',
|
||||
'src/core/lib/gpr/spinlock.h',
|
||||
|
|
@ -212,6 +211,7 @@ Pod::Spec.new do |s|
|
|||
'src/core/lib/gprpp/global_config_custom.h',
|
||||
'src/core/lib/gprpp/global_config_env.h',
|
||||
'src/core/lib/gprpp/global_config_generic.h',
|
||||
'src/core/lib/gprpp/host_port.h',
|
||||
'src/core/lib/gprpp/manual_constructor.h',
|
||||
'src/core/lib/gprpp/map.h',
|
||||
'src/core/lib/gprpp/memory.h',
|
||||
|
|
@ -228,7 +228,6 @@ Pod::Spec.new do |s|
|
|||
'src/core/lib/gpr/env_linux.cc',
|
||||
'src/core/lib/gpr/env_posix.cc',
|
||||
'src/core/lib/gpr/env_windows.cc',
|
||||
'src/core/lib/gpr/host_port.cc',
|
||||
'src/core/lib/gpr/log.cc',
|
||||
'src/core/lib/gpr/log_android.cc',
|
||||
'src/core/lib/gpr/log_linux.cc',
|
||||
|
|
@ -255,6 +254,7 @@ Pod::Spec.new do |s|
|
|||
'src/core/lib/gprpp/arena.cc',
|
||||
'src/core/lib/gprpp/fork.cc',
|
||||
'src/core/lib/gprpp/global_config_env.cc',
|
||||
'src/core/lib/gprpp/host_port.cc',
|
||||
'src/core/lib/gprpp/thd_posix.cc',
|
||||
'src/core/lib/gprpp/thd_windows.cc',
|
||||
'src/core/lib/profiling/basic_timers.cc',
|
||||
|
|
@ -414,6 +414,7 @@ Pod::Spec.new do |s|
|
|||
'src/core/lib/gprpp/orphanable.h',
|
||||
'src/core/lib/gprpp/ref_counted.h',
|
||||
'src/core/lib/gprpp/ref_counted_ptr.h',
|
||||
'src/core/lib/gprpp/string_view.h',
|
||||
'src/core/lib/http/format_request.h',
|
||||
'src/core/lib/http/httpcli.h',
|
||||
'src/core/lib/http/parser.h',
|
||||
|
|
@ -884,7 +885,6 @@ Pod::Spec.new do |s|
|
|||
ss.private_header_files = 'src/core/lib/gpr/alloc.h',
|
||||
'src/core/lib/gpr/arena.h',
|
||||
'src/core/lib/gpr/env.h',
|
||||
'src/core/lib/gpr/host_port.h',
|
||||
'src/core/lib/gpr/mpscq.h',
|
||||
'src/core/lib/gpr/murmur_hash.h',
|
||||
'src/core/lib/gpr/spinlock.h',
|
||||
|
|
@ -905,6 +905,7 @@ Pod::Spec.new do |s|
|
|||
'src/core/lib/gprpp/global_config_custom.h',
|
||||
'src/core/lib/gprpp/global_config_env.h',
|
||||
'src/core/lib/gprpp/global_config_generic.h',
|
||||
'src/core/lib/gprpp/host_port.h',
|
||||
'src/core/lib/gprpp/manual_constructor.h',
|
||||
'src/core/lib/gprpp/map.h',
|
||||
'src/core/lib/gprpp/memory.h',
|
||||
|
|
@ -1067,6 +1068,7 @@ Pod::Spec.new do |s|
|
|||
'src/core/lib/gprpp/orphanable.h',
|
||||
'src/core/lib/gprpp/ref_counted.h',
|
||||
'src/core/lib/gprpp/ref_counted_ptr.h',
|
||||
'src/core/lib/gprpp/string_view.h',
|
||||
'src/core/lib/http/format_request.h',
|
||||
'src/core/lib/http/httpcli.h',
|
||||
'src/core/lib/http/parser.h',
|
||||
|
|
|
|||
|
|
@ -85,7 +85,6 @@ Gem::Specification.new do |s|
|
|||
s.files += %w( src/core/lib/gpr/alloc.h )
|
||||
s.files += %w( src/core/lib/gpr/arena.h )
|
||||
s.files += %w( src/core/lib/gpr/env.h )
|
||||
s.files += %w( src/core/lib/gpr/host_port.h )
|
||||
s.files += %w( src/core/lib/gpr/mpscq.h )
|
||||
s.files += %w( src/core/lib/gpr/murmur_hash.h )
|
||||
s.files += %w( src/core/lib/gpr/spinlock.h )
|
||||
|
|
@ -106,6 +105,7 @@ Gem::Specification.new do |s|
|
|||
s.files += %w( src/core/lib/gprpp/global_config_custom.h )
|
||||
s.files += %w( src/core/lib/gprpp/global_config_env.h )
|
||||
s.files += %w( src/core/lib/gprpp/global_config_generic.h )
|
||||
s.files += %w( src/core/lib/gprpp/host_port.h )
|
||||
s.files += %w( src/core/lib/gprpp/manual_constructor.h )
|
||||
s.files += %w( src/core/lib/gprpp/map.h )
|
||||
s.files += %w( src/core/lib/gprpp/memory.h )
|
||||
|
|
@ -122,7 +122,6 @@ Gem::Specification.new do |s|
|
|||
s.files += %w( src/core/lib/gpr/env_linux.cc )
|
||||
s.files += %w( src/core/lib/gpr/env_posix.cc )
|
||||
s.files += %w( src/core/lib/gpr/env_windows.cc )
|
||||
s.files += %w( src/core/lib/gpr/host_port.cc )
|
||||
s.files += %w( src/core/lib/gpr/log.cc )
|
||||
s.files += %w( src/core/lib/gpr/log_android.cc )
|
||||
s.files += %w( src/core/lib/gpr/log_linux.cc )
|
||||
|
|
@ -149,6 +148,7 @@ Gem::Specification.new do |s|
|
|||
s.files += %w( src/core/lib/gprpp/arena.cc )
|
||||
s.files += %w( src/core/lib/gprpp/fork.cc )
|
||||
s.files += %w( src/core/lib/gprpp/global_config_env.cc )
|
||||
s.files += %w( src/core/lib/gprpp/host_port.cc )
|
||||
s.files += %w( src/core/lib/gprpp/thd_posix.cc )
|
||||
s.files += %w( src/core/lib/gprpp/thd_windows.cc )
|
||||
s.files += %w( src/core/lib/profiling/basic_timers.cc )
|
||||
|
|
@ -348,6 +348,7 @@ Gem::Specification.new do |s|
|
|||
s.files += %w( src/core/lib/gprpp/orphanable.h )
|
||||
s.files += %w( src/core/lib/gprpp/ref_counted.h )
|
||||
s.files += %w( src/core/lib/gprpp/ref_counted_ptr.h )
|
||||
s.files += %w( src/core/lib/gprpp/string_view.h )
|
||||
s.files += %w( src/core/lib/http/format_request.h )
|
||||
s.files += %w( src/core/lib/http/httpcli.h )
|
||||
s.files += %w( src/core/lib/http/parser.h )
|
||||
|
|
|
|||
2
grpc.gyp
2
grpc.gyp
|
|
@ -226,7 +226,6 @@
|
|||
'src/core/lib/gpr/env_linux.cc',
|
||||
'src/core/lib/gpr/env_posix.cc',
|
||||
'src/core/lib/gpr/env_windows.cc',
|
||||
'src/core/lib/gpr/host_port.cc',
|
||||
'src/core/lib/gpr/log.cc',
|
||||
'src/core/lib/gpr/log_android.cc',
|
||||
'src/core/lib/gpr/log_linux.cc',
|
||||
|
|
@ -253,6 +252,7 @@
|
|||
'src/core/lib/gprpp/arena.cc',
|
||||
'src/core/lib/gprpp/fork.cc',
|
||||
'src/core/lib/gprpp/global_config_env.cc',
|
||||
'src/core/lib/gprpp/host_port.cc',
|
||||
'src/core/lib/gprpp/thd_posix.cc',
|
||||
'src/core/lib/gprpp/thd_windows.cc',
|
||||
'src/core/lib/profiling/basic_timers.cc',
|
||||
|
|
|
|||
|
|
@ -90,7 +90,6 @@
|
|||
<file baseinstalldir="/" name="src/core/lib/gpr/alloc.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gpr/arena.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gpr/env.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gpr/host_port.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gpr/mpscq.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gpr/murmur_hash.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gpr/spinlock.h" role="src" />
|
||||
|
|
@ -111,6 +110,7 @@
|
|||
<file baseinstalldir="/" name="src/core/lib/gprpp/global_config_custom.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gprpp/global_config_env.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gprpp/global_config_generic.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gprpp/host_port.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gprpp/manual_constructor.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gprpp/map.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gprpp/memory.h" role="src" />
|
||||
|
|
@ -127,7 +127,6 @@
|
|||
<file baseinstalldir="/" name="src/core/lib/gpr/env_linux.cc" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gpr/env_posix.cc" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gpr/env_windows.cc" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gpr/host_port.cc" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gpr/log.cc" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gpr/log_android.cc" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gpr/log_linux.cc" role="src" />
|
||||
|
|
@ -154,6 +153,7 @@
|
|||
<file baseinstalldir="/" name="src/core/lib/gprpp/arena.cc" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gprpp/fork.cc" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gprpp/global_config_env.cc" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gprpp/host_port.cc" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gprpp/thd_posix.cc" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gprpp/thd_windows.cc" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/profiling/basic_timers.cc" role="src" />
|
||||
|
|
@ -353,6 +353,7 @@
|
|||
<file baseinstalldir="/" name="src/core/lib/gprpp/orphanable.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gprpp/ref_counted.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gprpp/ref_counted_ptr.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/gprpp/string_view.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/http/format_request.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/http/httpcli.h" role="src" />
|
||||
<file baseinstalldir="/" name="src/core/lib/http/parser.h" role="src" />
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@
|
|||
#include "src/core/ext/filters/client_channel/proxy_mapper_registry.h"
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/env.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/slice/b64.h"
|
||||
#include "src/core/lib/uri/uri_parser.h"
|
||||
|
||||
|
|
@ -126,17 +126,18 @@ static bool proxy_mapper_map_name(grpc_proxy_mapper* mapper,
|
|||
if (no_proxy_str != nullptr) {
|
||||
static const char* NO_PROXY_SEPARATOR = ",";
|
||||
bool use_proxy = true;
|
||||
char* server_host;
|
||||
char* server_port;
|
||||
if (!gpr_split_host_port(uri->path[0] == '/' ? uri->path + 1 : uri->path,
|
||||
&server_host, &server_port)) {
|
||||
grpc_core::UniquePtr<char> server_host;
|
||||
grpc_core::UniquePtr<char> server_port;
|
||||
if (!grpc_core::SplitHostPort(
|
||||
uri->path[0] == '/' ? uri->path + 1 : uri->path, &server_host,
|
||||
&server_port)) {
|
||||
gpr_log(GPR_INFO,
|
||||
"unable to split host and port, not checking no_proxy list for "
|
||||
"host '%s'",
|
||||
server_uri);
|
||||
gpr_free(no_proxy_str);
|
||||
} else {
|
||||
size_t uri_len = strlen(server_host);
|
||||
size_t uri_len = strlen(server_host.get());
|
||||
char** no_proxy_hosts;
|
||||
size_t num_no_proxy_hosts;
|
||||
gpr_string_split(no_proxy_str, NO_PROXY_SEPARATOR, &no_proxy_hosts,
|
||||
|
|
@ -145,8 +146,8 @@ static bool proxy_mapper_map_name(grpc_proxy_mapper* mapper,
|
|||
char* no_proxy_entry = no_proxy_hosts[i];
|
||||
size_t no_proxy_len = strlen(no_proxy_entry);
|
||||
if (no_proxy_len <= uri_len &&
|
||||
gpr_stricmp(no_proxy_entry, &server_host[uri_len - no_proxy_len]) ==
|
||||
0) {
|
||||
gpr_stricmp(no_proxy_entry,
|
||||
&(server_host.get()[uri_len - no_proxy_len])) == 0) {
|
||||
gpr_log(GPR_INFO, "not using proxy for host in no_proxy list '%s'",
|
||||
server_uri);
|
||||
use_proxy = false;
|
||||
|
|
@ -157,8 +158,6 @@ static bool proxy_mapper_map_name(grpc_proxy_mapper* mapper,
|
|||
gpr_free(no_proxy_hosts[i]);
|
||||
}
|
||||
gpr_free(no_proxy_hosts);
|
||||
gpr_free(server_host);
|
||||
gpr_free(server_port);
|
||||
gpr_free(no_proxy_str);
|
||||
if (!use_proxy) goto no_use_proxy;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,6 @@
|
|||
#include "src/core/lib/backoff/backoff.h"
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/channel/channel_stack.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/manual_constructor.h"
|
||||
#include "src/core/lib/gprpp/memory.h"
|
||||
|
|
|
|||
|
|
@ -84,7 +84,6 @@
|
|||
#include "src/core/lib/backoff/backoff.h"
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/channel/channel_stack.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/manual_constructor.h"
|
||||
#include "src/core/lib/gprpp/map.h"
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@
|
|||
#include <grpc/support/log.h>
|
||||
#include <grpc/support/string_util.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
|
||||
#ifdef GRPC_POSIX_SOCKET
|
||||
#include <errno.h>
|
||||
|
|
@ -73,9 +73,9 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr,
|
|||
bool log_errors) {
|
||||
bool success = false;
|
||||
// Split host and port.
|
||||
char* host;
|
||||
char* port;
|
||||
if (!gpr_split_host_port(hostport, &host, &port)) {
|
||||
grpc_core::UniquePtr<char> host;
|
||||
grpc_core::UniquePtr<char> port;
|
||||
if (!grpc_core::SplitHostPort(hostport, &host, &port)) {
|
||||
if (log_errors) {
|
||||
gpr_log(GPR_ERROR, "Failed gpr_split_host_port(%s, ...)", hostport);
|
||||
}
|
||||
|
|
@ -86,8 +86,10 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr,
|
|||
addr->len = static_cast<socklen_t>(sizeof(grpc_sockaddr_in));
|
||||
grpc_sockaddr_in* in = reinterpret_cast<grpc_sockaddr_in*>(addr->addr);
|
||||
in->sin_family = GRPC_AF_INET;
|
||||
if (grpc_inet_pton(GRPC_AF_INET, host, &in->sin_addr) == 0) {
|
||||
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 address: '%s'", host);
|
||||
if (grpc_inet_pton(GRPC_AF_INET, host.get(), &in->sin_addr) == 0) {
|
||||
if (log_errors) {
|
||||
gpr_log(GPR_ERROR, "invalid ipv4 address: '%s'", host.get());
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
// Parse port.
|
||||
|
|
@ -96,15 +98,14 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr,
|
|||
goto done;
|
||||
}
|
||||
int port_num;
|
||||
if (sscanf(port, "%d", &port_num) != 1 || port_num < 0 || port_num > 65535) {
|
||||
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port);
|
||||
if (sscanf(port.get(), "%d", &port_num) != 1 || port_num < 0 ||
|
||||
port_num > 65535) {
|
||||
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port.get());
|
||||
goto done;
|
||||
}
|
||||
in->sin_port = grpc_htons(static_cast<uint16_t>(port_num));
|
||||
success = true;
|
||||
done:
|
||||
gpr_free(host);
|
||||
gpr_free(port);
|
||||
return success;
|
||||
}
|
||||
|
||||
|
|
@ -124,9 +125,9 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
|
|||
bool log_errors) {
|
||||
bool success = false;
|
||||
// Split host and port.
|
||||
char* host;
|
||||
char* port;
|
||||
if (!gpr_split_host_port(hostport, &host, &port)) {
|
||||
grpc_core::UniquePtr<char> host;
|
||||
grpc_core::UniquePtr<char> port;
|
||||
if (!grpc_core::SplitHostPort(hostport, &host, &port)) {
|
||||
if (log_errors) {
|
||||
gpr_log(GPR_ERROR, "Failed gpr_split_host_port(%s, ...)", hostport);
|
||||
}
|
||||
|
|
@ -138,11 +139,12 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
|
|||
grpc_sockaddr_in6* in6 = reinterpret_cast<grpc_sockaddr_in6*>(addr->addr);
|
||||
in6->sin6_family = GRPC_AF_INET6;
|
||||
// Handle the RFC6874 syntax for IPv6 zone identifiers.
|
||||
char* host_end = static_cast<char*>(gpr_memrchr(host, '%', strlen(host)));
|
||||
char* host_end =
|
||||
static_cast<char*>(gpr_memrchr(host.get(), '%', strlen(host.get())));
|
||||
if (host_end != nullptr) {
|
||||
GPR_ASSERT(host_end >= host);
|
||||
GPR_ASSERT(host_end >= host.get());
|
||||
char host_without_scope[GRPC_INET6_ADDRSTRLEN + 1];
|
||||
size_t host_without_scope_len = static_cast<size_t>(host_end - host);
|
||||
size_t host_without_scope_len = static_cast<size_t>(host_end - host.get());
|
||||
uint32_t sin6_scope_id = 0;
|
||||
if (host_without_scope_len > GRPC_INET6_ADDRSTRLEN) {
|
||||
if (log_errors) {
|
||||
|
|
@ -154,7 +156,7 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
|
|||
}
|
||||
goto done;
|
||||
}
|
||||
strncpy(host_without_scope, host, host_without_scope_len);
|
||||
strncpy(host_without_scope, host.get(), host_without_scope_len);
|
||||
host_without_scope[host_without_scope_len] = '\0';
|
||||
if (grpc_inet_pton(GRPC_AF_INET6, host_without_scope, &in6->sin6_addr) ==
|
||||
0) {
|
||||
|
|
@ -163,9 +165,9 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
|
|||
}
|
||||
goto done;
|
||||
}
|
||||
if (gpr_parse_bytes_to_uint32(host_end + 1,
|
||||
strlen(host) - host_without_scope_len - 1,
|
||||
&sin6_scope_id) == 0) {
|
||||
if (gpr_parse_bytes_to_uint32(
|
||||
host_end + 1, strlen(host.get()) - host_without_scope_len - 1,
|
||||
&sin6_scope_id) == 0) {
|
||||
if ((sin6_scope_id = grpc_if_nametoindex(host_end + 1)) == 0) {
|
||||
gpr_log(GPR_ERROR,
|
||||
"Invalid interface name: '%s'. "
|
||||
|
|
@ -177,8 +179,10 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
|
|||
// Handle "sin6_scope_id" being type "u_long". See grpc issue #10027.
|
||||
in6->sin6_scope_id = sin6_scope_id;
|
||||
} else {
|
||||
if (grpc_inet_pton(GRPC_AF_INET6, host, &in6->sin6_addr) == 0) {
|
||||
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host);
|
||||
if (grpc_inet_pton(GRPC_AF_INET6, host.get(), &in6->sin6_addr) == 0) {
|
||||
if (log_errors) {
|
||||
gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host.get());
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -188,15 +192,14 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
|
|||
goto done;
|
||||
}
|
||||
int port_num;
|
||||
if (sscanf(port, "%d", &port_num) != 1 || port_num < 0 || port_num > 65535) {
|
||||
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port);
|
||||
if (sscanf(port.get(), "%d", &port_num) != 1 || port_num < 0 ||
|
||||
port_num > 65535) {
|
||||
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port.get());
|
||||
goto done;
|
||||
}
|
||||
in6->sin6_port = grpc_htons(static_cast<uint16_t>(port_num));
|
||||
success = true;
|
||||
done:
|
||||
gpr_free(host);
|
||||
gpr_free(port);
|
||||
return success;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@
|
|||
#include "src/core/ext/filters/client_channel/service_config.h"
|
||||
#include "src/core/lib/backoff/backoff.h"
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/manual_constructor.h"
|
||||
#include "src/core/lib/iomgr/combiner.h"
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@
|
|||
#include <address_sorting/address_sorting.h>
|
||||
#include "src/core/ext/filters/client_channel/parse_address.h"
|
||||
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/iomgr/combiner.h"
|
||||
#include "src/core/lib/iomgr/error.h"
|
||||
#include "src/core/lib/iomgr/executor.h"
|
||||
|
|
@ -355,9 +355,9 @@ void grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(
|
|||
grpc_ares_hostbyname_request* hr = nullptr;
|
||||
ares_channel* channel = nullptr;
|
||||
/* parse name, splitting it into host and port parts */
|
||||
char* host;
|
||||
char* port;
|
||||
gpr_split_host_port(name, &host, &port);
|
||||
grpc_core::UniquePtr<char> host;
|
||||
grpc_core::UniquePtr<char> port;
|
||||
grpc_core::SplitHostPort(name, &host, &port);
|
||||
if (host == nullptr) {
|
||||
error = grpc_error_set_str(
|
||||
GRPC_ERROR_CREATE_FROM_STATIC_STRING("unparseable host:port"),
|
||||
|
|
@ -370,7 +370,7 @@ void grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(
|
|||
GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name));
|
||||
goto error_cleanup;
|
||||
}
|
||||
port = gpr_strdup(default_port);
|
||||
port.reset(gpr_strdup(default_port));
|
||||
}
|
||||
error = grpc_ares_ev_driver_create_locked(&r->ev_driver, interested_parties,
|
||||
query_timeout_ms, combiner, r);
|
||||
|
|
@ -414,20 +414,22 @@ void grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(
|
|||
}
|
||||
r->pending_queries = 1;
|
||||
if (grpc_ares_query_ipv6()) {
|
||||
hr = create_hostbyname_request_locked(r, host, grpc_strhtons(port),
|
||||
false /* is_balancer */);
|
||||
hr = create_hostbyname_request_locked(r, host.get(),
|
||||
grpc_strhtons(port.get()),
|
||||
/*is_balancer=*/false);
|
||||
ares_gethostbyname(*channel, hr->host, AF_INET6, on_hostbyname_done_locked,
|
||||
hr);
|
||||
}
|
||||
hr = create_hostbyname_request_locked(r, host, grpc_strhtons(port),
|
||||
false /* is_balancer */);
|
||||
hr =
|
||||
create_hostbyname_request_locked(r, host.get(), grpc_strhtons(port.get()),
|
||||
/*is_balancer=*/false);
|
||||
ares_gethostbyname(*channel, hr->host, AF_INET, on_hostbyname_done_locked,
|
||||
hr);
|
||||
if (check_grpclb) {
|
||||
/* Query the SRV record */
|
||||
grpc_ares_request_ref_locked(r);
|
||||
char* service_name;
|
||||
gpr_asprintf(&service_name, "_grpclb._tcp.%s", host);
|
||||
gpr_asprintf(&service_name, "_grpclb._tcp.%s", host.get());
|
||||
ares_query(*channel, service_name, ns_c_in, ns_t_srv,
|
||||
on_srv_query_done_locked, r);
|
||||
gpr_free(service_name);
|
||||
|
|
@ -435,28 +437,25 @@ void grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(
|
|||
if (r->service_config_json_out != nullptr) {
|
||||
grpc_ares_request_ref_locked(r);
|
||||
char* config_name;
|
||||
gpr_asprintf(&config_name, "_grpc_config.%s", host);
|
||||
gpr_asprintf(&config_name, "_grpc_config.%s", host.get());
|
||||
ares_search(*channel, config_name, ns_c_in, ns_t_txt, on_txt_done_locked,
|
||||
r);
|
||||
gpr_free(config_name);
|
||||
}
|
||||
grpc_ares_ev_driver_start_locked(r->ev_driver);
|
||||
grpc_ares_request_unref_locked(r);
|
||||
gpr_free(host);
|
||||
gpr_free(port);
|
||||
return;
|
||||
|
||||
error_cleanup:
|
||||
GRPC_CLOSURE_SCHED(r->on_done, error);
|
||||
gpr_free(host);
|
||||
gpr_free(port);
|
||||
}
|
||||
|
||||
static bool inner_resolve_as_ip_literal_locked(
|
||||
const char* name, const char* default_port,
|
||||
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs, char** host,
|
||||
char** port, char** hostport) {
|
||||
gpr_split_host_port(name, host, port);
|
||||
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs,
|
||||
grpc_core::UniquePtr<char>* host, grpc_core::UniquePtr<char>* port,
|
||||
grpc_core::UniquePtr<char>* hostport) {
|
||||
grpc_core::SplitHostPort(name, host, port);
|
||||
if (*host == nullptr) {
|
||||
gpr_log(GPR_ERROR,
|
||||
"Failed to parse %s to host:port while attempting to resolve as ip "
|
||||
|
|
@ -472,12 +471,14 @@ static bool inner_resolve_as_ip_literal_locked(
|
|||
name);
|
||||
return false;
|
||||
}
|
||||
*port = gpr_strdup(default_port);
|
||||
port->reset(gpr_strdup(default_port));
|
||||
}
|
||||
grpc_resolved_address addr;
|
||||
GPR_ASSERT(gpr_join_host_port(hostport, *host, atoi(*port)));
|
||||
if (grpc_parse_ipv4_hostport(*hostport, &addr, false /* log errors */) ||
|
||||
grpc_parse_ipv6_hostport(*hostport, &addr, false /* log errors */)) {
|
||||
GPR_ASSERT(grpc_core::JoinHostPort(hostport, host->get(), atoi(port->get())));
|
||||
if (grpc_parse_ipv4_hostport(hostport->get(), &addr,
|
||||
false /* log errors */) ||
|
||||
grpc_parse_ipv6_hostport(hostport->get(), &addr,
|
||||
false /* log errors */)) {
|
||||
GPR_ASSERT(*addrs == nullptr);
|
||||
*addrs = grpc_core::MakeUnique<ServerAddressList>();
|
||||
(*addrs)->emplace_back(addr.addr, addr.len, nullptr /* args */);
|
||||
|
|
@ -489,24 +490,22 @@ static bool inner_resolve_as_ip_literal_locked(
|
|||
static bool resolve_as_ip_literal_locked(
|
||||
const char* name, const char* default_port,
|
||||
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs) {
|
||||
char* host = nullptr;
|
||||
char* port = nullptr;
|
||||
char* hostport = nullptr;
|
||||
grpc_core::UniquePtr<char> host;
|
||||
grpc_core::UniquePtr<char> port;
|
||||
grpc_core::UniquePtr<char> hostport;
|
||||
bool out = inner_resolve_as_ip_literal_locked(name, default_port, addrs,
|
||||
&host, &port, &hostport);
|
||||
gpr_free(host);
|
||||
gpr_free(port);
|
||||
gpr_free(hostport);
|
||||
return out;
|
||||
}
|
||||
|
||||
static bool target_matches_localhost_inner(const char* name, char** host,
|
||||
char** port) {
|
||||
if (!gpr_split_host_port(name, host, port)) {
|
||||
static bool target_matches_localhost_inner(const char* name,
|
||||
grpc_core::UniquePtr<char>* host,
|
||||
grpc_core::UniquePtr<char>* port) {
|
||||
if (!grpc_core::SplitHostPort(name, host, port)) {
|
||||
gpr_log(GPR_ERROR, "Unable to split host and port for name: %s", name);
|
||||
return false;
|
||||
}
|
||||
if (gpr_stricmp(*host, "localhost") == 0) {
|
||||
if (gpr_stricmp(host->get(), "localhost") == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
@ -514,20 +513,17 @@ static bool target_matches_localhost_inner(const char* name, char** host,
|
|||
}
|
||||
|
||||
static bool target_matches_localhost(const char* name) {
|
||||
char* host = nullptr;
|
||||
char* port = nullptr;
|
||||
bool out = target_matches_localhost_inner(name, &host, &port);
|
||||
gpr_free(host);
|
||||
gpr_free(port);
|
||||
return out;
|
||||
grpc_core::UniquePtr<char> host;
|
||||
grpc_core::UniquePtr<char> port;
|
||||
return target_matches_localhost_inner(name, &host, &port);
|
||||
}
|
||||
|
||||
#ifdef GRPC_ARES_RESOLVE_LOCALHOST_MANUALLY
|
||||
static bool inner_maybe_resolve_localhost_manually_locked(
|
||||
const char* name, const char* default_port,
|
||||
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs, char** host,
|
||||
char** port) {
|
||||
gpr_split_host_port(name, host, port);
|
||||
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs,
|
||||
grpc_core::UniquePtr<char>* host, grpc_core::UniquePtr<char>* port) {
|
||||
grpc_core::SplitHostPort(name, host, port);
|
||||
if (*host == nullptr) {
|
||||
gpr_log(GPR_ERROR,
|
||||
"Failed to parse %s into host:port during manual localhost "
|
||||
|
|
@ -543,12 +539,12 @@ static bool inner_maybe_resolve_localhost_manually_locked(
|
|||
name);
|
||||
return false;
|
||||
}
|
||||
*port = gpr_strdup(default_port);
|
||||
port->reset(gpr_strdup(default_port));
|
||||
}
|
||||
if (gpr_stricmp(*host, "localhost") == 0) {
|
||||
if (gpr_stricmp(host->get(), "localhost") == 0) {
|
||||
GPR_ASSERT(*addrs == nullptr);
|
||||
*addrs = grpc_core::MakeUnique<grpc_core::ServerAddressList>();
|
||||
uint16_t numeric_port = grpc_strhtons(*port);
|
||||
uint16_t numeric_port = grpc_strhtons(port->get());
|
||||
// Append the ipv6 loopback address.
|
||||
struct sockaddr_in6 ipv6_loopback_addr;
|
||||
memset(&ipv6_loopback_addr, 0, sizeof(ipv6_loopback_addr));
|
||||
|
|
@ -576,13 +572,10 @@ static bool inner_maybe_resolve_localhost_manually_locked(
|
|||
static bool grpc_ares_maybe_resolve_localhost_manually_locked(
|
||||
const char* name, const char* default_port,
|
||||
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs) {
|
||||
char* host = nullptr;
|
||||
char* port = nullptr;
|
||||
bool out = inner_maybe_resolve_localhost_manually_locked(name, default_port,
|
||||
addrs, &host, &port);
|
||||
gpr_free(host);
|
||||
gpr_free(port);
|
||||
return out;
|
||||
grpc_core::UniquePtr<char> host;
|
||||
grpc_core::UniquePtr<char> port;
|
||||
return inner_maybe_resolve_localhost_manually_locked(name, default_port,
|
||||
addrs, &host, &port);
|
||||
}
|
||||
#else /* GRPC_ARES_RESOLVE_LOCALHOST_MANUALLY */
|
||||
static bool grpc_ares_maybe_resolve_localhost_manually_locked(
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
#include "src/core/ext/filters/client_channel/parse_address.h"
|
||||
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
|
||||
#include "src/core/ext/filters/client_channel/server_address.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
|
||||
bool grpc_ares_query_ipv6() {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
#include "src/core/ext/filters/client_channel/parse_address.h"
|
||||
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
|
||||
#include "src/core/ext/filters/client_channel/server_address.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/iomgr/socket_windows.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@
|
|||
#include "src/core/ext/filters/client_channel/server_address.h"
|
||||
#include "src/core/lib/backoff/backoff.h"
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/manual_constructor.h"
|
||||
#include "src/core/lib/iomgr/combiner.h"
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@
|
|||
#include "src/core/ext/filters/client_channel/resolver_registry.h"
|
||||
#include "src/core/ext/filters/client_channel/server_address.h"
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gpr/useful.h"
|
||||
#include "src/core/lib/iomgr/closure.h"
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@
|
|||
#include "src/core/ext/filters/client_channel/resolver_registry.h"
|
||||
#include "src/core/ext/filters/client_channel/server_address.h"
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/iomgr/combiner.h"
|
||||
#include "src/core/lib/iomgr/resolve_address.h"
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@
|
|||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/channel/handshaker.h"
|
||||
#include "src/core/lib/channel/handshaker_registry.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/iomgr/endpoint.h"
|
||||
#include "src/core/lib/iomgr/resolve_address.h"
|
||||
#include "src/core/lib/iomgr/resource_quota.h"
|
||||
|
|
|
|||
|
|
@ -137,10 +137,10 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
|
|||
p->error = grpc_error_set_int(p->error, GRPC_ERROR_INT_STREAM_ID,
|
||||
static_cast<intptr_t>(s->id));
|
||||
gpr_free(msg);
|
||||
p->error =
|
||||
grpc_error_set_str(p->error, GRPC_ERROR_STR_RAW_BYTES,
|
||||
grpc_dump_slice_to_slice(
|
||||
*slice, GPR_DUMP_HEX | GPR_DUMP_ASCII));
|
||||
p->error = grpc_error_set_str(
|
||||
p->error, GRPC_ERROR_STR_RAW_BYTES,
|
||||
grpc_slice_from_moved_string(grpc_core::UniquePtr<char>(
|
||||
grpc_dump_slice(*slice, GPR_DUMP_HEX | GPR_DUMP_ASCII))));
|
||||
p->error =
|
||||
grpc_error_set_int(p->error, GRPC_ERROR_INT_OFFSET, cur - beg);
|
||||
p->state = GRPC_CHTTP2_DATA_ERROR;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@
|
|||
#include "src/core/ext/transport/chttp2/transport/incoming_metadata.h"
|
||||
#include "src/core/ext/transport/cronet/transport/cronet_transport.h"
|
||||
#include "src/core/lib/debug/trace.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/manual_constructor.h"
|
||||
#include "src/core/lib/iomgr/endpoint.h"
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@
|
|||
|
||||
#include "src/core/lib/channel/channelz_registry.h"
|
||||
#include "src/core/lib/channel/status_util.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gpr/useful.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/gprpp/memory.h"
|
||||
#include "src/core/lib/iomgr/error.h"
|
||||
#include "src/core/lib/iomgr/exec_ctx.h"
|
||||
|
|
@ -406,14 +406,15 @@ void PopulateSocketAddressJson(grpc_json* json, const char* name,
|
|||
(strcmp(uri->scheme, "ipv6") == 0))) {
|
||||
const char* host_port = uri->path;
|
||||
if (*host_port == '/') ++host_port;
|
||||
char* host = nullptr;
|
||||
char* port = nullptr;
|
||||
GPR_ASSERT(gpr_split_host_port(host_port, &host, &port));
|
||||
UniquePtr<char> host;
|
||||
UniquePtr<char> port;
|
||||
GPR_ASSERT(SplitHostPort(host_port, &host, &port));
|
||||
int port_num = -1;
|
||||
if (port != nullptr) {
|
||||
port_num = atoi(port);
|
||||
port_num = atoi(port.get());
|
||||
}
|
||||
char* b64_host = grpc_base64_encode(host, strlen(host), false, false);
|
||||
char* b64_host =
|
||||
grpc_base64_encode(host.get(), strlen(host.get()), false, false);
|
||||
json_iterator = grpc_json_create_child(json_iterator, json, "tcpip_address",
|
||||
nullptr, GRPC_JSON_OBJECT, false);
|
||||
json = json_iterator;
|
||||
|
|
@ -422,8 +423,6 @@ void PopulateSocketAddressJson(grpc_json* json, const char* name,
|
|||
"port", port_num);
|
||||
json_iterator = grpc_json_create_child(json_iterator, json, "ip_address",
|
||||
b64_host, GRPC_JSON_STRING, true);
|
||||
gpr_free(host);
|
||||
gpr_free(port);
|
||||
} else if (uri != nullptr && strcmp(uri->scheme, "unix") == 0) {
|
||||
json_iterator = grpc_json_create_child(json_iterator, json, "uds_address",
|
||||
nullptr, GRPC_JSON_OBJECT, false);
|
||||
|
|
|
|||
|
|
@ -1,98 +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 <grpc/support/port_platform.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <grpc/support/alloc.h>
|
||||
#include <grpc/support/log.h>
|
||||
#include <grpc/support/string_util.h>
|
||||
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
|
||||
int gpr_join_host_port(char** out, const char* host, int port) {
|
||||
if (host[0] != '[' && strchr(host, ':') != nullptr) {
|
||||
/* IPv6 literals must be enclosed in brackets. */
|
||||
return gpr_asprintf(out, "[%s]:%d", host, port);
|
||||
} else {
|
||||
/* Ordinary non-bracketed host:port. */
|
||||
return gpr_asprintf(out, "%s:%d", host, port);
|
||||
}
|
||||
}
|
||||
|
||||
int gpr_split_host_port(const char* name, char** host, char** port) {
|
||||
const char* host_start;
|
||||
size_t host_len;
|
||||
const char* port_start;
|
||||
|
||||
*host = nullptr;
|
||||
*port = nullptr;
|
||||
|
||||
if (name[0] == '[') {
|
||||
/* Parse a bracketed host, typically an IPv6 literal. */
|
||||
const char* rbracket = strchr(name, ']');
|
||||
if (rbracket == nullptr) {
|
||||
/* Unmatched [ */
|
||||
return 0;
|
||||
}
|
||||
if (rbracket[1] == '\0') {
|
||||
/* ]<end> */
|
||||
port_start = nullptr;
|
||||
} else if (rbracket[1] == ':') {
|
||||
/* ]:<port?> */
|
||||
port_start = rbracket + 2;
|
||||
} else {
|
||||
/* ]<invalid> */
|
||||
return 0;
|
||||
}
|
||||
host_start = name + 1;
|
||||
host_len = static_cast<size_t>(rbracket - host_start);
|
||||
if (memchr(host_start, ':', host_len) == nullptr) {
|
||||
/* Require all bracketed hosts to contain a colon, because a hostname or
|
||||
IPv4 address should never use brackets. */
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
const char* colon = strchr(name, ':');
|
||||
if (colon != nullptr && strchr(colon + 1, ':') == nullptr) {
|
||||
/* Exactly 1 colon. Split into host:port. */
|
||||
host_start = name;
|
||||
host_len = static_cast<size_t>(colon - name);
|
||||
port_start = colon + 1;
|
||||
} else {
|
||||
/* 0 or 2+ colons. Bare hostname or IPv6 litearal. */
|
||||
host_start = name;
|
||||
host_len = strlen(name);
|
||||
port_start = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate return values. */
|
||||
*host = static_cast<char*>(gpr_malloc(host_len + 1));
|
||||
memcpy(*host, host_start, host_len);
|
||||
(*host)[host_len] = '\0';
|
||||
|
||||
if (port_start != nullptr) {
|
||||
*port = gpr_strdup(port_start);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -289,17 +289,22 @@ char* gpr_strvec_flatten(gpr_strvec* sv, size_t* final_length) {
|
|||
return gpr_strjoin((const char**)sv->strs, sv->count, final_length);
|
||||
}
|
||||
|
||||
int gpr_stricmp(const char* a, const char* b) {
|
||||
int gpr_strincmp(const char* a, const char* b, size_t n) {
|
||||
int ca, cb;
|
||||
do {
|
||||
ca = tolower(*a);
|
||||
cb = tolower(*b);
|
||||
++a;
|
||||
++b;
|
||||
} while (ca == cb && ca && cb);
|
||||
--n;
|
||||
} while (ca == cb && ca != 0 && cb != 0 && n != 0);
|
||||
return ca - cb;
|
||||
}
|
||||
|
||||
int gpr_stricmp(const char* a, const char* b) {
|
||||
return gpr_strincmp(a, b, SIZE_MAX);
|
||||
}
|
||||
|
||||
static void add_string_to_split(const char* beg, const char* end, char*** strs,
|
||||
size_t* nstrs, size_t* capstrs) {
|
||||
char* out =
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ char* gpr_strvec_flatten(gpr_strvec* strs, size_t* total_length);
|
|||
/** Case insensitive string comparison... return <0 if lower(a)<lower(b), ==0 if
|
||||
lower(a)==lower(b), >0 if lower(a)>lower(b) */
|
||||
int gpr_stricmp(const char* a, const char* b);
|
||||
int gpr_strincmp(const char* a, const char* b, size_t n);
|
||||
|
||||
void* gpr_memrchr(const void* s, int c, size_t n);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
*
|
||||
* 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 <grpc/support/port_platform.h>
|
||||
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <grpc/support/alloc.h>
|
||||
#include <grpc/support/log.h>
|
||||
#include <grpc/support/string_util.h>
|
||||
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/string_view.h"
|
||||
|
||||
namespace grpc_core {
|
||||
int JoinHostPort(UniquePtr<char>* out, const char* host, int port) {
|
||||
char* tmp;
|
||||
int ret;
|
||||
if (host[0] != '[' && strchr(host, ':') != nullptr) {
|
||||
/* IPv6 literals must be enclosed in brackets. */
|
||||
ret = gpr_asprintf(&tmp, "[%s]:%d", host, port);
|
||||
} else {
|
||||
/* Ordinary non-bracketed host:port. */
|
||||
ret = gpr_asprintf(&tmp, "%s:%d", host, port);
|
||||
}
|
||||
out->reset(tmp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool SplitHostPort(StringView name, StringView* host, StringView* port) {
|
||||
if (name[0] == '[') {
|
||||
/* Parse a bracketed host, typically an IPv6 literal. */
|
||||
const size_t rbracket = name.find(']', 1);
|
||||
if (rbracket == grpc_core::StringView::npos) {
|
||||
/* Unmatched [ */
|
||||
return false;
|
||||
}
|
||||
if (rbracket == name.size() - 1) {
|
||||
/* ]<end> */
|
||||
port->clear();
|
||||
} else if (name[rbracket + 1] == ':') {
|
||||
/* ]:<port?> */
|
||||
*port = name.substr(rbracket + 2, name.size() - rbracket - 2);
|
||||
} else {
|
||||
/* ]<invalid> */
|
||||
return false;
|
||||
}
|
||||
*host = name.substr(1, rbracket - 1);
|
||||
if (host->find(':') == grpc_core::StringView::npos) {
|
||||
/* Require all bracketed hosts to contain a colon, because a hostname or
|
||||
IPv4 address should never use brackets. */
|
||||
host->clear();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
size_t colon = name.find(':');
|
||||
if (colon != grpc_core::StringView::npos &&
|
||||
name.find(':', colon + 1) == grpc_core::StringView::npos) {
|
||||
/* Exactly 1 colon. Split into host:port. */
|
||||
*host = name.substr(0, colon);
|
||||
*port = name.substr(colon + 1, name.size() - colon - 1);
|
||||
} else {
|
||||
/* 0 or 2+ colons. Bare hostname or IPv6 litearal. */
|
||||
*host = name;
|
||||
port->clear();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SplitHostPort(StringView name, UniquePtr<char>* host,
|
||||
UniquePtr<char>* port) {
|
||||
StringView host_view;
|
||||
StringView port_view;
|
||||
const bool ret = SplitHostPort(name, &host_view, &port_view);
|
||||
host->reset(host_view.empty() ? nullptr : host_view.dup().release());
|
||||
port->reset(port_view.empty() ? nullptr : port_view.dup().release());
|
||||
return ret;
|
||||
}
|
||||
} // namespace grpc_core
|
||||
|
|
@ -16,28 +16,44 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef GRPC_CORE_LIB_GPR_HOST_PORT_H
|
||||
#define GRPC_CORE_LIB_GPR_HOST_PORT_H
|
||||
#ifndef GRPC_CORE_LIB_GPRPP_HOST_PORT_H
|
||||
#define GRPC_CORE_LIB_GPRPP_HOST_PORT_H
|
||||
|
||||
#include <grpc/support/port_platform.h>
|
||||
|
||||
#include "src/core/lib/gprpp/memory.h"
|
||||
#include "src/core/lib/gprpp/string_view.h"
|
||||
|
||||
namespace grpc_core {
|
||||
|
||||
/** Given a host and port, creates a newly-allocated string of the form
|
||||
"host:port" or "[ho:st]:port", depending on whether the host contains colons
|
||||
like an IPv6 literal. If the host is already bracketed, then additional
|
||||
brackets will not be added.
|
||||
|
||||
Usage is similar to gpr_asprintf: returns the number of bytes written
|
||||
(excluding the final '\0'), and *out points to a string which must later be
|
||||
destroyed using gpr_free().
|
||||
(excluding the final '\0'), and *out points to a string.
|
||||
|
||||
In the unlikely event of an error, returns -1 and sets *out to NULL. */
|
||||
int gpr_join_host_port(char** out, const char* host, int port);
|
||||
int JoinHostPort(UniquePtr<char>* out, const char* host, int port);
|
||||
|
||||
/** Given a name in the form "host:port" or "[ho:st]:port", split into hostname
|
||||
and port number, into newly allocated strings, which must later be
|
||||
destroyed using gpr_free().
|
||||
Return 1 on success, 0 on failure. Guarantees *host and *port == NULL on
|
||||
failure. */
|
||||
int gpr_split_host_port(const char* name, char** host, char** port);
|
||||
and port number.
|
||||
|
||||
#endif /* GRPC_CORE_LIB_GPR_HOST_PORT_H */
|
||||
There are two variants of this method:
|
||||
1) StringView output: port and host are returned as views on name.
|
||||
2) char* output: port and host are copied into newly allocated strings.
|
||||
|
||||
Prefer variant (1) over (2), because no allocation or copy is performed in
|
||||
variant (1). Use (2) only when interacting with C API that mandate
|
||||
null-terminated strings.
|
||||
|
||||
Return true on success, false on failure. Guarantees *host and *port are
|
||||
cleared on failure. */
|
||||
bool SplitHostPort(StringView name, StringView* host, StringView* port);
|
||||
bool SplitHostPort(StringView name, UniquePtr<char>* host,
|
||||
UniquePtr<char>* port);
|
||||
|
||||
} // namespace grpc_core
|
||||
|
||||
#endif /* GRPC_CORE_LIB_GPRPP_HOST_PORT_H */
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
*
|
||||
* Copyright 2019 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_GPRPP_STRING_VIEW_H
|
||||
#define GRPC_CORE_LIB_GPRPP_STRING_VIEW_H
|
||||
|
||||
#include <grpc/support/port_platform.h>
|
||||
|
||||
#include <grpc/impl/codegen/slice.h>
|
||||
#include <grpc/support/alloc.h>
|
||||
#include <grpc/support/log.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gpr/useful.h"
|
||||
#include "src/core/lib/gprpp/memory.h"
|
||||
|
||||
namespace grpc_core {
|
||||
|
||||
// Provides a light-weight view over a char array or a slice, similar but not
|
||||
// identical to absl::string_view.
|
||||
//
|
||||
// Any method that has the same name as absl::string_view MUST HAVE identical
|
||||
// semantics to what absl::string_view provides.
|
||||
//
|
||||
// Methods that are not part of absl::string_view API, must be clearly
|
||||
// annotated.
|
||||
//
|
||||
// StringView does not own the buffers that back the view. Callers must ensure
|
||||
// the buffer stays around while the StringView is accessible.
|
||||
//
|
||||
// Pass StringView by value in functions, since it is exactly two pointers in
|
||||
// size.
|
||||
//
|
||||
// The interface used here is not identical to absl::string_view. Notably, we
|
||||
// need to support slices while we cannot support std::string, and gpr string
|
||||
// style functions such as strdup() and cmp(). Once we switch to
|
||||
// absl::string_view this class will inherit from absl::string_view and add the
|
||||
// gRPC-specific APIs.
|
||||
class StringView final {
|
||||
public:
|
||||
static constexpr size_t npos = std::numeric_limits<size_t>::max();
|
||||
|
||||
constexpr StringView(const char* ptr, size_t size) : ptr_(ptr), size_(size) {}
|
||||
constexpr StringView(const char* ptr)
|
||||
: StringView(ptr, ptr == nullptr ? 0 : strlen(ptr)) {}
|
||||
// Not part of absl::string_view API.
|
||||
StringView(const grpc_slice& slice)
|
||||
: StringView(reinterpret_cast<const char*>(GRPC_SLICE_START_PTR(slice)),
|
||||
GRPC_SLICE_LENGTH(slice)) {}
|
||||
constexpr StringView() : StringView(nullptr, 0) {}
|
||||
|
||||
constexpr const char* data() const { return ptr_; }
|
||||
constexpr size_t size() const { return size_; }
|
||||
constexpr bool empty() const { return size_ == 0; }
|
||||
|
||||
StringView substr(size_t start, size_t size = npos) {
|
||||
GPR_DEBUG_ASSERT(start + size <= size_);
|
||||
return StringView(ptr_ + start, std::min(size, size_ - start));
|
||||
}
|
||||
|
||||
constexpr const char& operator[](size_t i) const { return ptr_[i]; }
|
||||
|
||||
const char& front() const { return ptr_[0]; }
|
||||
const char& back() const { return ptr_[size_ - 1]; }
|
||||
|
||||
void remove_prefix(size_t n) {
|
||||
GPR_DEBUG_ASSERT(n <= size_);
|
||||
ptr_ += n;
|
||||
size_ -= n;
|
||||
}
|
||||
|
||||
void remove_suffix(size_t n) {
|
||||
GPR_DEBUG_ASSERT(n <= size_);
|
||||
size_ -= n;
|
||||
}
|
||||
|
||||
size_t find(char c, size_t pos = 0) const {
|
||||
if (empty() || pos >= size_) return npos;
|
||||
const char* result =
|
||||
static_cast<const char*>(memchr(ptr_ + pos, c, size_ - pos));
|
||||
return result != nullptr ? result - ptr_ : npos;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
ptr_ = nullptr;
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
// Creates a dup of the string viewed by this class.
|
||||
// Return value is null-terminated and never nullptr.
|
||||
//
|
||||
// Not part of absl::string_view API.
|
||||
grpc_core::UniquePtr<char> dup() const {
|
||||
char* str = static_cast<char*>(gpr_malloc(size_ + 1));
|
||||
if (size_ > 0) memcpy(str, ptr_, size_);
|
||||
str[size_] = '\0';
|
||||
return grpc_core::UniquePtr<char>(str);
|
||||
}
|
||||
|
||||
// Not part of absl::string_view API.
|
||||
int cmp(StringView other) const {
|
||||
const size_t len = GPR_MIN(size(), other.size());
|
||||
const int ret = strncmp(data(), other.data(), len);
|
||||
if (ret != 0) return ret;
|
||||
if (size() == other.size()) return 0;
|
||||
if (size() < other.size()) return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
private:
|
||||
const char* ptr_;
|
||||
size_t size_;
|
||||
};
|
||||
|
||||
inline bool operator==(StringView lhs, StringView rhs) {
|
||||
return lhs.size() == rhs.size() &&
|
||||
strncmp(lhs.data(), rhs.data(), lhs.size()) == 0;
|
||||
}
|
||||
|
||||
inline bool operator!=(StringView lhs, StringView rhs) { return !(lhs == rhs); }
|
||||
|
||||
} // namespace grpc_core
|
||||
|
||||
#endif /* GRPC_CORE_LIB_GPRPP_STRING_VIEW_H */
|
||||
|
|
@ -30,6 +30,7 @@
|
|||
#include "src/core/lib/channel/handshaker_registry.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
||||
#include "src/core/lib/gprpp/string_view.h"
|
||||
#include "src/core/lib/iomgr/pollset.h"
|
||||
#include "src/core/lib/security/credentials/credentials.h"
|
||||
#include "src/core/lib/security/security_connector/ssl_utils.h"
|
||||
|
|
@ -108,7 +109,8 @@ class grpc_httpcli_ssl_channel_security_connector final
|
|||
return strcmp(secure_peer_name_, other->secure_peer_name_);
|
||||
}
|
||||
|
||||
bool check_call_host(const char* host, grpc_auth_context* auth_context,
|
||||
bool check_call_host(grpc_core::StringView host,
|
||||
grpc_auth_context* auth_context,
|
||||
grpc_closure* on_call_host_checked,
|
||||
grpc_error** error) override {
|
||||
*error = GRPC_ERROR_NONE;
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@
|
|||
#include <grpc/support/string_util.h>
|
||||
|
||||
#include <grpc/support/log.h>
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gpr/useful.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
|
||||
#include "src/core/lib/iomgr/iomgr_custom.h"
|
||||
#include "src/core/lib/iomgr/resolve_address_custom.h"
|
||||
|
|
@ -86,11 +86,12 @@ void grpc_custom_resolve_callback(grpc_custom_resolver* r,
|
|||
}
|
||||
|
||||
static grpc_error* try_split_host_port(const char* name,
|
||||
const char* default_port, char** host,
|
||||
char** port) {
|
||||
const char* default_port,
|
||||
grpc_core::UniquePtr<char>* host,
|
||||
grpc_core::UniquePtr<char>* port) {
|
||||
/* parse name, splitting it into host and port parts */
|
||||
grpc_error* error;
|
||||
gpr_split_host_port(name, host, port);
|
||||
SplitHostPort(name, host, port);
|
||||
if (*host == nullptr) {
|
||||
char* msg;
|
||||
gpr_asprintf(&msg, "unparseable host:port: '%s'", name);
|
||||
|
|
@ -107,7 +108,7 @@ static grpc_error* try_split_host_port(const char* name,
|
|||
gpr_free(msg);
|
||||
return error;
|
||||
}
|
||||
*port = gpr_strdup(default_port);
|
||||
port->reset(gpr_strdup(default_port));
|
||||
}
|
||||
return GRPC_ERROR_NONE;
|
||||
}
|
||||
|
|
@ -115,28 +116,26 @@ static grpc_error* try_split_host_port(const char* name,
|
|||
static grpc_error* blocking_resolve_address_impl(
|
||||
const char* name, const char* default_port,
|
||||
grpc_resolved_addresses** addresses) {
|
||||
char* host;
|
||||
char* port;
|
||||
grpc_core::UniquePtr<char> host;
|
||||
grpc_core::UniquePtr<char> port;
|
||||
grpc_error* err;
|
||||
|
||||
GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD();
|
||||
|
||||
err = try_split_host_port(name, default_port, &host, &port);
|
||||
if (err != GRPC_ERROR_NONE) {
|
||||
gpr_free(host);
|
||||
gpr_free(port);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Call getaddrinfo */
|
||||
grpc_custom_resolver resolver;
|
||||
resolver.host = host;
|
||||
resolver.port = port;
|
||||
resolver.host = host.get();
|
||||
resolver.port = port.get();
|
||||
|
||||
grpc_resolved_addresses* addrs;
|
||||
grpc_core::ExecCtx* curr = grpc_core::ExecCtx::Get();
|
||||
grpc_core::ExecCtx::Set(nullptr);
|
||||
err = resolve_address_vtable->resolve(host, port, &addrs);
|
||||
err = resolve_address_vtable->resolve(host.get(), port.get(), &addrs);
|
||||
if (err != GRPC_ERROR_NONE) {
|
||||
if (retry_named_port_failure(&resolver, &addrs)) {
|
||||
GRPC_ERROR_UNREF(err);
|
||||
|
|
@ -147,8 +146,6 @@ static grpc_error* blocking_resolve_address_impl(
|
|||
if (err == GRPC_ERROR_NONE) {
|
||||
*addresses = addrs;
|
||||
}
|
||||
gpr_free(resolver.host);
|
||||
gpr_free(resolver.port);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
@ -157,22 +154,20 @@ static void resolve_address_impl(const char* name, const char* default_port,
|
|||
grpc_closure* on_done,
|
||||
grpc_resolved_addresses** addrs) {
|
||||
grpc_custom_resolver* r = nullptr;
|
||||
char* host = nullptr;
|
||||
char* port = nullptr;
|
||||
grpc_core::UniquePtr<char> host;
|
||||
grpc_core::UniquePtr<char> port;
|
||||
grpc_error* err;
|
||||
GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD();
|
||||
err = try_split_host_port(name, default_port, &host, &port);
|
||||
if (err != GRPC_ERROR_NONE) {
|
||||
GRPC_CLOSURE_SCHED(on_done, err);
|
||||
gpr_free(host);
|
||||
gpr_free(port);
|
||||
return;
|
||||
}
|
||||
r = (grpc_custom_resolver*)gpr_malloc(sizeof(grpc_custom_resolver));
|
||||
r->on_done = on_done;
|
||||
r->addresses = addrs;
|
||||
r->host = host;
|
||||
r->port = port;
|
||||
r->host = host.release();
|
||||
r->port = port.release();
|
||||
|
||||
/* Call getaddrinfo */
|
||||
resolve_address_vtable->resolve_async(r, r->host, r->port);
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@
|
|||
#include <grpc/support/string_util.h>
|
||||
#include <grpc/support/time.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gpr/useful.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/gprpp/thd.h"
|
||||
#include "src/core/lib/iomgr/block_annotate.h"
|
||||
#include "src/core/lib/iomgr/executor.h"
|
||||
|
|
@ -48,8 +48,6 @@ static grpc_error* posix_blocking_resolve_address(
|
|||
grpc_core::ExecCtx exec_ctx;
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *result = nullptr, *resp;
|
||||
char* host;
|
||||
char* port;
|
||||
int s;
|
||||
size_t i;
|
||||
grpc_error* err;
|
||||
|
|
@ -59,8 +57,10 @@ static grpc_error* posix_blocking_resolve_address(
|
|||
return grpc_resolve_unix_domain_address(name + 5, addresses);
|
||||
}
|
||||
|
||||
grpc_core::UniquePtr<char> host;
|
||||
grpc_core::UniquePtr<char> port;
|
||||
/* parse name, splitting it into host and port parts */
|
||||
gpr_split_host_port(name, &host, &port);
|
||||
grpc_core::SplitHostPort(name, &host, &port);
|
||||
if (host == nullptr) {
|
||||
err = grpc_error_set_str(
|
||||
GRPC_ERROR_CREATE_FROM_STATIC_STRING("unparseable host:port"),
|
||||
|
|
@ -74,7 +74,7 @@ static grpc_error* posix_blocking_resolve_address(
|
|||
GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name));
|
||||
goto done;
|
||||
}
|
||||
port = gpr_strdup(default_port);
|
||||
port.reset(gpr_strdup(default_port));
|
||||
}
|
||||
|
||||
/* Call getaddrinfo */
|
||||
|
|
@ -84,16 +84,16 @@ static grpc_error* posix_blocking_resolve_address(
|
|||
hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */
|
||||
|
||||
GRPC_SCHEDULING_START_BLOCKING_REGION;
|
||||
s = getaddrinfo(host, port, &hints, &result);
|
||||
s = getaddrinfo(host.get(), port.get(), &hints, &result);
|
||||
GRPC_SCHEDULING_END_BLOCKING_REGION;
|
||||
|
||||
if (s != 0) {
|
||||
/* Retry if well-known service name is recognized */
|
||||
const char* svc[][2] = {{"http", "80"}, {"https", "443"}};
|
||||
for (i = 0; i < GPR_ARRAY_SIZE(svc); i++) {
|
||||
if (strcmp(port, svc[i][0]) == 0) {
|
||||
if (strcmp(port.get(), svc[i][0]) == 0) {
|
||||
GRPC_SCHEDULING_START_BLOCKING_REGION;
|
||||
s = getaddrinfo(host, svc[i][1], &hints, &result);
|
||||
s = getaddrinfo(host.get(), svc[i][1], &hints, &result);
|
||||
GRPC_SCHEDULING_END_BLOCKING_REGION;
|
||||
break;
|
||||
}
|
||||
|
|
@ -133,8 +133,6 @@ static grpc_error* posix_blocking_resolve_address(
|
|||
err = GRPC_ERROR_NONE;
|
||||
|
||||
done:
|
||||
gpr_free(host);
|
||||
gpr_free(port);
|
||||
if (result) {
|
||||
freeaddrinfo(result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@
|
|||
#include <grpc/support/string_util.h>
|
||||
#include <grpc/support/time.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/gprpp/thd.h"
|
||||
#include "src/core/lib/iomgr/block_annotate.h"
|
||||
#include "src/core/lib/iomgr/executor.h"
|
||||
|
|
@ -57,14 +57,14 @@ static grpc_error* windows_blocking_resolve_address(
|
|||
grpc_core::ExecCtx exec_ctx;
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *result = NULL, *resp;
|
||||
char* host;
|
||||
char* port;
|
||||
int s;
|
||||
size_t i;
|
||||
grpc_error* error = GRPC_ERROR_NONE;
|
||||
|
||||
/* parse name, splitting it into host and port parts */
|
||||
gpr_split_host_port(name, &host, &port);
|
||||
grpc_core::UniquePtr<char> host;
|
||||
grpc_core::UniquePtr<char> port;
|
||||
grpc_core::SplitHostPort(name, &host, &port);
|
||||
if (host == NULL) {
|
||||
char* msg;
|
||||
gpr_asprintf(&msg, "unparseable host:port: '%s'", name);
|
||||
|
|
@ -80,7 +80,7 @@ static grpc_error* windows_blocking_resolve_address(
|
|||
gpr_free(msg);
|
||||
goto done;
|
||||
}
|
||||
port = gpr_strdup(default_port);
|
||||
port.reset(gpr_strdup(default_port));
|
||||
}
|
||||
|
||||
/* Call getaddrinfo */
|
||||
|
|
@ -90,7 +90,7 @@ static grpc_error* windows_blocking_resolve_address(
|
|||
hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */
|
||||
|
||||
GRPC_SCHEDULING_START_BLOCKING_REGION;
|
||||
s = getaddrinfo(host, port, &hints, &result);
|
||||
s = getaddrinfo(host.get(), port.get(), &hints, &result);
|
||||
GRPC_SCHEDULING_END_BLOCKING_REGION;
|
||||
if (s != 0) {
|
||||
error = GRPC_WSA_ERROR(WSAGetLastError(), "getaddrinfo");
|
||||
|
|
@ -122,8 +122,6 @@ static grpc_error* windows_blocking_resolve_address(
|
|||
}
|
||||
|
||||
done:
|
||||
gpr_free(host);
|
||||
gpr_free(port);
|
||||
if (result) {
|
||||
freeaddrinfo(result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@
|
|||
#include <grpc/support/log.h>
|
||||
#include <grpc/support/string_util.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/iomgr/sockaddr.h"
|
||||
#include "src/core/lib/iomgr/socket_utils.h"
|
||||
#include "src/core/lib/iomgr/unix_sockets_posix.h"
|
||||
|
|
@ -181,15 +181,17 @@ int grpc_sockaddr_to_string(char** out,
|
|||
}
|
||||
if (ip != nullptr && grpc_inet_ntop(addr->sa_family, ip, ntop_buf,
|
||||
sizeof(ntop_buf)) != nullptr) {
|
||||
grpc_core::UniquePtr<char> tmp_out;
|
||||
if (sin6_scope_id != 0) {
|
||||
char* host_with_scope;
|
||||
/* Enclose sin6_scope_id with the format defined in RFC 6784 section 2. */
|
||||
gpr_asprintf(&host_with_scope, "%s%%25%" PRIu32, ntop_buf, sin6_scope_id);
|
||||
ret = gpr_join_host_port(out, host_with_scope, port);
|
||||
ret = grpc_core::JoinHostPort(&tmp_out, host_with_scope, port);
|
||||
gpr_free(host_with_scope);
|
||||
} else {
|
||||
ret = gpr_join_host_port(out, ntop_buf, port);
|
||||
ret = grpc_core::JoinHostPort(&tmp_out, ntop_buf, port);
|
||||
}
|
||||
*out = tmp_out.release();
|
||||
} else {
|
||||
ret = gpr_asprintf(out, "(sockaddr family=%d)", addr->sa_family);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@
|
|||
#include <grpc/support/sync.h>
|
||||
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/iomgr/sockaddr.h"
|
||||
#include "src/core/lib/iomgr/sockaddr_utils.h"
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
#include <netinet/in.h>
|
||||
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/iomgr/cfstream_handle.h"
|
||||
#include "src/core/lib/iomgr/closure.h"
|
||||
#include "src/core/lib/iomgr/endpoint_cfstream.h"
|
||||
|
|
@ -143,12 +143,13 @@ static void OnOpen(void* arg, grpc_error* error) {
|
|||
|
||||
static void ParseResolvedAddress(const grpc_resolved_address* addr,
|
||||
CFStringRef* host, int* port) {
|
||||
char *host_port, *host_string, *port_string;
|
||||
char* host_port;
|
||||
grpc_sockaddr_to_string(&host_port, addr, 1);
|
||||
gpr_split_host_port(host_port, &host_string, &port_string);
|
||||
*host = CFStringCreateWithCString(NULL, host_string, kCFStringEncodingUTF8);
|
||||
gpr_free(host_string);
|
||||
gpr_free(port_string);
|
||||
grpc_core::UniquePtr<char> host_string;
|
||||
grpc_core::UniquePtr<char> port_string;
|
||||
grpc_core::SplitHostPort(host_port, &host_string, &port_string);
|
||||
*host =
|
||||
CFStringCreateWithCString(NULL, host_string.get(), kCFStringEncodingUTF8);
|
||||
gpr_free(host_port);
|
||||
*port = grpc_sockaddr_get_port(addr);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,10 +108,11 @@ class grpc_alts_channel_security_connector final
|
|||
return strcmp(target_name_, other->target_name_);
|
||||
}
|
||||
|
||||
bool check_call_host(const char* host, grpc_auth_context* auth_context,
|
||||
bool check_call_host(grpc_core::StringView host,
|
||||
grpc_auth_context* auth_context,
|
||||
grpc_closure* on_call_host_checked,
|
||||
grpc_error** error) override {
|
||||
if (host == nullptr || strcmp(host, target_name_) != 0) {
|
||||
if (host.empty() || host != target_name_) {
|
||||
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
||||
"ALTS call host does not match target name");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@
|
|||
#include "src/core/ext/transport/chttp2/alpn/alpn.h"
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/channel/handshaker.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
||||
#include "src/core/lib/security/context/security_context.h"
|
||||
#include "src/core/lib/security/credentials/credentials.h"
|
||||
|
|
@ -102,39 +102,35 @@ class grpc_fake_channel_security_connector final
|
|||
tsi_create_fake_handshaker(/*is_client=*/true), this));
|
||||
}
|
||||
|
||||
bool check_call_host(const char* host, grpc_auth_context* auth_context,
|
||||
bool check_call_host(grpc_core::StringView host,
|
||||
grpc_auth_context* auth_context,
|
||||
grpc_closure* on_call_host_checked,
|
||||
grpc_error** error) override {
|
||||
char* authority_hostname = nullptr;
|
||||
char* authority_ignored_port = nullptr;
|
||||
char* target_hostname = nullptr;
|
||||
char* target_ignored_port = nullptr;
|
||||
gpr_split_host_port(host, &authority_hostname, &authority_ignored_port);
|
||||
gpr_split_host_port(target_, &target_hostname, &target_ignored_port);
|
||||
grpc_core::StringView authority_hostname;
|
||||
grpc_core::StringView authority_ignored_port;
|
||||
grpc_core::StringView target_hostname;
|
||||
grpc_core::StringView target_ignored_port;
|
||||
grpc_core::SplitHostPort(host, &authority_hostname,
|
||||
&authority_ignored_port);
|
||||
grpc_core::SplitHostPort(target_, &target_hostname, &target_ignored_port);
|
||||
if (target_name_override_ != nullptr) {
|
||||
char* fake_security_target_name_override_hostname = nullptr;
|
||||
char* fake_security_target_name_override_ignored_port = nullptr;
|
||||
gpr_split_host_port(target_name_override_,
|
||||
&fake_security_target_name_override_hostname,
|
||||
&fake_security_target_name_override_ignored_port);
|
||||
if (strcmp(authority_hostname,
|
||||
fake_security_target_name_override_hostname) != 0) {
|
||||
grpc_core::StringView fake_security_target_name_override_hostname;
|
||||
grpc_core::StringView fake_security_target_name_override_ignored_port;
|
||||
grpc_core::SplitHostPort(
|
||||
target_name_override_, &fake_security_target_name_override_hostname,
|
||||
&fake_security_target_name_override_ignored_port);
|
||||
if (authority_hostname != fake_security_target_name_override_hostname) {
|
||||
gpr_log(GPR_ERROR,
|
||||
"Authority (host) '%s' != Fake Security Target override '%s'",
|
||||
host, fake_security_target_name_override_hostname);
|
||||
host.data(),
|
||||
fake_security_target_name_override_hostname.data());
|
||||
abort();
|
||||
}
|
||||
gpr_free(fake_security_target_name_override_hostname);
|
||||
gpr_free(fake_security_target_name_override_ignored_port);
|
||||
} else if (strcmp(authority_hostname, target_hostname) != 0) {
|
||||
gpr_log(GPR_ERROR, "Authority (host) '%s' != Target '%s'",
|
||||
authority_hostname, target_hostname);
|
||||
} else if (authority_hostname != target_hostname) {
|
||||
gpr_log(GPR_ERROR, "Authority (host) '%s' != Target '%s'", host.data(),
|
||||
target_);
|
||||
abort();
|
||||
}
|
||||
gpr_free(authority_hostname);
|
||||
gpr_free(authority_ignored_port);
|
||||
gpr_free(target_hostname);
|
||||
gpr_free(target_ignored_port);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -156,10 +156,11 @@ class grpc_local_channel_security_connector final
|
|||
creds->connect_type());
|
||||
}
|
||||
|
||||
bool check_call_host(const char* host, grpc_auth_context* auth_context,
|
||||
bool check_call_host(grpc_core::StringView host,
|
||||
grpc_auth_context* auth_context,
|
||||
grpc_closure* on_call_host_checked,
|
||||
grpc_error** error) override {
|
||||
if (host == nullptr || strcmp(host, target_name_) != 0) {
|
||||
if (host.empty() || host != target_name_) {
|
||||
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
||||
"local call host does not match target name");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@
|
|||
#include "src/core/ext/transport/chttp2/alpn/alpn.h"
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/channel/handshaker.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/iomgr/load_file.h"
|
||||
#include "src/core/lib/security/context/security_context.h"
|
||||
#include "src/core/lib/security/credentials/credentials.h"
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ class grpc_channel_security_connector : public grpc_security_connector {
|
|||
/// Returns true if completed synchronously, in which case \a error will
|
||||
/// be set to indicate the result. Otherwise, \a on_call_host_checked
|
||||
/// will be invoked when complete.
|
||||
virtual bool check_call_host(const char* host,
|
||||
virtual bool check_call_host(grpc_core::StringView host,
|
||||
grpc_auth_context* auth_context,
|
||||
grpc_closure* on_call_host_checked,
|
||||
grpc_error** error) GRPC_ABSTRACT;
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@
|
|||
|
||||
#include "src/core/ext/transport/chttp2/alpn/alpn.h"
|
||||
#include "src/core/lib/channel/handshaker.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
||||
#include "src/core/lib/security/context/security_context.h"
|
||||
#include "src/core/lib/security/credentials/credentials.h"
|
||||
|
|
@ -75,15 +75,14 @@ class grpc_ssl_channel_security_connector final
|
|||
? nullptr
|
||||
: gpr_strdup(overridden_target_name)),
|
||||
verify_options_(&config->verify_options) {
|
||||
char* port;
|
||||
gpr_split_host_port(target_name, &target_name_, &port);
|
||||
gpr_free(port);
|
||||
grpc_core::StringView host;
|
||||
grpc_core::StringView port;
|
||||
grpc_core::SplitHostPort(target_name, &host, &port);
|
||||
target_name_ = host.dup();
|
||||
}
|
||||
|
||||
~grpc_ssl_channel_security_connector() override {
|
||||
tsi_ssl_client_handshaker_factory_unref(client_handshaker_factory_);
|
||||
if (target_name_ != nullptr) gpr_free(target_name_);
|
||||
if (overridden_target_name_ != nullptr) gpr_free(overridden_target_name_);
|
||||
}
|
||||
|
||||
grpc_security_status InitializeHandshakerFactory(
|
||||
|
|
@ -123,8 +122,8 @@ class grpc_ssl_channel_security_connector final
|
|||
tsi_handshaker* tsi_hs = nullptr;
|
||||
tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker(
|
||||
client_handshaker_factory_,
|
||||
overridden_target_name_ != nullptr ? overridden_target_name_
|
||||
: target_name_,
|
||||
overridden_target_name_ != nullptr ? overridden_target_name_.get()
|
||||
: target_name_.get(),
|
||||
&tsi_hs);
|
||||
if (result != TSI_OK) {
|
||||
gpr_log(GPR_ERROR, "Handshaker creation failed with error %s.",
|
||||
|
|
@ -139,8 +138,8 @@ class grpc_ssl_channel_security_connector final
|
|||
grpc_core::RefCountedPtr<grpc_auth_context>* auth_context,
|
||||
grpc_closure* on_peer_checked) override {
|
||||
const char* target_name = overridden_target_name_ != nullptr
|
||||
? overridden_target_name_
|
||||
: target_name_;
|
||||
? overridden_target_name_.get()
|
||||
: target_name_.get();
|
||||
grpc_error* error = ssl_check_peer(target_name, &peer, auth_context);
|
||||
if (error == GRPC_ERROR_NONE &&
|
||||
verify_options_->verify_peer_callback != nullptr) {
|
||||
|
|
@ -175,17 +174,18 @@ class grpc_ssl_channel_security_connector final
|
|||
reinterpret_cast<const grpc_ssl_channel_security_connector*>(other_sc);
|
||||
int c = channel_security_connector_cmp(other);
|
||||
if (c != 0) return c;
|
||||
c = strcmp(target_name_, other->target_name_);
|
||||
c = strcmp(target_name_.get(), other->target_name_.get());
|
||||
if (c != 0) return c;
|
||||
return (overridden_target_name_ == nullptr ||
|
||||
other->overridden_target_name_ == nullptr)
|
||||
? GPR_ICMP(overridden_target_name_,
|
||||
other->overridden_target_name_)
|
||||
: strcmp(overridden_target_name_,
|
||||
other->overridden_target_name_);
|
||||
? GPR_ICMP(overridden_target_name_.get(),
|
||||
other->overridden_target_name_.get())
|
||||
: strcmp(overridden_target_name_.get(),
|
||||
other->overridden_target_name_.get());
|
||||
}
|
||||
|
||||
bool check_call_host(const char* host, grpc_auth_context* auth_context,
|
||||
bool check_call_host(grpc_core::StringView host,
|
||||
grpc_auth_context* auth_context,
|
||||
grpc_closure* on_call_host_checked,
|
||||
grpc_error** error) override {
|
||||
grpc_security_status status = GRPC_SECURITY_ERROR;
|
||||
|
|
@ -194,7 +194,7 @@ class grpc_ssl_channel_security_connector final
|
|||
/* If the target name was overridden, then the original target_name was
|
||||
'checked' transitively during the previous peer check at the end of the
|
||||
handshake. */
|
||||
if (overridden_target_name_ != nullptr && strcmp(host, target_name_) == 0) {
|
||||
if (overridden_target_name_ != nullptr && host == target_name_.get()) {
|
||||
status = GRPC_SECURITY_OK;
|
||||
}
|
||||
if (status != GRPC_SECURITY_OK) {
|
||||
|
|
@ -212,8 +212,8 @@ class grpc_ssl_channel_security_connector final
|
|||
|
||||
private:
|
||||
tsi_ssl_client_handshaker_factory* client_handshaker_factory_;
|
||||
char* target_name_;
|
||||
char* overridden_target_name_;
|
||||
grpc_core::UniquePtr<char> target_name_;
|
||||
grpc_core::UniquePtr<char> overridden_target_name_;
|
||||
const verify_peer_options* verify_options_;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@
|
|||
|
||||
#include "src/core/ext/transport/chttp2/alpn/alpn.h"
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/global_config.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
||||
#include "src/core/lib/iomgr/load_file.h"
|
||||
#include "src/core/lib/security/context/security_context.h"
|
||||
|
|
@ -136,12 +136,13 @@ grpc_error* grpc_ssl_check_alpn(const tsi_peer* peer) {
|
|||
return GRPC_ERROR_NONE;
|
||||
}
|
||||
|
||||
grpc_error* grpc_ssl_check_peer_name(const char* peer_name,
|
||||
grpc_error* grpc_ssl_check_peer_name(grpc_core::StringView peer_name,
|
||||
const tsi_peer* peer) {
|
||||
/* Check the peer name if specified. */
|
||||
if (peer_name != nullptr && !grpc_ssl_host_matches_name(peer, peer_name)) {
|
||||
if (!peer_name.empty() && !grpc_ssl_host_matches_name(peer, peer_name)) {
|
||||
char* msg;
|
||||
gpr_asprintf(&msg, "Peer name %s is not in peer certificate", peer_name);
|
||||
gpr_asprintf(&msg, "Peer name %s is not in peer certificate",
|
||||
peer_name.data());
|
||||
grpc_error* error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
|
||||
gpr_free(msg);
|
||||
return error;
|
||||
|
|
@ -149,15 +150,16 @@ grpc_error* grpc_ssl_check_peer_name(const char* peer_name,
|
|||
return GRPC_ERROR_NONE;
|
||||
}
|
||||
|
||||
bool grpc_ssl_check_call_host(const char* host, const char* target_name,
|
||||
const char* overridden_target_name,
|
||||
bool grpc_ssl_check_call_host(grpc_core::StringView host,
|
||||
grpc_core::StringView target_name,
|
||||
grpc_core::StringView overridden_target_name,
|
||||
grpc_auth_context* auth_context,
|
||||
grpc_closure* on_call_host_checked,
|
||||
grpc_error** error) {
|
||||
grpc_security_status status = GRPC_SECURITY_ERROR;
|
||||
tsi_peer peer = grpc_shallow_peer_from_ssl_auth_context(auth_context);
|
||||
if (grpc_ssl_host_matches_name(&peer, host)) status = GRPC_SECURITY_OK;
|
||||
if (overridden_target_name != nullptr && strcmp(host, target_name) == 0) {
|
||||
if (!overridden_target_name.empty() && host == target_name) {
|
||||
status = GRPC_SECURITY_OK;
|
||||
}
|
||||
if (status != GRPC_SECURITY_OK) {
|
||||
|
|
@ -179,35 +181,28 @@ const char** grpc_fill_alpn_protocol_strings(size_t* num_alpn_protocols) {
|
|||
return alpn_protocol_strings;
|
||||
}
|
||||
|
||||
int grpc_ssl_host_matches_name(const tsi_peer* peer, const char* peer_name) {
|
||||
char* allocated_name = nullptr;
|
||||
int r;
|
||||
|
||||
char* ignored_port;
|
||||
gpr_split_host_port(peer_name, &allocated_name, &ignored_port);
|
||||
gpr_free(ignored_port);
|
||||
peer_name = allocated_name;
|
||||
if (!peer_name) return 0;
|
||||
int grpc_ssl_host_matches_name(const tsi_peer* peer,
|
||||
grpc_core::StringView peer_name) {
|
||||
grpc_core::StringView allocated_name;
|
||||
grpc_core::StringView ignored_port;
|
||||
grpc_core::SplitHostPort(peer_name, &allocated_name, &ignored_port);
|
||||
if (allocated_name.empty()) return 0;
|
||||
|
||||
// IPv6 zone-id should not be included in comparisons.
|
||||
char* const zone_id = strchr(allocated_name, '%');
|
||||
if (zone_id != nullptr) *zone_id = '\0';
|
||||
|
||||
r = tsi_ssl_peer_matches_name(peer, peer_name);
|
||||
gpr_free(allocated_name);
|
||||
return r;
|
||||
const size_t zone_id = allocated_name.find('%');
|
||||
if (zone_id != grpc_core::StringView::npos) {
|
||||
allocated_name.remove_suffix(allocated_name.size() - zone_id);
|
||||
}
|
||||
return tsi_ssl_peer_matches_name(peer, allocated_name);
|
||||
}
|
||||
|
||||
bool grpc_ssl_cmp_target_name(const char* target_name,
|
||||
const char* other_target_name,
|
||||
const char* overridden_target_name,
|
||||
const char* other_overridden_target_name) {
|
||||
int c = strcmp(target_name, other_target_name);
|
||||
int grpc_ssl_cmp_target_name(
|
||||
grpc_core::StringView target_name, grpc_core::StringView other_target_name,
|
||||
grpc_core::StringView overridden_target_name,
|
||||
grpc_core::StringView other_overridden_target_name) {
|
||||
int c = target_name.cmp(other_target_name);
|
||||
if (c != 0) return c;
|
||||
return (overridden_target_name == nullptr ||
|
||||
other_overridden_target_name == nullptr)
|
||||
? GPR_ICMP(overridden_target_name, other_overridden_target_name)
|
||||
: strcmp(overridden_target_name, other_overridden_target_name);
|
||||
return overridden_target_name.cmp(other_overridden_target_name);
|
||||
}
|
||||
|
||||
grpc_core::RefCountedPtr<grpc_auth_context> grpc_ssl_peer_to_auth_context(
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "src/core/lib/gprpp/global_config.h"
|
||||
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
||||
#include "src/core/lib/gprpp/string_view.h"
|
||||
#include "src/core/lib/iomgr/error.h"
|
||||
#include "src/core/lib/security/security_connector/security_connector.h"
|
||||
#include "src/core/tsi/ssl_transport_security.h"
|
||||
|
|
@ -46,16 +47,17 @@ GPR_GLOBAL_CONFIG_DECLARE_BOOL(grpc_not_use_system_ssl_roots);
|
|||
grpc_error* grpc_ssl_check_alpn(const tsi_peer* peer);
|
||||
|
||||
/* Check peer name information returned from SSL handshakes. */
|
||||
grpc_error* grpc_ssl_check_peer_name(const char* peer_name,
|
||||
grpc_error* grpc_ssl_check_peer_name(grpc_core::StringView peer_name,
|
||||
const tsi_peer* peer);
|
||||
/* Compare targer_name information extracted from SSL security connectors. */
|
||||
bool grpc_ssl_cmp_target_name(const char* target_name,
|
||||
const char* other_target_name,
|
||||
const char* overridden_target_name,
|
||||
const char* other_overridden_target_name);
|
||||
int grpc_ssl_cmp_target_name(
|
||||
grpc_core::StringView target_name, grpc_core::StringView other_target_name,
|
||||
grpc_core::StringView overridden_target_name,
|
||||
grpc_core::StringView other_overridden_target_name);
|
||||
/* Check the host that will be set for a call is acceptable.*/
|
||||
bool grpc_ssl_check_call_host(const char* host, const char* target_name,
|
||||
const char* overridden_target_name,
|
||||
bool grpc_ssl_check_call_host(grpc_core::StringView host,
|
||||
grpc_core::StringView target_name,
|
||||
grpc_core::StringView overridden_target_name,
|
||||
grpc_auth_context* auth_context,
|
||||
grpc_closure* on_call_host_checked,
|
||||
grpc_error** error);
|
||||
|
|
@ -89,7 +91,8 @@ grpc_core::RefCountedPtr<grpc_auth_context> grpc_ssl_peer_to_auth_context(
|
|||
tsi_peer grpc_shallow_peer_from_ssl_auth_context(
|
||||
const grpc_auth_context* auth_context);
|
||||
void grpc_shallow_peer_destruct(tsi_peer* peer);
|
||||
int grpc_ssl_host_matches_name(const tsi_peer* peer, const char* peer_name);
|
||||
int grpc_ssl_host_matches_name(const tsi_peer* peer,
|
||||
grpc_core::StringView peer_name);
|
||||
|
||||
/* --- Default SSL Root Store. --- */
|
||||
namespace grpc_core {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
#include <grpc/support/log.h>
|
||||
#include <grpc/support/string_util.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/security/credentials/ssl/ssl_credentials.h"
|
||||
#include "src/core/lib/security/credentials/tls/spiffe_credentials.h"
|
||||
#include "src/core/lib/security/security_connector/ssl_utils.h"
|
||||
|
|
@ -105,18 +105,13 @@ SpiffeChannelSecurityConnector::SpiffeChannelSecurityConnector(
|
|||
? nullptr
|
||||
: gpr_strdup(overridden_target_name)) {
|
||||
check_arg_ = ServerAuthorizationCheckArgCreate(this);
|
||||
char* port;
|
||||
gpr_split_host_port(target_name, &target_name_, &port);
|
||||
gpr_free(port);
|
||||
grpc_core::StringView host;
|
||||
grpc_core::StringView port;
|
||||
grpc_core::SplitHostPort(target_name, &host, &port);
|
||||
target_name_ = host.dup();
|
||||
}
|
||||
|
||||
SpiffeChannelSecurityConnector::~SpiffeChannelSecurityConnector() {
|
||||
if (target_name_ != nullptr) {
|
||||
gpr_free(target_name_);
|
||||
}
|
||||
if (overridden_target_name_ != nullptr) {
|
||||
gpr_free(overridden_target_name_);
|
||||
}
|
||||
if (client_handshaker_factory_ != nullptr) {
|
||||
tsi_ssl_client_handshaker_factory_unref(client_handshaker_factory_);
|
||||
}
|
||||
|
|
@ -130,8 +125,8 @@ void SpiffeChannelSecurityConnector::add_handshakers(
|
|||
tsi_handshaker* tsi_hs = nullptr;
|
||||
tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker(
|
||||
client_handshaker_factory_,
|
||||
overridden_target_name_ != nullptr ? overridden_target_name_
|
||||
: target_name_,
|
||||
overridden_target_name_ != nullptr ? overridden_target_name_.get()
|
||||
: target_name_.get(),
|
||||
&tsi_hs);
|
||||
if (result != TSI_OK) {
|
||||
gpr_log(GPR_ERROR, "Handshaker creation failed with error %s.",
|
||||
|
|
@ -147,8 +142,8 @@ void SpiffeChannelSecurityConnector::check_peer(
|
|||
grpc_core::RefCountedPtr<grpc_auth_context>* auth_context,
|
||||
grpc_closure* on_peer_checked) {
|
||||
const char* target_name = overridden_target_name_ != nullptr
|
||||
? overridden_target_name_
|
||||
: target_name_;
|
||||
? overridden_target_name_.get()
|
||||
: target_name_.get();
|
||||
grpc_error* error = grpc_ssl_check_alpn(&peer);
|
||||
if (error != GRPC_ERROR_NONE) {
|
||||
GRPC_CLOSURE_SCHED(on_peer_checked, error);
|
||||
|
|
@ -203,16 +198,17 @@ int SpiffeChannelSecurityConnector::cmp(
|
|||
if (c != 0) {
|
||||
return c;
|
||||
}
|
||||
return grpc_ssl_cmp_target_name(target_name_, other->target_name_,
|
||||
overridden_target_name_,
|
||||
other->overridden_target_name_);
|
||||
return grpc_ssl_cmp_target_name(target_name_.get(), other->target_name_.get(),
|
||||
overridden_target_name_.get(),
|
||||
other->overridden_target_name_.get());
|
||||
}
|
||||
|
||||
bool SpiffeChannelSecurityConnector::check_call_host(
|
||||
const char* host, grpc_auth_context* auth_context,
|
||||
grpc_core::StringView host, grpc_auth_context* auth_context,
|
||||
grpc_closure* on_call_host_checked, grpc_error** error) {
|
||||
return grpc_ssl_check_call_host(host, target_name_, overridden_target_name_,
|
||||
auth_context, on_call_host_checked, error);
|
||||
return grpc_ssl_check_call_host(host, target_name_.get(),
|
||||
overridden_target_name_.get(), auth_context,
|
||||
on_call_host_checked, error);
|
||||
}
|
||||
|
||||
void SpiffeChannelSecurityConnector::cancel_check_call_host(
|
||||
|
|
|
|||
|
|
@ -53,7 +53,8 @@ class SpiffeChannelSecurityConnector final
|
|||
|
||||
int cmp(const grpc_security_connector* other_sc) const override;
|
||||
|
||||
bool check_call_host(const char* host, grpc_auth_context* auth_context,
|
||||
bool check_call_host(grpc_core::StringView host,
|
||||
grpc_auth_context* auth_context,
|
||||
grpc_closure* on_call_host_checked,
|
||||
grpc_error** error) override;
|
||||
|
||||
|
|
@ -83,8 +84,8 @@ class SpiffeChannelSecurityConnector final
|
|||
grpc_tls_server_authorization_check_arg* arg);
|
||||
|
||||
grpc_closure* on_peer_checked_;
|
||||
char* target_name_;
|
||||
char* overridden_target_name_;
|
||||
grpc_core::UniquePtr<char> target_name_;
|
||||
grpc_core::UniquePtr<char> overridden_target_name_;
|
||||
tsi_ssl_client_handshaker_factory* client_handshaker_factory_ = nullptr;
|
||||
grpc_tls_server_authorization_check_arg* check_arg_;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -346,7 +346,7 @@ static void auth_start_transport_stream_op_batch(
|
|||
GRPC_CALL_STACK_REF(calld->owning_call, "check_call_host");
|
||||
GRPC_CLOSURE_INIT(&calld->async_result_closure, on_host_checked, batch,
|
||||
grpc_schedule_on_exec_ctx);
|
||||
char* call_host = grpc_slice_to_c_string(calld->host);
|
||||
grpc_core::StringView call_host(calld->host);
|
||||
grpc_error* error = GRPC_ERROR_NONE;
|
||||
if (chand->security_connector->check_call_host(
|
||||
call_host, chand->auth_context.get(),
|
||||
|
|
@ -360,7 +360,6 @@ static void auth_start_transport_stream_op_batch(
|
|||
&calld->check_call_host_cancel_closure, cancel_check_call_host,
|
||||
elem, grpc_schedule_on_exec_ctx));
|
||||
}
|
||||
gpr_free(call_host);
|
||||
return; /* early exit */
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@
|
|||
#include <grpc/support/sync.h>
|
||||
#include <grpc/support/thd_id.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/thd.h"
|
||||
#include "src/core/lib/iomgr/closure.h"
|
||||
#include "src/core/lib/slice/slice_internal.h"
|
||||
|
|
|
|||
|
|
@ -233,11 +233,10 @@ static void ssl_info_callback(const SSL* ssl, int where, int ret) {
|
|||
|
||||
/* Returns 1 if name looks like an IP address, 0 otherwise.
|
||||
This is a very rough heuristic, and only handles IPv6 in hexadecimal form. */
|
||||
static int looks_like_ip_address(const char* name) {
|
||||
size_t i;
|
||||
static int looks_like_ip_address(grpc_core::StringView name) {
|
||||
size_t dot_count = 0;
|
||||
size_t num_size = 0;
|
||||
for (i = 0; i < strlen(name); i++) {
|
||||
for (size_t i = 0; i < name.size(); ++i) {
|
||||
if (name[i] == ':') {
|
||||
/* IPv6 Address in hexadecimal form, : is not allowed in DNS names. */
|
||||
return 1;
|
||||
|
|
@ -1506,52 +1505,46 @@ static void tsi_ssl_server_handshaker_factory_destroy(
|
|||
gpr_free(self);
|
||||
}
|
||||
|
||||
static int does_entry_match_name(const char* entry, size_t entry_length,
|
||||
const char* name) {
|
||||
const char* dot;
|
||||
const char* name_subdomain = nullptr;
|
||||
size_t name_length = strlen(name);
|
||||
size_t name_subdomain_length;
|
||||
if (entry_length == 0) return 0;
|
||||
static int does_entry_match_name(grpc_core::StringView entry,
|
||||
grpc_core::StringView name) {
|
||||
if (entry.empty()) return 0;
|
||||
|
||||
/* Take care of '.' terminations. */
|
||||
if (name[name_length - 1] == '.') {
|
||||
name_length--;
|
||||
if (name.back() == '.') {
|
||||
name.remove_suffix(1);
|
||||
}
|
||||
if (entry[entry_length - 1] == '.') {
|
||||
entry_length--;
|
||||
if (entry_length == 0) return 0;
|
||||
if (entry.back() == '.') {
|
||||
entry.remove_suffix(1);
|
||||
if (entry.empty()) return 0;
|
||||
}
|
||||
|
||||
if ((name_length == entry_length) &&
|
||||
strncmp(name, entry, entry_length) == 0) {
|
||||
if (name == entry) {
|
||||
return 1; /* Perfect match. */
|
||||
}
|
||||
if (entry[0] != '*') return 0;
|
||||
if (entry.front() != '*') return 0;
|
||||
|
||||
/* Wildchar subdomain matching. */
|
||||
if (entry_length < 3 || entry[1] != '.') { /* At least *.x */
|
||||
if (entry.size() < 3 || entry[1] != '.') { /* At least *.x */
|
||||
gpr_log(GPR_ERROR, "Invalid wildchar entry.");
|
||||
return 0;
|
||||
}
|
||||
name_subdomain = strchr(name, '.');
|
||||
if (name_subdomain == nullptr) return 0;
|
||||
name_subdomain_length = strlen(name_subdomain);
|
||||
if (name_subdomain_length < 2) return 0;
|
||||
name_subdomain++; /* Starts after the dot. */
|
||||
name_subdomain_length--;
|
||||
entry += 2; /* Remove *. */
|
||||
entry_length -= 2;
|
||||
dot = strchr(name_subdomain, '.');
|
||||
if ((dot == nullptr) || (dot == &name_subdomain[name_subdomain_length - 1])) {
|
||||
gpr_log(GPR_ERROR, "Invalid toplevel subdomain: %s", name_subdomain);
|
||||
size_t name_subdomain_pos = name.find('.');
|
||||
if (name_subdomain_pos == grpc_core::StringView::npos) return 0;
|
||||
if (name_subdomain_pos >= name.size() - 2) return 0;
|
||||
grpc_core::StringView name_subdomain =
|
||||
name.substr(name_subdomain_pos + 1); /* Starts after the dot. */
|
||||
entry.remove_prefix(2); /* Remove *. */
|
||||
size_t dot = name_subdomain.find('.');
|
||||
if (dot == grpc_core::StringView::npos || dot == name_subdomain.size() - 1) {
|
||||
grpc_core::UniquePtr<char> name_subdomain_cstr(name_subdomain.dup());
|
||||
gpr_log(GPR_ERROR, "Invalid toplevel subdomain: %s",
|
||||
name_subdomain_cstr.get());
|
||||
return 0;
|
||||
}
|
||||
if (name_subdomain[name_subdomain_length - 1] == '.') {
|
||||
name_subdomain_length--;
|
||||
if (name_subdomain.back() == '.') {
|
||||
name_subdomain.remove_suffix(1);
|
||||
}
|
||||
return ((entry_length > 0) && (name_subdomain_length == entry_length) &&
|
||||
strncmp(entry, name_subdomain, entry_length) == 0);
|
||||
return !entry.empty() && name_subdomain == entry;
|
||||
}
|
||||
|
||||
static int ssl_server_handshaker_factory_servername_callback(SSL* ssl, int* ap,
|
||||
|
|
@ -1919,7 +1912,8 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options(
|
|||
|
||||
/* --- tsi_ssl utils. --- */
|
||||
|
||||
int tsi_ssl_peer_matches_name(const tsi_peer* peer, const char* name) {
|
||||
int tsi_ssl_peer_matches_name(const tsi_peer* peer,
|
||||
grpc_core::StringView name) {
|
||||
size_t i = 0;
|
||||
size_t san_count = 0;
|
||||
const tsi_peer_property* cn_property = nullptr;
|
||||
|
|
@ -1933,13 +1927,10 @@ int tsi_ssl_peer_matches_name(const tsi_peer* peer, const char* name) {
|
|||
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY) == 0) {
|
||||
san_count++;
|
||||
|
||||
if (!like_ip && does_entry_match_name(property->value.data,
|
||||
property->value.length, name)) {
|
||||
grpc_core::StringView entry(property->value.data, property->value.length);
|
||||
if (!like_ip && does_entry_match_name(entry, name)) {
|
||||
return 1;
|
||||
} else if (like_ip &&
|
||||
strncmp(name, property->value.data, property->value.length) ==
|
||||
0 &&
|
||||
strlen(name) == property->value.length) {
|
||||
} else if (like_ip && name == entry) {
|
||||
/* IP Addresses are exact matches only. */
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -1951,8 +1942,9 @@ int tsi_ssl_peer_matches_name(const tsi_peer* peer, const char* name) {
|
|||
|
||||
/* If there's no SAN, try the CN, but only if its not like an IP Address */
|
||||
if (san_count == 0 && cn_property != nullptr && !like_ip) {
|
||||
if (does_entry_match_name(cn_property->value.data,
|
||||
cn_property->value.length, name)) {
|
||||
if (does_entry_match_name(grpc_core::StringView(cn_property->value.data,
|
||||
cn_property->value.length),
|
||||
name)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <grpc/support/port_platform.h>
|
||||
|
||||
#include "src/core/lib/gprpp/string_view.h"
|
||||
#include "src/core/tsi/transport_security_interface.h"
|
||||
|
||||
/* Value for the TSI_CERTIFICATE_TYPE_PEER_PROPERTY property for X509 certs. */
|
||||
|
|
@ -306,7 +307,7 @@ void tsi_ssl_server_handshaker_factory_unref(
|
|||
- handle mixed case.
|
||||
- handle %encoded chars.
|
||||
- handle public suffix wildchar more strictly (e.g. *.co.uk) */
|
||||
int tsi_ssl_peer_matches_name(const tsi_peer* peer, const char* name);
|
||||
int tsi_ssl_peer_matches_name(const tsi_peer* peer, grpc_core::StringView name);
|
||||
|
||||
/* --- Testing support. ---
|
||||
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@
|
|||
#include <grpc/support/log.h>
|
||||
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gpr/tmpfile.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/security/credentials/credentials.h"
|
||||
#include "src/core/lib/security/security_connector/ssl_utils.h"
|
||||
#include "test/core/end2end/data/ssl_test_data.h"
|
||||
|
|
@ -51,19 +51,18 @@
|
|||
|
||||
#import "../ConfigureCronet.h"
|
||||
|
||||
typedef struct fullstack_secure_fixture_data {
|
||||
char *localaddr;
|
||||
} fullstack_secure_fixture_data;
|
||||
struct fullstack_secure_fixture_data {
|
||||
grpc_core::UniquePtr<char> localaddr;
|
||||
};
|
||||
|
||||
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
|
||||
grpc_channel_args *client_args, grpc_channel_args *server_args) {
|
||||
grpc_end2end_test_fixture f;
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
fullstack_secure_fixture_data *ffd =
|
||||
(fullstack_secure_fixture_data *)gpr_malloc(sizeof(fullstack_secure_fixture_data));
|
||||
fullstack_secure_fixture_data *ffd = grpc_core::New<fullstack_secure_fixture_data>();
|
||||
memset(&f, 0, sizeof(f));
|
||||
|
||||
gpr_join_host_port(&ffd->localaddr, "127.0.0.1", port);
|
||||
grpc_core::JoinHostPort(&ffd->localaddr, "127.0.0.1", port);
|
||||
|
||||
f.fixture_data = ffd;
|
||||
f.cq = grpc_completion_queue_create_for_next(NULL);
|
||||
|
|
@ -83,7 +82,8 @@ static void cronet_init_client_secure_fullstack(grpc_end2end_test_fixture *f,
|
|||
grpc_channel_args *client_args,
|
||||
stream_engine *cronetEngine) {
|
||||
fullstack_secure_fixture_data *ffd = (fullstack_secure_fixture_data *)f->fixture_data;
|
||||
f->client = grpc_cronet_secure_channel_create(cronetEngine, ffd->localaddr, client_args, NULL);
|
||||
f->client =
|
||||
grpc_cronet_secure_channel_create(cronetEngine, ffd->localaddr.get(), client_args, NULL);
|
||||
GPR_ASSERT(f->client != NULL);
|
||||
}
|
||||
|
||||
|
|
@ -96,15 +96,14 @@ static void chttp2_init_server_secure_fullstack(grpc_end2end_test_fixture *f,
|
|||
}
|
||||
f->server = grpc_server_create(server_args, NULL);
|
||||
grpc_server_register_completion_queue(f->server, f->cq, NULL);
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr, server_creds));
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr.get(), server_creds));
|
||||
grpc_server_credentials_release(server_creds);
|
||||
grpc_server_start(f->server);
|
||||
}
|
||||
|
||||
static void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) {
|
||||
fullstack_secure_fixture_data *ffd = (fullstack_secure_fixture_data *)f->fixture_data;
|
||||
gpr_free(ffd->localaddr);
|
||||
gpr_free(ffd);
|
||||
grpc_core::Delete(ffd);
|
||||
}
|
||||
|
||||
static void cronet_init_client_simple_ssl_secure_fullstack(grpc_end2end_test_fixture *f,
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@
|
|||
|
||||
#import "src/core/lib/channel/channel_args.h"
|
||||
#import "src/core/lib/gpr/env.h"
|
||||
#import "src/core/lib/gpr/host_port.h"
|
||||
#import "src/core/lib/gpr/string.h"
|
||||
#import "src/core/lib/gpr/tmpfile.h"
|
||||
#import "src/core/lib/gprpp/host_port.h"
|
||||
#import "test/core/end2end/data/ssl_test_data.h"
|
||||
#import "test/core/util/test_config.h"
|
||||
|
||||
|
|
@ -133,11 +133,11 @@ unsigned int parse_h2_length(const char *field) {
|
|||
{{NULL, NULL, NULL, NULL}}}};
|
||||
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
char *addr;
|
||||
gpr_join_host_port(&addr, "127.0.0.1", port);
|
||||
grpc_core::UniquePtr<char> addr;
|
||||
grpc_core::JoinHostPort(&addr, "127.0.0.1", port);
|
||||
grpc_completion_queue *cq = grpc_completion_queue_create_for_next(NULL);
|
||||
stream_engine *cronetEngine = [Cronet getGlobalEngine];
|
||||
grpc_channel *client = grpc_cronet_secure_channel_create(cronetEngine, addr, NULL, NULL);
|
||||
grpc_channel *client = grpc_cronet_secure_channel_create(cronetEngine, addr.get(), NULL, NULL);
|
||||
|
||||
cq_verifier *cqv = cq_verifier_create(cq);
|
||||
grpc_op ops[6];
|
||||
|
|
@ -264,11 +264,11 @@ unsigned int parse_h2_length(const char *field) {
|
|||
{{NULL, NULL, NULL, NULL}}}};
|
||||
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
char *addr;
|
||||
gpr_join_host_port(&addr, "127.0.0.1", port);
|
||||
grpc_core::UniquePtr<char> addr;
|
||||
grpc_core::JoinHostPort(&addr, "127.0.0.1", port);
|
||||
grpc_completion_queue *cq = grpc_completion_queue_create_for_next(NULL);
|
||||
stream_engine *cronetEngine = [Cronet getGlobalEngine];
|
||||
grpc_channel *client = grpc_cronet_secure_channel_create(cronetEngine, addr, args, NULL);
|
||||
grpc_channel *client = grpc_cronet_secure_channel_create(cronetEngine, addr.get(), args, NULL);
|
||||
|
||||
cq_verifier *cqv = cq_verifier_create(cq);
|
||||
grpc_op ops[6];
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ CORE_SOURCE_FILES = [
|
|||
'src/core/lib/gpr/env_linux.cc',
|
||||
'src/core/lib/gpr/env_posix.cc',
|
||||
'src/core/lib/gpr/env_windows.cc',
|
||||
'src/core/lib/gpr/host_port.cc',
|
||||
'src/core/lib/gpr/log.cc',
|
||||
'src/core/lib/gpr/log_android.cc',
|
||||
'src/core/lib/gpr/log_linux.cc',
|
||||
|
|
@ -54,6 +53,7 @@ CORE_SOURCE_FILES = [
|
|||
'src/core/lib/gprpp/arena.cc',
|
||||
'src/core/lib/gprpp/fork.cc',
|
||||
'src/core/lib/gprpp/global_config_env.cc',
|
||||
'src/core/lib/gprpp/host_port.cc',
|
||||
'src/core/lib/gprpp/thd_posix.cc',
|
||||
'src/core/lib/gprpp/thd_windows.cc',
|
||||
'src/core/lib/profiling/basic_timers.cc',
|
||||
|
|
|
|||
|
|
@ -25,8 +25,9 @@
|
|||
#include <grpc/support/log.h>
|
||||
#include <grpc/support/string_util.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/gprpp/memory.h"
|
||||
#include "src/core/lib/security/security_connector/ssl_utils.h"
|
||||
#include "test/core/end2end/cq_verifier.h"
|
||||
#include "test/core/util/port.h"
|
||||
|
|
@ -144,7 +145,9 @@ int main(int argc, char** argv) {
|
|||
gpr_asprintf(&args[0], "%s/bad_ssl_%s_server%s", root, test,
|
||||
gpr_subprocess_binary_extension());
|
||||
args[1] = const_cast<char*>("--bind");
|
||||
gpr_join_host_port(&args[2], "::", port);
|
||||
grpc_core::UniquePtr<char> joined;
|
||||
grpc_core::JoinHostPort(&joined, "::", port);
|
||||
args[2] = joined.get();
|
||||
svr = gpr_subprocess_create(4, (const char**)args);
|
||||
gpr_free(args[0]);
|
||||
|
||||
|
|
@ -153,7 +156,6 @@ int main(int argc, char** argv) {
|
|||
run_test(args[2], i);
|
||||
grpc_shutdown();
|
||||
}
|
||||
gpr_free(args[2]);
|
||||
|
||||
gpr_subprocess_interrupt(svr);
|
||||
status = gpr_subprocess_join(svr);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@
|
|||
#include <grpc/support/log.h>
|
||||
#include <grpc/support/string_util.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/gprpp/memory.h"
|
||||
#include "src/core/lib/iomgr/exec_ctx.h"
|
||||
#include "src/core/lib/iomgr/socket_utils.h"
|
||||
#include "test/core/util/test_config.h"
|
||||
|
|
@ -60,20 +61,20 @@ static void test_grpc_parse_ipv6_parity_with_getaddrinfo(
|
|||
|
||||
struct sockaddr_in6 resolve_with_gettaddrinfo(const char* uri_text) {
|
||||
grpc_uri* uri = grpc_uri_parse(uri_text, 0);
|
||||
char* host = nullptr;
|
||||
char* port = nullptr;
|
||||
gpr_split_host_port(uri->path, &host, &port);
|
||||
grpc_core::UniquePtr<char> host;
|
||||
grpc_core::UniquePtr<char> port;
|
||||
grpc_core::SplitHostPort(uri->path, &host, &port);
|
||||
struct addrinfo hints;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_INET6;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
struct addrinfo* result;
|
||||
int res = getaddrinfo(host, port, &hints, &result);
|
||||
int res = getaddrinfo(host.get(), port.get(), &hints, &result);
|
||||
if (res != 0) {
|
||||
gpr_log(GPR_ERROR,
|
||||
"getaddrinfo failed to resolve host:%s port:%s. Error: %d.", host,
|
||||
port, res);
|
||||
"getaddrinfo failed to resolve host:%s port:%s. Error: %d.",
|
||||
host.get(), port.get(), res);
|
||||
abort();
|
||||
}
|
||||
size_t num_addrs_from_getaddrinfo = 0;
|
||||
|
|
@ -86,8 +87,6 @@ struct sockaddr_in6 resolve_with_gettaddrinfo(const char* uri_text) {
|
|||
*reinterpret_cast<struct sockaddr_in6*>(result->ai_addr);
|
||||
// Cleanup
|
||||
freeaddrinfo(result);
|
||||
gpr_free(host);
|
||||
gpr_free(port);
|
||||
grpc_uri_destroy(uri);
|
||||
return out;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@
|
|||
#include <grpc/support/alloc.h>
|
||||
#include <grpc/support/log.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/gprpp/memory.h"
|
||||
#include "src/core/lib/gprpp/thd.h"
|
||||
#include "src/core/lib/iomgr/sockaddr.h"
|
||||
|
|
@ -71,7 +71,7 @@
|
|||
#define SERVER_INCOMING_DATA_LENGTH_LOWER_THRESHOLD (size_t)200
|
||||
|
||||
struct rpc_state {
|
||||
char* target;
|
||||
grpc_core::UniquePtr<char> target;
|
||||
grpc_completion_queue* cq;
|
||||
grpc_channel* channel;
|
||||
grpc_call* call;
|
||||
|
|
@ -165,8 +165,9 @@ static void start_rpc(int target_port, grpc_status_code expected_status,
|
|||
|
||||
state.cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
cqv = cq_verifier_create(state.cq);
|
||||
gpr_join_host_port(&state.target, "127.0.0.1", target_port);
|
||||
state.channel = grpc_insecure_channel_create(state.target, nullptr, nullptr);
|
||||
grpc_core::JoinHostPort(&state.target, "127.0.0.1", target_port);
|
||||
state.channel =
|
||||
grpc_insecure_channel_create(state.target.get(), nullptr, nullptr);
|
||||
grpc_slice host = grpc_slice_from_static_string("localhost");
|
||||
state.call = grpc_channel_create_call(
|
||||
state.channel, nullptr, GRPC_PROPAGATE_DEFAULTS, state.cq,
|
||||
|
|
@ -230,7 +231,7 @@ static void cleanup_rpc() {
|
|||
} while (ev.type != GRPC_QUEUE_SHUTDOWN);
|
||||
grpc_completion_queue_destroy(state.cq);
|
||||
grpc_channel_destroy(state.channel);
|
||||
gpr_free(state.target);
|
||||
state.target.reset();
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#include <grpc/support/string_util.h>
|
||||
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/iomgr/exec_ctx.h"
|
||||
#include "src/core/lib/slice/slice_internal.h"
|
||||
#include "src/core/lib/transport/metadata.h"
|
||||
|
|
@ -77,10 +77,10 @@ static void run_test(bool wait_for_ready, bool use_service_config) {
|
|||
|
||||
/* create a call, channel to a port which will refuse connection */
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
char* addr;
|
||||
gpr_join_host_port(&addr, "127.0.0.1", port);
|
||||
gpr_log(GPR_INFO, "server: %s", addr);
|
||||
chan = grpc_insecure_channel_create(addr, args, nullptr);
|
||||
grpc_core::UniquePtr<char> addr;
|
||||
grpc_core::JoinHostPort(&addr, "127.0.0.1", port);
|
||||
gpr_log(GPR_INFO, "server: %s", addr.get());
|
||||
chan = grpc_insecure_channel_create(addr.get(), args, nullptr);
|
||||
grpc_slice host = grpc_slice_from_static_string("nonexistant");
|
||||
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(2);
|
||||
call =
|
||||
|
|
@ -88,8 +88,6 @@ static void run_test(bool wait_for_ready, bool use_service_config) {
|
|||
grpc_slice_from_static_string("/service/method"),
|
||||
&host, deadline, nullptr);
|
||||
|
||||
gpr_free(addr);
|
||||
|
||||
memset(ops, 0, sizeof(ops));
|
||||
op = ops;
|
||||
op->op = GRPC_OP_SEND_INITIAL_METADATA;
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@
|
|||
#include <grpc/support/log.h>
|
||||
#include <grpc/support/string_util.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/iomgr/error.h"
|
||||
#include "src/core/lib/iomgr/resolve_address.h"
|
||||
#include "src/core/lib/iomgr/sockaddr_utils.h"
|
||||
|
|
@ -70,8 +70,6 @@ static void log_resolved_addrs(const char* label, const char* hostname) {
|
|||
|
||||
void test_connect(const char* server_host, const char* client_host, int port,
|
||||
int expect_ok) {
|
||||
char* client_hostport;
|
||||
char* server_hostport;
|
||||
grpc_channel* client;
|
||||
grpc_server* server;
|
||||
grpc_completion_queue* cq;
|
||||
|
|
@ -99,7 +97,8 @@ void test_connect(const char* server_host, const char* client_host, int port,
|
|||
picked_port = 1;
|
||||
}
|
||||
|
||||
gpr_join_host_port(&server_hostport, server_host, port);
|
||||
grpc_core::UniquePtr<char> server_hostport;
|
||||
grpc_core::JoinHostPort(&server_hostport, server_host, port);
|
||||
|
||||
grpc_metadata_array_init(&initial_metadata_recv);
|
||||
grpc_metadata_array_init(&trailing_metadata_recv);
|
||||
|
|
@ -111,7 +110,7 @@ void test_connect(const char* server_host, const char* client_host, int port,
|
|||
server = grpc_server_create(nullptr, nullptr);
|
||||
grpc_server_register_completion_queue(server, cq, nullptr);
|
||||
GPR_ASSERT((got_port = grpc_server_add_insecure_http2_port(
|
||||
server, server_hostport)) > 0);
|
||||
server, server_hostport.get())) > 0);
|
||||
if (port == 0) {
|
||||
port = got_port;
|
||||
} else {
|
||||
|
|
@ -121,6 +120,7 @@ void test_connect(const char* server_host, const char* client_host, int port,
|
|||
cqv = cq_verifier_create(cq);
|
||||
|
||||
/* Create client. */
|
||||
grpc_core::UniquePtr<char> client_hostport;
|
||||
if (client_host[0] == 'i') {
|
||||
/* for ipv4:/ipv6: addresses, concatenate the port to each of the parts */
|
||||
size_t i;
|
||||
|
|
@ -139,8 +139,8 @@ void test_connect(const char* server_host, const char* client_host, int port,
|
|||
gpr_asprintf(&hosts_with_port[i], "%s:%d", uri_part_str, port);
|
||||
gpr_free(uri_part_str);
|
||||
}
|
||||
client_hostport = gpr_strjoin_sep((const char**)hosts_with_port,
|
||||
uri_parts.count, ",", nullptr);
|
||||
client_hostport.reset(gpr_strjoin_sep((const char**)hosts_with_port,
|
||||
uri_parts.count, ",", nullptr));
|
||||
for (i = 0; i < uri_parts.count; i++) {
|
||||
gpr_free(hosts_with_port[i]);
|
||||
}
|
||||
|
|
@ -148,18 +148,17 @@ void test_connect(const char* server_host, const char* client_host, int port,
|
|||
grpc_slice_buffer_destroy(&uri_parts);
|
||||
grpc_slice_unref(uri_slice);
|
||||
} else {
|
||||
gpr_join_host_port(&client_hostport, client_host, port);
|
||||
grpc_core::JoinHostPort(&client_hostport, client_host, port);
|
||||
}
|
||||
client = grpc_insecure_channel_create(client_hostport, nullptr, nullptr);
|
||||
client =
|
||||
grpc_insecure_channel_create(client_hostport.get(), nullptr, nullptr);
|
||||
|
||||
gpr_log(GPR_INFO, "Testing with server=%s client=%s (expecting %s)",
|
||||
server_hostport, client_hostport, expect_ok ? "success" : "failure");
|
||||
server_hostport.get(), client_hostport.get(),
|
||||
expect_ok ? "success" : "failure");
|
||||
log_resolved_addrs("server resolved addr", server_host);
|
||||
log_resolved_addrs("client resolved addr", client_host);
|
||||
|
||||
gpr_free(client_hostport);
|
||||
gpr_free(server_hostport);
|
||||
|
||||
if (expect_ok) {
|
||||
/* Normal deadline, shouldn't be reached. */
|
||||
deadline = grpc_timeout_milliseconds_to_deadline(60000);
|
||||
|
|
|
|||
|
|
@ -29,25 +29,23 @@
|
|||
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/channel/connected_channel.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/surface/channel.h"
|
||||
#include "src/core/lib/surface/server.h"
|
||||
#include "test/core/util/port.h"
|
||||
#include "test/core/util/test_config.h"
|
||||
|
||||
typedef struct fullstack_fixture_data {
|
||||
char* localaddr;
|
||||
} fullstack_fixture_data;
|
||||
struct fullstack_fixture_data {
|
||||
grpc_core::UniquePtr<char> localaddr;
|
||||
};
|
||||
|
||||
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
|
||||
grpc_channel_args* client_args, grpc_channel_args* server_args) {
|
||||
grpc_end2end_test_fixture f;
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
|
||||
gpr_malloc(sizeof(fullstack_fixture_data)));
|
||||
fullstack_fixture_data* ffd = grpc_core::New<fullstack_fixture_data>();
|
||||
memset(&f, 0, sizeof(f));
|
||||
|
||||
gpr_join_host_port(&ffd->localaddr, "localhost", port);
|
||||
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
|
||||
|
||||
f.fixture_data = ffd;
|
||||
f.cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
|
|
@ -71,7 +69,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
|
|||
grpc_arg arg = make_census_enable_arg();
|
||||
client_args = grpc_channel_args_copy_and_add(client_args, &arg, 1);
|
||||
f->client =
|
||||
grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr);
|
||||
grpc_insecure_channel_create(ffd->localaddr.get(), client_args, nullptr);
|
||||
GPR_ASSERT(f->client);
|
||||
{
|
||||
grpc_core::ExecCtx exec_ctx;
|
||||
|
|
@ -94,15 +92,15 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
|
|||
grpc_channel_args_destroy(server_args);
|
||||
}
|
||||
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
|
||||
GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
|
||||
GPR_ASSERT(
|
||||
grpc_server_add_insecure_http2_port(f->server, ffd->localaddr.get()));
|
||||
grpc_server_start(f->server);
|
||||
}
|
||||
|
||||
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
|
||||
fullstack_fixture_data* ffd =
|
||||
static_cast<fullstack_fixture_data*>(f->fixture_data);
|
||||
gpr_free(ffd->localaddr);
|
||||
gpr_free(ffd);
|
||||
grpc_core::Delete(ffd);
|
||||
}
|
||||
|
||||
/* All test configurations */
|
||||
|
|
|
|||
|
|
@ -30,28 +30,29 @@
|
|||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/channel/connected_channel.h"
|
||||
#include "src/core/lib/compression/compression_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/surface/channel.h"
|
||||
#include "src/core/lib/surface/server.h"
|
||||
#include "test/core/util/port.h"
|
||||
#include "test/core/util/test_config.h"
|
||||
|
||||
typedef struct fullstack_compression_fixture_data {
|
||||
char* localaddr;
|
||||
grpc_channel_args* client_args_compression;
|
||||
grpc_channel_args* server_args_compression;
|
||||
} fullstack_compression_fixture_data;
|
||||
struct fullstack_compression_fixture_data {
|
||||
~fullstack_compression_fixture_data() {
|
||||
grpc_channel_args_destroy(client_args_compression);
|
||||
grpc_channel_args_destroy(server_args_compression);
|
||||
}
|
||||
grpc_core::UniquePtr<char> localaddr;
|
||||
grpc_channel_args* client_args_compression = nullptr;
|
||||
grpc_channel_args* server_args_compression = nullptr;
|
||||
};
|
||||
|
||||
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_compression(
|
||||
grpc_channel_args* client_args, grpc_channel_args* server_args) {
|
||||
grpc_end2end_test_fixture f;
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
fullstack_compression_fixture_data* ffd =
|
||||
static_cast<fullstack_compression_fixture_data*>(
|
||||
gpr_malloc(sizeof(fullstack_compression_fixture_data)));
|
||||
memset(ffd, 0, sizeof(fullstack_compression_fixture_data));
|
||||
|
||||
gpr_join_host_port(&ffd->localaddr, "localhost", port);
|
||||
grpc_core::New<fullstack_compression_fixture_data>();
|
||||
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
|
||||
|
||||
memset(&f, 0, sizeof(f));
|
||||
f.fixture_data = ffd;
|
||||
|
|
@ -73,7 +74,7 @@ void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture* f,
|
|||
grpc_channel_args_set_channel_default_compression_algorithm(
|
||||
client_args, GRPC_COMPRESS_GZIP);
|
||||
f->client = grpc_insecure_channel_create(
|
||||
ffd->localaddr, ffd->client_args_compression, nullptr);
|
||||
ffd->localaddr.get(), ffd->client_args_compression, nullptr);
|
||||
}
|
||||
|
||||
void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f,
|
||||
|
|
@ -92,7 +93,8 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f,
|
|||
}
|
||||
f->server = grpc_server_create(ffd->server_args_compression, nullptr);
|
||||
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
|
||||
GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
|
||||
GPR_ASSERT(
|
||||
grpc_server_add_insecure_http2_port(f->server, ffd->localaddr.get()));
|
||||
grpc_server_start(f->server);
|
||||
}
|
||||
|
||||
|
|
@ -100,10 +102,7 @@ void chttp2_tear_down_fullstack_compression(grpc_end2end_test_fixture* f) {
|
|||
grpc_core::ExecCtx exec_ctx;
|
||||
fullstack_compression_fixture_data* ffd =
|
||||
static_cast<fullstack_compression_fixture_data*>(f->fixture_data);
|
||||
grpc_channel_args_destroy(ffd->client_args_compression);
|
||||
grpc_channel_args_destroy(ffd->server_args_compression);
|
||||
gpr_free(ffd->localaddr);
|
||||
gpr_free(ffd);
|
||||
grpc_core::Delete(ffd);
|
||||
}
|
||||
|
||||
/* All test configurations */
|
||||
|
|
|
|||
|
|
@ -25,26 +25,24 @@
|
|||
#include <grpc/support/log.h>
|
||||
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/security/credentials/fake/fake_credentials.h"
|
||||
#include "test/core/end2end/data/ssl_test_data.h"
|
||||
#include "test/core/util/port.h"
|
||||
#include "test/core/util/test_config.h"
|
||||
|
||||
typedef struct fullstack_secure_fixture_data {
|
||||
char* localaddr;
|
||||
} fullstack_secure_fixture_data;
|
||||
struct fullstack_secure_fixture_data {
|
||||
grpc_core::UniquePtr<char> localaddr;
|
||||
};
|
||||
|
||||
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
|
||||
grpc_channel_args* client_args, grpc_channel_args* server_args) {
|
||||
grpc_end2end_test_fixture f;
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(
|
||||
gpr_malloc(sizeof(fullstack_secure_fixture_data)));
|
||||
|
||||
grpc_core::New<fullstack_secure_fixture_data>();
|
||||
memset(&f, 0, sizeof(f));
|
||||
gpr_join_host_port(&ffd->localaddr, "localhost", port);
|
||||
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
|
||||
|
||||
f.fixture_data = ffd;
|
||||
f.cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
|
|
@ -66,8 +64,8 @@ static void chttp2_init_client_secure_fullstack(
|
|||
grpc_channel_credentials* creds) {
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
|
||||
f->client =
|
||||
grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr);
|
||||
f->client = grpc_secure_channel_create(creds, ffd->localaddr.get(),
|
||||
client_args, nullptr);
|
||||
GPR_ASSERT(f->client != nullptr);
|
||||
grpc_channel_credentials_release(creds);
|
||||
}
|
||||
|
|
@ -82,7 +80,7 @@ static void chttp2_init_server_secure_fullstack(
|
|||
}
|
||||
f->server = grpc_server_create(server_args, nullptr);
|
||||
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr,
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr.get(),
|
||||
server_creds));
|
||||
grpc_server_credentials_release(server_creds);
|
||||
grpc_server_start(f->server);
|
||||
|
|
@ -91,8 +89,7 @@ static void chttp2_init_server_secure_fullstack(
|
|||
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
|
||||
gpr_free(ffd->localaddr);
|
||||
gpr_free(ffd);
|
||||
grpc_core::Delete(ffd);
|
||||
}
|
||||
|
||||
static void chttp2_init_client_fake_secure_fullstack(
|
||||
|
|
|
|||
|
|
@ -33,26 +33,25 @@
|
|||
#include "src/core/ext/filters/http/server/http_server_filter.h"
|
||||
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
|
||||
#include "src/core/lib/channel/connected_channel.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
|
||||
#include "src/core/lib/surface/channel.h"
|
||||
#include "src/core/lib/surface/server.h"
|
||||
#include "test/core/util/port.h"
|
||||
#include "test/core/util/test_config.h"
|
||||
|
||||
typedef struct fullstack_fixture_data {
|
||||
char* localaddr;
|
||||
} fullstack_fixture_data;
|
||||
struct fullstack_fixture_data {
|
||||
grpc_core::UniquePtr<char> localaddr;
|
||||
};
|
||||
|
||||
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
|
||||
grpc_channel_args* client_args, grpc_channel_args* server_args) {
|
||||
grpc_end2end_test_fixture f;
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
|
||||
gpr_malloc(sizeof(fullstack_fixture_data)));
|
||||
fullstack_fixture_data* ffd = grpc_core::New<fullstack_fixture_data>();
|
||||
memset(&f, 0, sizeof(f));
|
||||
|
||||
gpr_join_host_port(&ffd->localaddr, "localhost", port);
|
||||
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
|
||||
|
||||
f.fixture_data = ffd;
|
||||
f.cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
|
|
@ -66,7 +65,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
|
|||
fullstack_fixture_data* ffd =
|
||||
static_cast<fullstack_fixture_data*>(f->fixture_data);
|
||||
f->client =
|
||||
grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr);
|
||||
grpc_insecure_channel_create(ffd->localaddr.get(), client_args, nullptr);
|
||||
GPR_ASSERT(f->client);
|
||||
}
|
||||
|
||||
|
|
@ -79,15 +78,15 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
|
|||
}
|
||||
f->server = grpc_server_create(server_args, nullptr);
|
||||
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
|
||||
GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
|
||||
GPR_ASSERT(
|
||||
grpc_server_add_insecure_http2_port(f->server, ffd->localaddr.get()));
|
||||
grpc_server_start(f->server);
|
||||
}
|
||||
|
||||
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
|
||||
fullstack_fixture_data* ffd =
|
||||
static_cast<fullstack_fixture_data*>(f->fixture_data);
|
||||
gpr_free(ffd->localaddr);
|
||||
gpr_free(ffd);
|
||||
grpc_core::Delete(ffd);
|
||||
}
|
||||
|
||||
/* All test configurations */
|
||||
|
|
|
|||
|
|
@ -34,25 +34,24 @@
|
|||
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
|
||||
#include "src/core/lib/channel/connected_channel.h"
|
||||
#include "src/core/lib/debug/trace.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/surface/channel.h"
|
||||
#include "src/core/lib/surface/server.h"
|
||||
#include "test/core/util/port.h"
|
||||
#include "test/core/util/test_config.h"
|
||||
|
||||
typedef struct fullstack_fixture_data {
|
||||
char* localaddr;
|
||||
} fullstack_fixture_data;
|
||||
struct fullstack_fixture_data {
|
||||
grpc_core::UniquePtr<char> localaddr;
|
||||
};
|
||||
|
||||
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
|
||||
grpc_channel_args* client_args, grpc_channel_args* server_args) {
|
||||
grpc_end2end_test_fixture f;
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
|
||||
gpr_malloc(sizeof(fullstack_fixture_data)));
|
||||
fullstack_fixture_data* ffd = grpc_core::New<fullstack_fixture_data>();
|
||||
memset(&f, 0, sizeof(f));
|
||||
|
||||
gpr_join_host_port(&ffd->localaddr, "localhost", port);
|
||||
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
|
||||
|
||||
f.fixture_data = ffd;
|
||||
f.cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
|
|
@ -66,7 +65,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
|
|||
fullstack_fixture_data* ffd =
|
||||
static_cast<fullstack_fixture_data*>(f->fixture_data);
|
||||
f->client =
|
||||
grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr);
|
||||
grpc_insecure_channel_create(ffd->localaddr.get(), client_args, nullptr);
|
||||
GPR_ASSERT(f->client);
|
||||
}
|
||||
|
||||
|
|
@ -79,15 +78,15 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
|
|||
}
|
||||
f->server = grpc_server_create(server_args, nullptr);
|
||||
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
|
||||
GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
|
||||
GPR_ASSERT(
|
||||
grpc_server_add_insecure_http2_port(f->server, ffd->localaddr.get()));
|
||||
grpc_server_start(f->server);
|
||||
}
|
||||
|
||||
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
|
||||
fullstack_fixture_data* ffd =
|
||||
static_cast<fullstack_fixture_data*>(f->fixture_data);
|
||||
gpr_free(ffd->localaddr);
|
||||
gpr_free(ffd);
|
||||
grpc_core::Delete(ffd);
|
||||
}
|
||||
|
||||
/* All test configurations */
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
#include "src/core/ext/filters/http/server/http_server_filter.h"
|
||||
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
|
||||
#include "src/core/lib/channel/connected_channel.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/surface/channel.h"
|
||||
#include "src/core/lib/surface/server.h"
|
||||
#include "test/core/util/port.h"
|
||||
|
|
@ -39,24 +39,20 @@
|
|||
static char* workarounds_arg[GRPC_MAX_WORKAROUND_ID] = {
|
||||
const_cast<char*>(GRPC_ARG_WORKAROUND_CRONET_COMPRESSION)};
|
||||
|
||||
typedef struct fullstack_fixture_data {
|
||||
char* localaddr;
|
||||
} fullstack_fixture_data;
|
||||
struct fullstack_fixture_data {
|
||||
grpc_core::UniquePtr<char> localaddr;
|
||||
};
|
||||
|
||||
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
|
||||
grpc_channel_args* client_args, grpc_channel_args* server_args) {
|
||||
grpc_end2end_test_fixture f;
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
|
||||
gpr_malloc(sizeof(fullstack_fixture_data)));
|
||||
fullstack_fixture_data* ffd = grpc_core::New<fullstack_fixture_data>();
|
||||
memset(&f, 0, sizeof(f));
|
||||
|
||||
gpr_join_host_port(&ffd->localaddr, "localhost", port);
|
||||
|
||||
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
|
||||
f.fixture_data = ffd;
|
||||
f.cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +61,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
|
|||
fullstack_fixture_data* ffd =
|
||||
static_cast<fullstack_fixture_data*>(f->fixture_data);
|
||||
f->client =
|
||||
grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr);
|
||||
grpc_insecure_channel_create(ffd->localaddr.get(), client_args, nullptr);
|
||||
GPR_ASSERT(f->client);
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +84,8 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
|
|||
}
|
||||
f->server = grpc_server_create(server_args_new, nullptr);
|
||||
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
|
||||
GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
|
||||
GPR_ASSERT(
|
||||
grpc_server_add_insecure_http2_port(f->server, ffd->localaddr.get()));
|
||||
grpc_server_start(f->server);
|
||||
grpc_channel_args_destroy(server_args_new);
|
||||
}
|
||||
|
|
@ -96,8 +93,7 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
|
|||
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
|
||||
fullstack_fixture_data* ffd =
|
||||
static_cast<fullstack_fixture_data*>(f->fixture_data);
|
||||
gpr_free(ffd->localaddr);
|
||||
gpr_free(ffd);
|
||||
grpc_core::Delete(ffd);
|
||||
}
|
||||
|
||||
/* All test configurations */
|
||||
|
|
|
|||
|
|
@ -28,25 +28,24 @@
|
|||
#include "src/core/ext/filters/http/server/http_server_filter.h"
|
||||
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
|
||||
#include "src/core/lib/channel/connected_channel.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/surface/channel.h"
|
||||
#include "src/core/lib/surface/server.h"
|
||||
#include "test/core/util/port.h"
|
||||
#include "test/core/util/test_config.h"
|
||||
|
||||
typedef struct fullstack_fixture_data {
|
||||
char* localaddr;
|
||||
} fullstack_fixture_data;
|
||||
struct fullstack_fixture_data {
|
||||
grpc_core::UniquePtr<char> localaddr;
|
||||
};
|
||||
|
||||
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
|
||||
grpc_channel_args* client_args, grpc_channel_args* server_args) {
|
||||
grpc_end2end_test_fixture f;
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
|
||||
gpr_malloc(sizeof(fullstack_fixture_data)));
|
||||
fullstack_fixture_data* ffd = grpc_core::New<fullstack_fixture_data>();
|
||||
memset(&f, 0, sizeof(f));
|
||||
|
||||
gpr_join_host_port(&ffd->localaddr, "localhost", port);
|
||||
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
|
||||
|
||||
f.fixture_data = ffd;
|
||||
f.cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
|
|
@ -60,7 +59,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
|
|||
fullstack_fixture_data* ffd =
|
||||
static_cast<fullstack_fixture_data*>(f->fixture_data);
|
||||
f->client =
|
||||
grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr);
|
||||
grpc_insecure_channel_create(ffd->localaddr.get(), client_args, nullptr);
|
||||
GPR_ASSERT(f->client);
|
||||
}
|
||||
|
||||
|
|
@ -73,15 +72,15 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
|
|||
}
|
||||
f->server = grpc_server_create(server_args, nullptr);
|
||||
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
|
||||
GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
|
||||
GPR_ASSERT(
|
||||
grpc_server_add_insecure_http2_port(f->server, ffd->localaddr.get()));
|
||||
grpc_server_start(f->server);
|
||||
}
|
||||
|
||||
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
|
||||
fullstack_fixture_data* ffd =
|
||||
static_cast<fullstack_fixture_data*>(f->fixture_data);
|
||||
gpr_free(ffd->localaddr);
|
||||
gpr_free(ffd);
|
||||
grpc_core::Delete(ffd);
|
||||
}
|
||||
|
||||
/* All test configurations */
|
||||
|
|
|
|||
|
|
@ -30,26 +30,26 @@
|
|||
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
|
||||
#include "src/core/lib/channel/connected_channel.h"
|
||||
#include "src/core/lib/gpr/env.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/surface/channel.h"
|
||||
#include "src/core/lib/surface/server.h"
|
||||
#include "test/core/end2end/fixtures/http_proxy_fixture.h"
|
||||
#include "test/core/util/port.h"
|
||||
#include "test/core/util/test_config.h"
|
||||
|
||||
typedef struct fullstack_fixture_data {
|
||||
char* server_addr;
|
||||
grpc_end2end_http_proxy* proxy;
|
||||
} fullstack_fixture_data;
|
||||
struct fullstack_fixture_data {
|
||||
~fullstack_fixture_data() { grpc_end2end_http_proxy_destroy(proxy); }
|
||||
grpc_core::UniquePtr<char> server_addr;
|
||||
grpc_end2end_http_proxy* proxy = nullptr;
|
||||
};
|
||||
|
||||
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
|
||||
grpc_channel_args* client_args, grpc_channel_args* server_args) {
|
||||
grpc_end2end_test_fixture f;
|
||||
memset(&f, 0, sizeof(f));
|
||||
fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
|
||||
gpr_malloc(sizeof(fullstack_fixture_data)));
|
||||
fullstack_fixture_data* ffd = grpc_core::New<fullstack_fixture_data>();
|
||||
const int server_port = grpc_pick_unused_port_or_die();
|
||||
gpr_join_host_port(&ffd->server_addr, "localhost", server_port);
|
||||
grpc_core::JoinHostPort(&ffd->server_addr, "localhost", server_port);
|
||||
|
||||
/* Passing client_args to proxy_create for the case of checking for proxy auth
|
||||
*/
|
||||
|
|
@ -81,8 +81,8 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
|
|||
}
|
||||
gpr_setenv("http_proxy", proxy_uri);
|
||||
gpr_free(proxy_uri);
|
||||
f->client =
|
||||
grpc_insecure_channel_create(ffd->server_addr, client_args, nullptr);
|
||||
f->client = grpc_insecure_channel_create(ffd->server_addr.get(), client_args,
|
||||
nullptr);
|
||||
GPR_ASSERT(f->client);
|
||||
}
|
||||
|
||||
|
|
@ -95,16 +95,15 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
|
|||
}
|
||||
f->server = grpc_server_create(server_args, nullptr);
|
||||
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
|
||||
GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->server_addr));
|
||||
GPR_ASSERT(
|
||||
grpc_server_add_insecure_http2_port(f->server, ffd->server_addr.get()));
|
||||
grpc_server_start(f->server);
|
||||
}
|
||||
|
||||
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
|
||||
fullstack_fixture_data* ffd =
|
||||
static_cast<fullstack_fixture_data*>(f->fixture_data);
|
||||
gpr_free(ffd->server_addr);
|
||||
grpc_end2end_http_proxy_destroy(ffd->proxy);
|
||||
gpr_free(ffd);
|
||||
grpc_core::Delete(ffd);
|
||||
}
|
||||
|
||||
/* All test configurations */
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#include <grpc/support/string_util.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "test/core/end2end/end2end_tests.h"
|
||||
#include "test/core/end2end/fixtures/local_util.h"
|
||||
#include "test/core/util/port.h"
|
||||
|
|
@ -31,7 +31,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_ipv4(
|
|||
grpc_end2end_test_fixture f =
|
||||
grpc_end2end_local_chttp2_create_fixture_fullstack();
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
gpr_join_host_port(
|
||||
grpc_core::JoinHostPort(
|
||||
&static_cast<grpc_end2end_local_fullstack_fixture_data*>(f.fixture_data)
|
||||
->localaddr,
|
||||
"127.0.0.1", port);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#include <grpc/support/string_util.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "test/core/end2end/end2end_tests.h"
|
||||
#include "test/core/end2end/fixtures/local_util.h"
|
||||
#include "test/core/util/port.h"
|
||||
|
|
@ -31,7 +31,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_ipv6(
|
|||
grpc_end2end_test_fixture f =
|
||||
grpc_end2end_local_chttp2_create_fixture_fullstack();
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
gpr_join_host_port(
|
||||
grpc_core::JoinHostPort(
|
||||
&static_cast<grpc_end2end_local_fullstack_fixture_data*>(f.fixture_data)
|
||||
->localaddr,
|
||||
"[::1]", port);
|
||||
|
|
|
|||
|
|
@ -30,10 +30,10 @@ static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_uds(
|
|||
grpc_channel_args* client_args, grpc_channel_args* server_args) {
|
||||
grpc_end2end_test_fixture f =
|
||||
grpc_end2end_local_chttp2_create_fixture_fullstack();
|
||||
gpr_asprintf(
|
||||
&static_cast<grpc_end2end_local_fullstack_fixture_data*>(f.fixture_data)
|
||||
->localaddr,
|
||||
"unix:/tmp/grpc_fullstack_test.%d.%d", getpid(), unique++);
|
||||
char* out = nullptr;
|
||||
gpr_asprintf(&out, "unix:/tmp/grpc_fullstack_test.%d.%d", getpid(), unique++);
|
||||
static_cast<grpc_end2end_local_fullstack_fixture_data*>(f.fixture_data)
|
||||
->localaddr.reset(out);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
#include <grpc/support/log.h>
|
||||
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/iomgr/iomgr.h"
|
||||
#include "src/core/lib/security/credentials/credentials.h"
|
||||
#include "test/core/end2end/data/ssl_test_data.h"
|
||||
|
|
@ -36,9 +36,9 @@ static const char oauth2_md[] = "Bearer aaslkfjs424535asdf";
|
|||
static const char* client_identity_property_name = "smurf_name";
|
||||
static const char* client_identity = "Brainy Smurf";
|
||||
|
||||
typedef struct fullstack_secure_fixture_data {
|
||||
char* localaddr;
|
||||
} fullstack_secure_fixture_data;
|
||||
struct fullstack_secure_fixture_data {
|
||||
grpc_core::UniquePtr<char> localaddr;
|
||||
};
|
||||
|
||||
static const grpc_metadata* find_metadata(const grpc_metadata* md,
|
||||
size_t md_count, const char* key,
|
||||
|
|
@ -95,16 +95,12 @@ static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
|
|||
grpc_end2end_test_fixture f;
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(
|
||||
gpr_malloc(sizeof(fullstack_secure_fixture_data)));
|
||||
grpc_core::New<fullstack_secure_fixture_data>();
|
||||
memset(&f, 0, sizeof(f));
|
||||
|
||||
gpr_join_host_port(&ffd->localaddr, "localhost", port);
|
||||
|
||||
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
|
||||
f.fixture_data = ffd;
|
||||
f.cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
|
|
@ -113,8 +109,8 @@ static void chttp2_init_client_secure_fullstack(
|
|||
grpc_channel_credentials* creds) {
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
|
||||
f->client =
|
||||
grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr);
|
||||
f->client = grpc_secure_channel_create(creds, ffd->localaddr.get(),
|
||||
client_args, nullptr);
|
||||
GPR_ASSERT(f->client != nullptr);
|
||||
grpc_channel_credentials_release(creds);
|
||||
}
|
||||
|
|
@ -129,7 +125,7 @@ static void chttp2_init_server_secure_fullstack(
|
|||
}
|
||||
f->server = grpc_server_create(server_args, nullptr);
|
||||
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr,
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr.get(),
|
||||
server_creds));
|
||||
grpc_server_credentials_release(server_creds);
|
||||
grpc_server_start(f->server);
|
||||
|
|
@ -138,8 +134,7 @@ static void chttp2_init_server_secure_fullstack(
|
|||
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
|
||||
gpr_free(ffd->localaddr);
|
||||
gpr_free(ffd);
|
||||
grpc_core::Delete(ffd);
|
||||
}
|
||||
|
||||
static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack(
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@
|
|||
#include "src/core/ext/filters/http/server/http_server_filter.h"
|
||||
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
|
||||
#include "src/core/lib/channel/connected_channel.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/surface/channel.h"
|
||||
#include "src/core/lib/surface/server.h"
|
||||
#include "test/core/end2end/fixtures/proxy.h"
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@
|
|||
#include <grpc/support/string_util.h>
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/env.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gpr/tmpfile.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/gprpp/inlined_vector.h"
|
||||
#include "src/core/lib/gprpp/thd.h"
|
||||
#include "src/core/lib/security/credentials/credentials.h"
|
||||
|
|
@ -42,10 +42,15 @@
|
|||
|
||||
typedef grpc_core::InlinedVector<grpc_core::Thread, 1> ThreadList;
|
||||
|
||||
typedef struct fullstack_secure_fixture_data {
|
||||
char* localaddr;
|
||||
struct fullstack_secure_fixture_data {
|
||||
~fullstack_secure_fixture_data() {
|
||||
for (size_t ind = 0; ind < thd_list.size(); ind++) {
|
||||
thd_list[ind].Join();
|
||||
}
|
||||
}
|
||||
grpc_core::UniquePtr<char> localaddr;
|
||||
ThreadList thd_list;
|
||||
} fullstack_secure_fixture_data;
|
||||
};
|
||||
|
||||
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
|
||||
grpc_channel_args* client_args, grpc_channel_args* server_args) {
|
||||
|
|
@ -54,7 +59,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
|
|||
fullstack_secure_fixture_data* ffd =
|
||||
grpc_core::New<fullstack_secure_fixture_data>();
|
||||
memset(&f, 0, sizeof(f));
|
||||
gpr_join_host_port(&ffd->localaddr, "localhost", port);
|
||||
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
|
||||
f.fixture_data = ffd;
|
||||
f.cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr);
|
||||
|
|
@ -74,8 +79,8 @@ static void chttp2_init_client_secure_fullstack(
|
|||
grpc_channel_credentials* creds) {
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
|
||||
f->client =
|
||||
grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr);
|
||||
f->client = grpc_secure_channel_create(creds, ffd->localaddr.get(),
|
||||
client_args, nullptr);
|
||||
GPR_ASSERT(f->client != nullptr);
|
||||
grpc_channel_credentials_release(creds);
|
||||
}
|
||||
|
|
@ -90,7 +95,7 @@ static void chttp2_init_server_secure_fullstack(
|
|||
}
|
||||
f->server = grpc_server_create(server_args, nullptr);
|
||||
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr,
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr.get(),
|
||||
server_creds));
|
||||
grpc_server_credentials_release(server_creds);
|
||||
grpc_server_start(f->server);
|
||||
|
|
@ -99,10 +104,6 @@ static void chttp2_init_server_secure_fullstack(
|
|||
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
|
||||
for (size_t ind = 0; ind < ffd->thd_list.size(); ind++) {
|
||||
ffd->thd_list[ind].Join();
|
||||
}
|
||||
gpr_free(ffd->localaddr);
|
||||
grpc_core::Delete(ffd);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,29 +25,28 @@
|
|||
#include <grpc/support/log.h>
|
||||
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gpr/tmpfile.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/security/credentials/credentials.h"
|
||||
#include "src/core/lib/security/security_connector/ssl_utils.h"
|
||||
#include "test/core/end2end/data/ssl_test_data.h"
|
||||
#include "test/core/util/port.h"
|
||||
#include "test/core/util/test_config.h"
|
||||
|
||||
typedef struct fullstack_secure_fixture_data {
|
||||
char* localaddr;
|
||||
} fullstack_secure_fixture_data;
|
||||
struct fullstack_secure_fixture_data {
|
||||
grpc_core::UniquePtr<char> localaddr;
|
||||
};
|
||||
|
||||
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
|
||||
grpc_channel_args* client_args, grpc_channel_args* server_args) {
|
||||
grpc_end2end_test_fixture f;
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(
|
||||
gpr_malloc(sizeof(fullstack_secure_fixture_data)));
|
||||
grpc_core::New<fullstack_secure_fixture_data>();
|
||||
memset(&f, 0, sizeof(f));
|
||||
|
||||
gpr_join_host_port(&ffd->localaddr, "localhost", port);
|
||||
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
|
||||
|
||||
f.fixture_data = ffd;
|
||||
f.cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
|
|
@ -69,8 +68,8 @@ static void chttp2_init_client_secure_fullstack(
|
|||
grpc_channel_credentials* creds) {
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
|
||||
f->client =
|
||||
grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr);
|
||||
f->client = grpc_secure_channel_create(creds, ffd->localaddr.get(),
|
||||
client_args, nullptr);
|
||||
GPR_ASSERT(f->client != nullptr);
|
||||
grpc_channel_credentials_release(creds);
|
||||
}
|
||||
|
|
@ -85,7 +84,7 @@ static void chttp2_init_server_secure_fullstack(
|
|||
}
|
||||
f->server = grpc_server_create(server_args, nullptr);
|
||||
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr,
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr.get(),
|
||||
server_creds));
|
||||
grpc_server_credentials_release(server_creds);
|
||||
grpc_server_start(f->server);
|
||||
|
|
@ -94,8 +93,7 @@ static void chttp2_init_server_secure_fullstack(
|
|||
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
|
||||
gpr_free(ffd->localaddr);
|
||||
gpr_free(ffd);
|
||||
grpc_core::Delete(ffd);
|
||||
}
|
||||
|
||||
static void chttp2_init_client_simple_ssl_secure_fullstack(
|
||||
|
|
|
|||
|
|
@ -25,19 +25,19 @@
|
|||
#include <grpc/support/log.h>
|
||||
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gpr/tmpfile.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/security/credentials/credentials.h"
|
||||
#include "src/core/lib/security/security_connector/ssl_utils.h"
|
||||
#include "test/core/end2end/data/ssl_test_data.h"
|
||||
#include "test/core/util/port.h"
|
||||
#include "test/core/util/test_config.h"
|
||||
|
||||
typedef struct fullstack_secure_fixture_data {
|
||||
char* localaddr;
|
||||
bool server_credential_reloaded;
|
||||
} fullstack_secure_fixture_data;
|
||||
struct fullstack_secure_fixture_data {
|
||||
grpc_core::UniquePtr<char> localaddr;
|
||||
bool server_credential_reloaded = false;
|
||||
};
|
||||
|
||||
static grpc_ssl_certificate_config_reload_status
|
||||
ssl_server_certificate_config_callback(
|
||||
|
|
@ -64,10 +64,9 @@ static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
|
|||
grpc_end2end_test_fixture f;
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(
|
||||
gpr_malloc(sizeof(fullstack_secure_fixture_data)));
|
||||
grpc_core::New<fullstack_secure_fixture_data>();
|
||||
memset(&f, 0, sizeof(f));
|
||||
gpr_join_host_port(&ffd->localaddr, "localhost", port);
|
||||
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
|
||||
|
||||
f.fixture_data = ffd;
|
||||
f.cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
|
|
@ -89,8 +88,8 @@ static void chttp2_init_client_secure_fullstack(
|
|||
grpc_channel_credentials* creds) {
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
|
||||
f->client =
|
||||
grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr);
|
||||
f->client = grpc_secure_channel_create(creds, ffd->localaddr.get(),
|
||||
client_args, nullptr);
|
||||
GPR_ASSERT(f->client != nullptr);
|
||||
grpc_channel_credentials_release(creds);
|
||||
}
|
||||
|
|
@ -106,7 +105,7 @@ static void chttp2_init_server_secure_fullstack(
|
|||
ffd->server_credential_reloaded = false;
|
||||
f->server = grpc_server_create(server_args, nullptr);
|
||||
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr,
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr.get(),
|
||||
server_creds));
|
||||
grpc_server_credentials_release(server_creds);
|
||||
grpc_server_start(f->server);
|
||||
|
|
@ -115,8 +114,7 @@ static void chttp2_init_server_secure_fullstack(
|
|||
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
|
||||
gpr_free(ffd->localaddr);
|
||||
gpr_free(ffd);
|
||||
grpc_core::Delete(ffd);
|
||||
}
|
||||
|
||||
static void chttp2_init_client_simple_ssl_secure_fullstack(
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
#include <grpc/support/log.h>
|
||||
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gpr/tmpfile.h"
|
||||
#include "src/core/lib/security/credentials/credentials.h"
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@
|
|||
#include "src/core/ext/filters/http/server/http_server_filter.h"
|
||||
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
|
||||
#include "src/core/lib/channel/connected_channel.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/surface/channel.h"
|
||||
#include "src/core/lib/surface/server.h"
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@
|
|||
#include <grpc/support/sync.h>
|
||||
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/gprpp/thd.h"
|
||||
#include "src/core/lib/http/parser.h"
|
||||
#include "src/core/lib/iomgr/closure.h"
|
||||
|
|
@ -53,8 +53,7 @@
|
|||
|
||||
struct grpc_end2end_http_proxy {
|
||||
grpc_end2end_http_proxy()
|
||||
: proxy_name(nullptr),
|
||||
server(nullptr),
|
||||
: server(nullptr),
|
||||
channel_args(nullptr),
|
||||
mu(nullptr),
|
||||
pollset(nullptr),
|
||||
|
|
@ -62,7 +61,7 @@ struct grpc_end2end_http_proxy {
|
|||
gpr_ref_init(&users, 1);
|
||||
combiner = grpc_combiner_create();
|
||||
}
|
||||
char* proxy_name;
|
||||
grpc_core::UniquePtr<char> proxy_name;
|
||||
grpc_core::Thread thd;
|
||||
grpc_tcp_server* server;
|
||||
grpc_channel_args* channel_args;
|
||||
|
|
@ -532,8 +531,8 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create(
|
|||
grpc_end2end_http_proxy* proxy = grpc_core::New<grpc_end2end_http_proxy>();
|
||||
// Construct proxy address.
|
||||
const int proxy_port = grpc_pick_unused_port_or_die();
|
||||
gpr_join_host_port(&proxy->proxy_name, "localhost", proxy_port);
|
||||
gpr_log(GPR_INFO, "Proxy address: %s", proxy->proxy_name);
|
||||
grpc_core::JoinHostPort(&proxy->proxy_name, "localhost", proxy_port);
|
||||
gpr_log(GPR_INFO, "Proxy address: %s", proxy->proxy_name.get());
|
||||
// Create TCP server.
|
||||
proxy->channel_args = grpc_channel_args_copy(args);
|
||||
grpc_error* error =
|
||||
|
|
@ -573,7 +572,6 @@ void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) {
|
|||
proxy->thd.Join();
|
||||
grpc_tcp_server_shutdown_listeners(proxy->server);
|
||||
grpc_tcp_server_unref(proxy->server);
|
||||
gpr_free(proxy->proxy_name);
|
||||
grpc_channel_args_destroy(proxy->channel_args);
|
||||
grpc_pollset_shutdown(proxy->pollset,
|
||||
GRPC_CLOSURE_CREATE(destroy_pollset, proxy->pollset,
|
||||
|
|
@ -584,5 +582,5 @@ void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) {
|
|||
|
||||
const char* grpc_end2end_http_proxy_get_proxy_name(
|
||||
grpc_end2end_http_proxy* proxy) {
|
||||
return proxy->proxy_name;
|
||||
return proxy->proxy_name.get();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@
|
|||
#include "src/core/ext/filters/http/server/http_server_filter.h"
|
||||
#include "src/core/ext/transport/inproc/inproc_transport.h"
|
||||
#include "src/core/lib/channel/connected_channel.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/surface/channel.h"
|
||||
#include "src/core/lib/surface/server.h"
|
||||
#include "test/core/util/port.h"
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
#include "src/core/ext/filters/http/server/http_server_filter.h"
|
||||
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
|
||||
#include "src/core/lib/channel/connected_channel.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/security/credentials/credentials.h"
|
||||
#include "src/core/lib/surface/server.h"
|
||||
|
|
@ -37,8 +36,7 @@
|
|||
grpc_end2end_test_fixture grpc_end2end_local_chttp2_create_fixture_fullstack() {
|
||||
grpc_end2end_test_fixture f;
|
||||
grpc_end2end_local_fullstack_fixture_data* ffd =
|
||||
static_cast<grpc_end2end_local_fullstack_fixture_data*>(
|
||||
gpr_malloc(sizeof(grpc_end2end_local_fullstack_fixture_data)));
|
||||
grpc_core::New<grpc_end2end_local_fullstack_fixture_data>();
|
||||
memset(&f, 0, sizeof(f));
|
||||
f.fixture_data = ffd;
|
||||
f.cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
|
|
@ -52,8 +50,8 @@ void grpc_end2end_local_chttp2_init_client_fullstack(
|
|||
grpc_channel_credentials* creds = grpc_local_credentials_create(type);
|
||||
grpc_end2end_local_fullstack_fixture_data* ffd =
|
||||
static_cast<grpc_end2end_local_fullstack_fixture_data*>(f->fixture_data);
|
||||
f->client =
|
||||
grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr);
|
||||
f->client = grpc_secure_channel_create(creds, ffd->localaddr.get(),
|
||||
client_args, nullptr);
|
||||
GPR_ASSERT(f->client != nullptr);
|
||||
grpc_channel_credentials_release(creds);
|
||||
}
|
||||
|
|
@ -99,8 +97,8 @@ void grpc_end2end_local_chttp2_init_server_fullstack(
|
|||
nullptr};
|
||||
grpc_server_credentials_set_auth_metadata_processor(creds, processor);
|
||||
}
|
||||
GPR_ASSERT(
|
||||
grpc_server_add_secure_http2_port(f->server, ffd->localaddr, creds));
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr.get(),
|
||||
creds));
|
||||
grpc_server_credentials_release(creds);
|
||||
grpc_server_start(f->server);
|
||||
}
|
||||
|
|
@ -109,6 +107,5 @@ void grpc_end2end_local_chttp2_tear_down_fullstack(
|
|||
grpc_end2end_test_fixture* f) {
|
||||
grpc_end2end_local_fullstack_fixture_data* ffd =
|
||||
static_cast<grpc_end2end_local_fullstack_fixture_data*>(f->fixture_data);
|
||||
gpr_free(ffd->localaddr);
|
||||
gpr_free(ffd);
|
||||
grpc_core::Delete(ffd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@
|
|||
|
||||
#include "src/core/lib/surface/channel.h"
|
||||
|
||||
typedef struct grpc_end2end_local_fullstack_fixture_data {
|
||||
char* localaddr;
|
||||
} grpc_end2end_local_fullstack_fixture_data;
|
||||
struct grpc_end2end_local_fullstack_fixture_data {
|
||||
grpc_core::UniquePtr<char> localaddr;
|
||||
};
|
||||
|
||||
/* Utility functions shared by h2_local tests. */
|
||||
grpc_end2end_test_fixture grpc_end2end_local_chttp2_create_fixture_fullstack();
|
||||
|
|
|
|||
|
|
@ -24,16 +24,15 @@
|
|||
#include <grpc/support/log.h>
|
||||
#include <grpc/support/sync.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/useful.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/gprpp/memory.h"
|
||||
#include "src/core/lib/gprpp/thd.h"
|
||||
#include "test/core/util/port.h"
|
||||
|
||||
struct grpc_end2end_proxy {
|
||||
grpc_end2end_proxy()
|
||||
: proxy_port(nullptr),
|
||||
server_port(nullptr),
|
||||
cq(nullptr),
|
||||
: cq(nullptr),
|
||||
server(nullptr),
|
||||
client(nullptr),
|
||||
shutdown(false),
|
||||
|
|
@ -42,8 +41,8 @@ struct grpc_end2end_proxy {
|
|||
memset(&new_call_metadata, 0, sizeof(new_call_metadata));
|
||||
}
|
||||
grpc_core::Thread thd;
|
||||
char* proxy_port;
|
||||
char* server_port;
|
||||
grpc_core::UniquePtr<char> proxy_port;
|
||||
grpc_core::UniquePtr<char> server_port;
|
||||
grpc_completion_queue* cq;
|
||||
grpc_server* server;
|
||||
grpc_channel* client;
|
||||
|
|
@ -92,15 +91,15 @@ grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def,
|
|||
|
||||
grpc_end2end_proxy* proxy = grpc_core::New<grpc_end2end_proxy>();
|
||||
|
||||
gpr_join_host_port(&proxy->proxy_port, "localhost", proxy_port);
|
||||
gpr_join_host_port(&proxy->server_port, "localhost", server_port);
|
||||
grpc_core::JoinHostPort(&proxy->proxy_port, "localhost", proxy_port);
|
||||
grpc_core::JoinHostPort(&proxy->server_port, "localhost", server_port);
|
||||
|
||||
gpr_log(GPR_DEBUG, "PROXY ADDR:%s BACKEND:%s", proxy->proxy_port,
|
||||
proxy->server_port);
|
||||
gpr_log(GPR_DEBUG, "PROXY ADDR:%s BACKEND:%s", proxy->proxy_port.get(),
|
||||
proxy->server_port.get());
|
||||
|
||||
proxy->cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
proxy->server = def->create_server(proxy->proxy_port, server_args);
|
||||
proxy->client = def->create_client(proxy->server_port, client_args);
|
||||
proxy->server = def->create_server(proxy->proxy_port.get(), server_args);
|
||||
proxy->client = def->create_client(proxy->server_port.get(), client_args);
|
||||
|
||||
grpc_server_register_completion_queue(proxy->server, proxy->cq, nullptr);
|
||||
grpc_server_start(proxy->server);
|
||||
|
|
@ -131,8 +130,6 @@ void grpc_end2end_proxy_destroy(grpc_end2end_proxy* proxy) {
|
|||
grpc_server_shutdown_and_notify(proxy->server, proxy->cq,
|
||||
new_closure(shutdown_complete, proxy));
|
||||
proxy->thd.Join();
|
||||
gpr_free(proxy->proxy_port);
|
||||
gpr_free(proxy->server_port);
|
||||
grpc_server_destroy(proxy->server);
|
||||
grpc_channel_destroy(proxy->client);
|
||||
grpc_completion_queue_destroy(proxy->cq);
|
||||
|
|
@ -441,9 +438,9 @@ static void thread_main(void* arg) {
|
|||
}
|
||||
|
||||
const char* grpc_end2end_proxy_get_client_target(grpc_end2end_proxy* proxy) {
|
||||
return proxy->proxy_port;
|
||||
return proxy->proxy_port.get();
|
||||
}
|
||||
|
||||
const char* grpc_end2end_proxy_get_server_port(grpc_end2end_proxy* proxy) {
|
||||
return proxy->server_port;
|
||||
return proxy->server_port.get();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@
|
|||
#include <grpc/support/log.h>
|
||||
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gpr/tmpfile.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/security/credentials/credentials.h"
|
||||
#include "src/core/lib/security/security_connector/ssl_utils.h"
|
||||
#include "test/core/end2end/cq_verifier.h"
|
||||
|
|
@ -40,20 +40,19 @@
|
|||
namespace grpc {
|
||||
namespace testing {
|
||||
|
||||
typedef struct fullstack_secure_fixture_data {
|
||||
char* localaddr;
|
||||
} fullstack_secure_fixture_data;
|
||||
struct fullstack_secure_fixture_data {
|
||||
grpc_core::UniquePtr<char> localaddr;
|
||||
};
|
||||
|
||||
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
|
||||
grpc_channel_args* client_args, grpc_channel_args* server_args) {
|
||||
grpc_end2end_test_fixture f;
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(
|
||||
gpr_malloc(sizeof(fullstack_secure_fixture_data)));
|
||||
grpc_core::New<fullstack_secure_fixture_data>();
|
||||
memset(&f, 0, sizeof(f));
|
||||
|
||||
gpr_join_host_port(&ffd->localaddr, "localhost", port);
|
||||
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
|
||||
|
||||
f.fixture_data = ffd;
|
||||
f.cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
|
|
@ -73,8 +72,8 @@ static void chttp2_init_client_secure_fullstack(
|
|||
grpc_channel_credentials* creds) {
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
|
||||
f->client =
|
||||
grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr);
|
||||
f->client = grpc_secure_channel_create(creds, ffd->localaddr.get(),
|
||||
client_args, nullptr);
|
||||
GPR_ASSERT(f->client != nullptr);
|
||||
grpc_channel_credentials_release(creds);
|
||||
}
|
||||
|
|
@ -89,7 +88,7 @@ static void chttp2_init_server_secure_fullstack(
|
|||
}
|
||||
f->server = grpc_server_create(server_args, nullptr);
|
||||
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr,
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr.get(),
|
||||
server_creds));
|
||||
grpc_server_credentials_release(server_creds);
|
||||
grpc_server_start(f->server);
|
||||
|
|
@ -98,8 +97,7 @@ static void chttp2_init_server_secure_fullstack(
|
|||
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
|
||||
fullstack_secure_fixture_data* ffd =
|
||||
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
|
||||
gpr_free(ffd->localaddr);
|
||||
gpr_free(ffd);
|
||||
grpc_core::Delete(ffd);
|
||||
}
|
||||
|
||||
static int fail_server_auth_check(grpc_channel_args* server_args) {
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@
|
|||
#include <grpc/support/log.h>
|
||||
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gpr/tmpfile.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/security/credentials/credentials.h"
|
||||
#include "src/core/lib/security/security_connector/ssl_utils.h"
|
||||
#include "test/core/end2end/cq_verifier.h"
|
||||
|
|
@ -215,19 +215,18 @@ void drain_cq(grpc_completion_queue* cq) {
|
|||
TEST(H2SessionReuseTest, SingleReuse) {
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
|
||||
char* server_addr;
|
||||
gpr_join_host_port(&server_addr, "localhost", port);
|
||||
grpc_core::UniquePtr<char> server_addr;
|
||||
grpc_core::JoinHostPort(&server_addr, "localhost", port);
|
||||
|
||||
grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
grpc_ssl_session_cache* cache = grpc_ssl_session_cache_create_lru(16);
|
||||
|
||||
grpc_server* server = server_create(cq, server_addr);
|
||||
grpc_server* server = server_create(cq, server_addr.get());
|
||||
|
||||
do_round_trip(cq, server, server_addr, cache, false);
|
||||
do_round_trip(cq, server, server_addr, cache, true);
|
||||
do_round_trip(cq, server, server_addr, cache, true);
|
||||
do_round_trip(cq, server, server_addr.get(), cache, false);
|
||||
do_round_trip(cq, server, server_addr.get(), cache, true);
|
||||
do_round_trip(cq, server, server_addr.get(), cache, true);
|
||||
|
||||
gpr_free(server_addr);
|
||||
grpc_ssl_session_cache_destroy(cache);
|
||||
|
||||
GPR_ASSERT(grpc_completion_queue_next(
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@
|
|||
#include <grpc/support/alloc.h>
|
||||
#include <grpc/support/log.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/gprpp/memory.h"
|
||||
#include "test/core/end2end/cq_verifier.h"
|
||||
#include "test/core/util/port.h"
|
||||
#include "test/core/util/test_config.h"
|
||||
|
|
@ -54,7 +55,6 @@ static struct test_state g_state;
|
|||
|
||||
static void prepare_test(int is_client) {
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
char* server_hostport;
|
||||
grpc_op* op;
|
||||
g_state.is_client = is_client;
|
||||
grpc_metadata_array_init(&g_state.initial_metadata_recv);
|
||||
|
|
@ -77,14 +77,13 @@ static void prepare_test(int is_client) {
|
|||
} else {
|
||||
g_state.server = grpc_server_create(nullptr, nullptr);
|
||||
grpc_server_register_completion_queue(g_state.server, g_state.cq, nullptr);
|
||||
gpr_join_host_port(&server_hostport, "0.0.0.0", port);
|
||||
grpc_server_add_insecure_http2_port(g_state.server, server_hostport);
|
||||
grpc_core::UniquePtr<char> server_hostport;
|
||||
grpc_core::JoinHostPort(&server_hostport, "0.0.0.0", port);
|
||||
grpc_server_add_insecure_http2_port(g_state.server, server_hostport.get());
|
||||
grpc_server_start(g_state.server);
|
||||
gpr_free(server_hostport);
|
||||
gpr_join_host_port(&server_hostport, "localhost", port);
|
||||
grpc_core::JoinHostPort(&server_hostport, "localhost", port);
|
||||
g_state.chan =
|
||||
grpc_insecure_channel_create(server_hostport, nullptr, nullptr);
|
||||
gpr_free(server_hostport);
|
||||
grpc_insecure_channel_create(server_hostport.get(), nullptr, nullptr);
|
||||
grpc_slice host = grpc_slice_from_static_string("bar");
|
||||
g_state.call = grpc_channel_create_call(
|
||||
g_state.chan, nullptr, GRPC_PROPAGATE_DEFAULTS, g_state.cq,
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@
|
|||
#include <grpc/support/alloc.h>
|
||||
#include <grpc/support/string_util.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "test/core/util/port.h"
|
||||
#include "test/core/util/subprocess.h"
|
||||
|
||||
|
|
@ -46,23 +46,24 @@ int main(int argc, char** argv) {
|
|||
gpr_asprintf(&args[0], "%s/fling_server%s", root,
|
||||
gpr_subprocess_binary_extension());
|
||||
args[1] = const_cast<char*>("--bind");
|
||||
gpr_join_host_port(&args[2], "::", port);
|
||||
grpc_core::UniquePtr<char> joined;
|
||||
grpc_core::JoinHostPort(&joined, "::", port);
|
||||
args[2] = joined.get();
|
||||
args[3] = const_cast<char*>("--no-secure");
|
||||
svr = gpr_subprocess_create(4, (const char**)args);
|
||||
gpr_free(args[0]);
|
||||
gpr_free(args[2]);
|
||||
|
||||
/* start the client */
|
||||
gpr_asprintf(&args[0], "%s/fling_client%s", root,
|
||||
gpr_subprocess_binary_extension());
|
||||
args[1] = const_cast<char*>("--target");
|
||||
gpr_join_host_port(&args[2], "127.0.0.1", port);
|
||||
grpc_core::JoinHostPort(&joined, "127.0.0.1", port);
|
||||
args[2] = joined.get();
|
||||
args[3] = const_cast<char*>("--scenario=ping-pong-stream");
|
||||
args[4] = const_cast<char*>("--no-secure");
|
||||
args[5] = nullptr;
|
||||
cli = gpr_subprocess_create(6, (const char**)args);
|
||||
gpr_free(args[0]);
|
||||
gpr_free(args[2]);
|
||||
|
||||
/* wait for completion */
|
||||
printf("waiting for client\n");
|
||||
|
|
|
|||
|
|
@ -22,8 +22,9 @@
|
|||
#include <grpc/support/alloc.h>
|
||||
#include <grpc/support/string_util.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/gprpp/memory.h"
|
||||
#include "test/core/util/port.h"
|
||||
#include "test/core/util/subprocess.h"
|
||||
|
||||
|
|
@ -46,23 +47,24 @@ int main(int argc, const char** argv) {
|
|||
gpr_asprintf(&args[0], "%s/fling_server%s", root,
|
||||
gpr_subprocess_binary_extension());
|
||||
args[1] = const_cast<char*>("--bind");
|
||||
gpr_join_host_port(&args[2], "::", port);
|
||||
grpc_core::UniquePtr<char> joined;
|
||||
grpc_core::JoinHostPort(&joined, "::", port);
|
||||
args[2] = joined.get();
|
||||
args[3] = const_cast<char*>("--no-secure");
|
||||
svr = gpr_subprocess_create(4, (const char**)args);
|
||||
gpr_free(args[0]);
|
||||
gpr_free(args[2]);
|
||||
|
||||
/* start the client */
|
||||
gpr_asprintf(&args[0], "%s/fling_client%s", root,
|
||||
gpr_subprocess_binary_extension());
|
||||
args[1] = const_cast<char*>("--target");
|
||||
gpr_join_host_port(&args[2], "127.0.0.1", port);
|
||||
grpc_core::JoinHostPort(&joined, "127.0.0.1", port);
|
||||
args[2] = joined.get();
|
||||
args[3] = const_cast<char*>("--scenario=ping-pong-request");
|
||||
args[4] = const_cast<char*>("--no-secure");
|
||||
args[5] = nullptr;
|
||||
cli = gpr_subprocess_create(6, (const char**)args);
|
||||
gpr_free(args[0]);
|
||||
gpr_free(args[2]);
|
||||
|
||||
/* wait for completion */
|
||||
printf("waiting for client\n");
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
#include <grpc/support/log.h>
|
||||
#include <grpc/support/time.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/profiling/timers.h"
|
||||
#include "test/core/end2end/data/ssl_test_data.h"
|
||||
#include "test/core/util/cmdline.h"
|
||||
|
|
@ -172,7 +172,7 @@ static void sigint_handler(int x) { _exit(0); }
|
|||
int main(int argc, char** argv) {
|
||||
grpc_event ev;
|
||||
call_state* s;
|
||||
char* addr_buf = nullptr;
|
||||
grpc_core::UniquePtr<char> addr_buf;
|
||||
gpr_cmdline* cl;
|
||||
grpc_completion_queue* shutdown_cq;
|
||||
int shutdown_started = 0;
|
||||
|
|
@ -199,8 +199,8 @@ int main(int argc, char** argv) {
|
|||
gpr_cmdline_destroy(cl);
|
||||
|
||||
if (addr == nullptr) {
|
||||
gpr_join_host_port(&addr_buf, "::", grpc_pick_unused_port_or_die());
|
||||
addr = addr_buf;
|
||||
grpc_core::JoinHostPort(&addr_buf, "::", grpc_pick_unused_port_or_die());
|
||||
addr = addr_buf.get();
|
||||
}
|
||||
gpr_log(GPR_INFO, "creating server on: %s", addr);
|
||||
|
||||
|
|
@ -220,8 +220,8 @@ int main(int argc, char** argv) {
|
|||
grpc_server_register_completion_queue(server, cq, nullptr);
|
||||
grpc_server_start(server);
|
||||
|
||||
gpr_free(addr_buf);
|
||||
addr = addr_buf = nullptr;
|
||||
addr = nullptr;
|
||||
addr_buf.reset();
|
||||
|
||||
grpc_call_details_init(&call_details);
|
||||
|
||||
|
|
|
|||
|
|
@ -58,16 +58,6 @@ grpc_cc_test(
|
|||
],
|
||||
)
|
||||
|
||||
grpc_cc_test(
|
||||
name = "host_port_test",
|
||||
srcs = ["host_port_test.cc"],
|
||||
language = "C++",
|
||||
deps = [
|
||||
"//:gpr",
|
||||
"//test/core/util:grpc_test_util",
|
||||
],
|
||||
)
|
||||
|
||||
grpc_cc_test(
|
||||
name = "log_test",
|
||||
srcs = ["log_test.cc"],
|
||||
|
|
|
|||
|
|
@ -64,6 +64,16 @@ grpc_cc_test(
|
|||
],
|
||||
)
|
||||
|
||||
grpc_cc_test(
|
||||
name = "host_port_test",
|
||||
srcs = ["host_port_test.cc"],
|
||||
language = "C++",
|
||||
deps = [
|
||||
"//:gpr",
|
||||
"//test/core/util:grpc_test_util",
|
||||
],
|
||||
)
|
||||
|
||||
grpc_cc_test(
|
||||
name = "grpc_core_map_test",
|
||||
srcs = ["map_test.cc"],
|
||||
|
|
@ -156,6 +166,19 @@ grpc_cc_test(
|
|||
],
|
||||
)
|
||||
|
||||
grpc_cc_test(
|
||||
name = "string_view_test",
|
||||
srcs = ["string_view_test.cc"],
|
||||
external_deps = [
|
||||
"gtest",
|
||||
],
|
||||
language = "C++",
|
||||
deps = [
|
||||
"//:gpr_base",
|
||||
"//test/core/util:grpc_test_util",
|
||||
],
|
||||
)
|
||||
|
||||
grpc_cc_test(
|
||||
name = "thd_test",
|
||||
srcs = ["thd_test.cc"],
|
||||
|
|
|
|||
|
|
@ -21,18 +21,17 @@
|
|||
#include <grpc/support/alloc.h>
|
||||
#include <grpc/support/log.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "test/core/util/test_config.h"
|
||||
|
||||
static void join_host_port_expect(const char* host, int port,
|
||||
const char* expected) {
|
||||
char* buf;
|
||||
grpc_core::UniquePtr<char> buf;
|
||||
int len;
|
||||
len = gpr_join_host_port(&buf, host, port);
|
||||
len = grpc_core::JoinHostPort(&buf, host, port);
|
||||
GPR_ASSERT(len >= 0);
|
||||
GPR_ASSERT(strlen(expected) == (size_t)len);
|
||||
GPR_ASSERT(strcmp(expected, buf) == 0);
|
||||
gpr_free(buf);
|
||||
GPR_ASSERT(strlen(expected) == static_cast<size_t>(len));
|
||||
GPR_ASSERT(strcmp(expected, buf.get()) == 0);
|
||||
}
|
||||
|
||||
static void test_join_host_port(void) {
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
*
|
||||
* Copyright 2017 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 <grpc/slice.h>
|
||||
|
||||
#include "src/core/lib/gprpp/string_view.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "src/core/lib/gprpp/memory.h"
|
||||
#include "test/core/util/test_config.h"
|
||||
|
||||
namespace grpc_core {
|
||||
namespace testing {
|
||||
|
||||
TEST(StringViewTest, Empty) {
|
||||
grpc_core::StringView empty;
|
||||
EXPECT_TRUE(empty.empty());
|
||||
EXPECT_EQ(empty.size(), 0lu);
|
||||
|
||||
grpc_core::StringView empty_buf("");
|
||||
EXPECT_TRUE(empty_buf.empty());
|
||||
EXPECT_EQ(empty_buf.size(), 0lu);
|
||||
|
||||
grpc_core::StringView empty_trimmed("foo", 0);
|
||||
EXPECT_TRUE(empty_trimmed.empty());
|
||||
EXPECT_EQ(empty_trimmed.size(), 0lu);
|
||||
|
||||
grpc_core::StringView empty_slice(grpc_empty_slice());
|
||||
EXPECT_TRUE(empty_slice.empty());
|
||||
EXPECT_EQ(empty_slice.size(), 0lu);
|
||||
}
|
||||
|
||||
TEST(StringViewTest, Size) {
|
||||
constexpr char kStr[] = "foo";
|
||||
grpc_core::StringView str1(kStr);
|
||||
EXPECT_EQ(str1.size(), strlen(kStr));
|
||||
grpc_core::StringView str2(kStr, 2);
|
||||
EXPECT_EQ(str2.size(), 2lu);
|
||||
}
|
||||
|
||||
TEST(StringViewTest, Data) {
|
||||
constexpr char kStr[] = "foo-bar";
|
||||
grpc_core::StringView str(kStr);
|
||||
EXPECT_EQ(str.size(), strlen(kStr));
|
||||
for (size_t i = 0; i < strlen(kStr); ++i) {
|
||||
EXPECT_EQ(str[i], kStr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(StringViewTest, Slice) {
|
||||
constexpr char kStr[] = "foo";
|
||||
grpc_core::StringView slice(grpc_slice_from_static_string(kStr));
|
||||
EXPECT_EQ(slice.size(), strlen(kStr));
|
||||
}
|
||||
|
||||
TEST(StringViewTest, Dup) {
|
||||
constexpr char kStr[] = "foo";
|
||||
grpc_core::StringView slice(grpc_slice_from_static_string(kStr));
|
||||
grpc_core::UniquePtr<char> dup = slice.dup();
|
||||
EXPECT_EQ(0, strcmp(kStr, dup.get()));
|
||||
EXPECT_EQ(slice.size(), strlen(kStr));
|
||||
}
|
||||
|
||||
TEST(StringViewTest, Eq) {
|
||||
constexpr char kStr1[] = "foo";
|
||||
constexpr char kStr2[] = "bar";
|
||||
grpc_core::StringView str1(kStr1);
|
||||
EXPECT_EQ(kStr1, str1);
|
||||
EXPECT_EQ(str1, kStr1);
|
||||
grpc_core::StringView slice1(grpc_slice_from_static_string(kStr1));
|
||||
EXPECT_EQ(slice1, str1);
|
||||
EXPECT_EQ(str1, slice1);
|
||||
EXPECT_NE(slice1, kStr2);
|
||||
EXPECT_NE(kStr2, slice1);
|
||||
grpc_core::StringView slice2(grpc_slice_from_static_string(kStr2));
|
||||
EXPECT_NE(slice2, str1);
|
||||
EXPECT_NE(str1, slice2);
|
||||
}
|
||||
|
||||
TEST(StringViewTest, Cmp) {
|
||||
constexpr char kStr1[] = "abc";
|
||||
constexpr char kStr2[] = "abd";
|
||||
constexpr char kStr3[] = "abcd";
|
||||
grpc_core::StringView str1(kStr1);
|
||||
grpc_core::StringView str2(kStr2);
|
||||
grpc_core::StringView str3(kStr3);
|
||||
EXPECT_EQ(str1.cmp(str1), 0);
|
||||
EXPECT_LT(str1.cmp(str2), 0);
|
||||
EXPECT_LT(str1.cmp(str3), 0);
|
||||
EXPECT_EQ(str2.cmp(str2), 0);
|
||||
EXPECT_GT(str2.cmp(str1), 0);
|
||||
EXPECT_GT(str2.cmp(str3), 0);
|
||||
EXPECT_EQ(str3.cmp(str3), 0);
|
||||
EXPECT_GT(str3.cmp(str1), 0);
|
||||
EXPECT_LT(str3.cmp(str2), 0);
|
||||
}
|
||||
|
||||
TEST(StringViewTest, RemovePrefix) {
|
||||
constexpr char kStr[] = "abcd";
|
||||
grpc_core::StringView str(kStr);
|
||||
str.remove_prefix(1);
|
||||
EXPECT_EQ("bcd", str);
|
||||
str.remove_prefix(2);
|
||||
EXPECT_EQ("d", str);
|
||||
str.remove_prefix(1);
|
||||
EXPECT_EQ("", str);
|
||||
}
|
||||
|
||||
TEST(StringViewTest, RemoveSuffix) {
|
||||
constexpr char kStr[] = "abcd";
|
||||
grpc_core::StringView str(kStr);
|
||||
str.remove_suffix(1);
|
||||
EXPECT_EQ("abc", str);
|
||||
str.remove_suffix(2);
|
||||
EXPECT_EQ("a", str);
|
||||
str.remove_suffix(1);
|
||||
EXPECT_EQ("", str);
|
||||
}
|
||||
|
||||
TEST(StringViewTest, Substring) {
|
||||
constexpr char kStr[] = "abcd";
|
||||
grpc_core::StringView str(kStr);
|
||||
EXPECT_EQ("bcd", str.substr(1));
|
||||
EXPECT_EQ("bc", str.substr(1, 2));
|
||||
}
|
||||
|
||||
TEST(StringViewTest, Find) {
|
||||
// Passing StringView::npos directly to GTEST macros result in link errors.
|
||||
// Store the value in a local variable and use it in the test.
|
||||
const size_t npos = grpc_core::StringView::npos;
|
||||
constexpr char kStr[] = "abacad";
|
||||
grpc_core::StringView str(kStr);
|
||||
EXPECT_EQ(0ul, str.find('a'));
|
||||
EXPECT_EQ(2ul, str.find('a', 1));
|
||||
EXPECT_EQ(4ul, str.find('a', 3));
|
||||
EXPECT_EQ(1ul, str.find('b'));
|
||||
EXPECT_EQ(npos, str.find('b', 2));
|
||||
EXPECT_EQ(npos, str.find('z'));
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace grpc_core
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
grpc::testing::TestEnvironment env(argc, argv);
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
|
@ -22,8 +22,8 @@
|
|||
#include <grpc/support/alloc.h>
|
||||
#include <grpc/support/string_util.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gpr/string.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "test/core/util/port.h"
|
||||
#include "test/core/util/subprocess.h"
|
||||
|
||||
|
|
@ -46,22 +46,23 @@ int main(int argc, char** argv) {
|
|||
gpr_asprintf(&args[0], "%s/memory_usage_server%s", root,
|
||||
gpr_subprocess_binary_extension());
|
||||
args[1] = const_cast<char*>("--bind");
|
||||
gpr_join_host_port(&args[2], "::", port);
|
||||
grpc_core::UniquePtr<char> joined;
|
||||
grpc_core::JoinHostPort(&joined, "::", port);
|
||||
args[2] = joined.get();
|
||||
args[3] = const_cast<char*>("--no-secure");
|
||||
svr = gpr_subprocess_create(4, (const char**)args);
|
||||
gpr_free(args[0]);
|
||||
gpr_free(args[2]);
|
||||
|
||||
/* start the client */
|
||||
gpr_asprintf(&args[0], "%s/memory_usage_client%s", root,
|
||||
gpr_subprocess_binary_extension());
|
||||
args[1] = const_cast<char*>("--target");
|
||||
gpr_join_host_port(&args[2], "127.0.0.1", port);
|
||||
grpc_core::JoinHostPort(&joined, "127.0.0.1", port);
|
||||
args[2] = joined.get();
|
||||
args[3] = const_cast<char*>("--warmup=1000");
|
||||
args[4] = const_cast<char*>("--benchmark=9000");
|
||||
cli = gpr_subprocess_create(5, (const char**)args);
|
||||
gpr_free(args[0]);
|
||||
gpr_free(args[2]);
|
||||
|
||||
/* wait for completion */
|
||||
printf("waiting for client\n");
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
#include <grpc/support/log.h>
|
||||
#include <grpc/support/time.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "test/core/end2end/data/ssl_test_data.h"
|
||||
#include "test/core/util/cmdline.h"
|
||||
#include "test/core/util/memory_counters.h"
|
||||
|
|
@ -149,7 +149,7 @@ static void sigint_handler(int x) { _exit(0); }
|
|||
int main(int argc, char** argv) {
|
||||
grpc_memory_counters_init();
|
||||
grpc_event ev;
|
||||
char* addr_buf = nullptr;
|
||||
grpc_core::UniquePtr<char> addr_buf;
|
||||
gpr_cmdline* cl;
|
||||
grpc_completion_queue* shutdown_cq;
|
||||
int shutdown_started = 0;
|
||||
|
|
@ -174,8 +174,8 @@ int main(int argc, char** argv) {
|
|||
gpr_cmdline_destroy(cl);
|
||||
|
||||
if (addr == nullptr) {
|
||||
gpr_join_host_port(&addr_buf, "::", grpc_pick_unused_port_or_die());
|
||||
addr = addr_buf;
|
||||
grpc_core::JoinHostPort(&addr_buf, "::", grpc_pick_unused_port_or_die());
|
||||
addr = addr_buf.get();
|
||||
}
|
||||
gpr_log(GPR_INFO, "creating server on: %s", addr);
|
||||
|
||||
|
|
@ -202,8 +202,8 @@ int main(int argc, char** argv) {
|
|||
struct grpc_memory_counters after_server_create =
|
||||
grpc_memory_counters_snapshot();
|
||||
|
||||
gpr_free(addr_buf);
|
||||
addr = addr_buf = nullptr;
|
||||
addr = nullptr;
|
||||
addr_buf.reset();
|
||||
|
||||
// initialize call instances
|
||||
for (int i = 0; i < static_cast<int>(sizeof(calls) / sizeof(fling_call));
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@
|
|||
#include <grpc/support/log.h>
|
||||
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/gprpp/memory.h"
|
||||
#include "src/core/lib/gprpp/thd.h"
|
||||
#include "src/core/lib/iomgr/exec_ctx.h"
|
||||
#include "test/core/end2end/data/ssl_test_data.h"
|
||||
|
|
@ -66,13 +67,11 @@ static void channel_idle_poll_for_timeout(grpc_channel* channel,
|
|||
static void run_timeouts_test(const test_fixture* fixture) {
|
||||
gpr_log(GPR_INFO, "TEST: %s", fixture->name);
|
||||
|
||||
char* addr;
|
||||
|
||||
grpc_core::UniquePtr<char> addr;
|
||||
grpc_init();
|
||||
grpc_core::JoinHostPort(&addr, "localhost", grpc_pick_unused_port_or_die());
|
||||
|
||||
gpr_join_host_port(&addr, "localhost", grpc_pick_unused_port_or_die());
|
||||
|
||||
grpc_channel* channel = fixture->create_channel(addr);
|
||||
grpc_channel* channel = fixture->create_channel(addr.get());
|
||||
grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
|
||||
/* start 1 watcher and then let it time out */
|
||||
|
|
@ -111,7 +110,6 @@ static void run_timeouts_test(const test_fixture* fixture) {
|
|||
grpc_completion_queue_destroy(cq);
|
||||
|
||||
grpc_shutdown();
|
||||
gpr_free(addr);
|
||||
}
|
||||
|
||||
/* An edge scenario; sets channel state to explicitly, and outside
|
||||
|
|
@ -120,13 +118,11 @@ static void run_channel_shutdown_before_timeout_test(
|
|||
const test_fixture* fixture) {
|
||||
gpr_log(GPR_INFO, "TEST: %s", fixture->name);
|
||||
|
||||
char* addr;
|
||||
|
||||
grpc_core::UniquePtr<char> addr;
|
||||
grpc_init();
|
||||
grpc_core::JoinHostPort(&addr, "localhost", grpc_pick_unused_port_or_die());
|
||||
|
||||
gpr_join_host_port(&addr, "localhost", grpc_pick_unused_port_or_die());
|
||||
|
||||
grpc_channel* channel = fixture->create_channel(addr);
|
||||
grpc_channel* channel = fixture->create_channel(addr.get());
|
||||
grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
|
||||
/* start 1 watcher and then shut down the channel before the timer goes off */
|
||||
|
|
@ -154,7 +150,6 @@ static void run_channel_shutdown_before_timeout_test(
|
|||
grpc_completion_queue_destroy(cq);
|
||||
|
||||
grpc_shutdown();
|
||||
gpr_free(addr);
|
||||
}
|
||||
|
||||
static grpc_channel* insecure_test_create_channel(const char* addr) {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
#include <grpc/support/log.h>
|
||||
|
||||
#include "src/core/lib/channel/channel_args.h"
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/gprpp/thd.h"
|
||||
#include "src/core/lib/iomgr/exec_ctx.h"
|
||||
#include "test/core/end2end/data/ssl_test_data.h"
|
||||
|
|
@ -56,11 +56,11 @@ static void run_test(const test_fixture* fixture) {
|
|||
|
||||
grpc_init();
|
||||
|
||||
char* addr;
|
||||
gpr_join_host_port(&addr, "localhost", grpc_pick_unused_port_or_die());
|
||||
grpc_core::UniquePtr<char> addr;
|
||||
grpc_core::JoinHostPort(&addr, "localhost", grpc_pick_unused_port_or_die());
|
||||
|
||||
grpc_server* server = grpc_server_create(nullptr, nullptr);
|
||||
fixture->add_server_port(server, addr);
|
||||
fixture->add_server_port(server, addr.get());
|
||||
grpc_completion_queue* server_cq =
|
||||
grpc_completion_queue_create_for_next(nullptr);
|
||||
grpc_server_register_completion_queue(server, server_cq, nullptr);
|
||||
|
|
@ -73,7 +73,7 @@ static void run_test(const test_fixture* fixture) {
|
|||
grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr);
|
||||
grpc_channel* channels[NUM_CONNECTIONS];
|
||||
for (size_t i = 0; i < NUM_CONNECTIONS; i++) {
|
||||
channels[i] = fixture->create_channel(addr);
|
||||
channels[i] = fixture->create_channel(addr.get());
|
||||
|
||||
gpr_timespec connect_deadline = grpc_timeout_seconds_to_deadline(30);
|
||||
grpc_connectivity_state state;
|
||||
|
|
@ -116,7 +116,6 @@ static void run_test(const test_fixture* fixture) {
|
|||
grpc_completion_queue_destroy(cq);
|
||||
|
||||
grpc_shutdown();
|
||||
gpr_free(addr);
|
||||
}
|
||||
|
||||
static void insecure_test_add_port(grpc_server* server, const char* addr) {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
#include <grpc/support/log.h>
|
||||
#include <grpc/support/time.h>
|
||||
|
||||
#include "src/core/lib/gpr/host_port.h"
|
||||
#include "src/core/lib/gprpp/host_port.h"
|
||||
#include "src/core/lib/security/credentials/credentials.h"
|
||||
#include "src/core/lib/security/credentials/fake/fake_credentials.h"
|
||||
#include "src/core/tsi/fake_transport_security.h"
|
||||
|
|
@ -47,17 +47,17 @@ void test_add_same_port_twice() {
|
|||
grpc_channel_args args = {1, &a};
|
||||
|
||||
int port = grpc_pick_unused_port_or_die();
|
||||
char* addr = nullptr;
|
||||
grpc_core::UniquePtr<char> addr;
|
||||
grpc_completion_queue* cq = grpc_completion_queue_create_for_pluck(nullptr);
|
||||
grpc_server* server = grpc_server_create(&args, nullptr);
|
||||
grpc_server_credentials* fake_creds =
|
||||
grpc_fake_transport_security_server_credentials_create();
|
||||
gpr_join_host_port(&addr, "localhost", port);
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(server, addr, fake_creds));
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(server, addr, fake_creds) == 0);
|
||||
grpc_core::JoinHostPort(&addr, "localhost", port);
|
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(server, addr.get(), fake_creds));
|
||||
GPR_ASSERT(
|
||||
grpc_server_add_secure_http2_port(server, addr.get(), fake_creds) == 0);
|
||||
|
||||
grpc_server_credentials_release(fake_creds);
|
||||
gpr_free(addr);
|
||||
grpc_server_shutdown_and_notify(server, cq, nullptr);
|
||||
grpc_completion_queue_pluck(cq, nullptr, gpr_inf_future(GPR_CLOCK_REALTIME),
|
||||
nullptr);
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue