diff --git a/BUILD b/BUILD
index d2fce9d6fea..89e4fc0f58b 100644
--- a/BUILD
+++ b/BUILD
@@ -1010,8 +1010,10 @@ grpc_cc_library(
"madler_zlib",
"absl/container:inlined_vector",
"absl/status",
+ "absl/status:statusor",
"absl/strings",
"absl/types:optional",
+ "absl/container:flat_hash_map",
],
language = "c++",
public_hdrs = GRPC_PUBLIC_HDRS,
diff --git a/BUILD.gn b/BUILD.gn
index 5c9947b645c..b43ac2edee9 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1221,10 +1221,12 @@ config("grpc_config") {
":upb",
":absl/types:optional",
":absl/strings:strings",
+ ":absl/status:statusor",
":absl/status:status",
":absl/functional:bind_front",
":absl/container:inlined_vector",
":absl/container:flat_hash_set",
+ ":absl/container:flat_hash_map",
"//third_party/cares",
":address_sorting",
]
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 72e072c179b..cc94cf0b3ed 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -122,6 +122,7 @@ set(gRPC_ABSL_USED_TARGETS
absl_errno_saver
absl_exponential_biased
absl_fixed_array
+ absl_flat_hash_map
absl_flat_hash_set
absl_function_ref
absl_graphcycles_internal
@@ -140,12 +141,14 @@ set(gRPC_ABSL_USED_TARGETS
absl_malloc_internal
absl_memory
absl_optional
+ absl_raw_hash_map
absl_raw_hash_set
absl_raw_logging_internal
absl_span
absl_spinlock_wait
absl_stacktrace
absl_status
+ absl_statusor
absl_str_format
absl_str_format_internal
absl_strings
@@ -2009,10 +2012,12 @@ target_link_libraries(grpc
upb
absl::optional
absl::strings
+ absl::statusor
absl::status
absl::bind_front
absl::inlined_vector
absl::flat_hash_set
+ absl::flat_hash_map
)
if(_gRPC_PLATFORM_IOS OR _gRPC_PLATFORM_MAC)
target_link_libraries(grpc "-framework CoreFoundation")
@@ -2562,8 +2567,10 @@ target_link_libraries(grpc_unsecure
upb
absl::optional
absl::strings
+ absl::statusor
absl::status
absl::inlined_vector
+ absl::flat_hash_map
)
if(_gRPC_PLATFORM_IOS OR _gRPC_PLATFORM_MAC)
target_link_libraries(grpc_unsecure "-framework CoreFoundation")
@@ -16286,7 +16293,7 @@ generate_pkgconfig(
"high performance general RPC framework"
"${gRPC_CORE_VERSION}"
"gpr openssl"
- "-lgrpc -laddress_sorting -lre2 -lupb -lcares -lz -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_exponential_biased -labsl_hash -labsl_bad_variant_access -labsl_city -labsl_status -labsl_cord -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_bad_optional_access -labsl_raw_logging_internal -labsl_log_severity"
+ "-lgrpc -laddress_sorting -lre2 -lupb -lcares -lz -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_exponential_biased -labsl_hash -labsl_city -labsl_statusor -labsl_bad_variant_access -labsl_status -labsl_cord -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_bad_optional_access -labsl_raw_logging_internal -labsl_log_severity"
""
"grpc.pc")
@@ -16296,7 +16303,7 @@ generate_pkgconfig(
"high performance general RPC framework without SSL"
"${gRPC_CORE_VERSION}"
"gpr"
- "-lgrpc_unsecure -labsl_status -labsl_cord -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_bad_optional_access -labsl_raw_logging_internal -labsl_log_severity"
+ "-lgrpc_unsecure -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_exponential_biased -labsl_hash -labsl_city -labsl_statusor -labsl_bad_variant_access -labsl_status -labsl_cord -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_bad_optional_access -labsl_raw_logging_internal -labsl_log_severity"
""
"grpc_unsecure.pc")
@@ -16306,7 +16313,7 @@ generate_pkgconfig(
"C++ wrapper for gRPC"
"${gRPC_CPP_VERSION}"
"grpc"
- "-lgrpc++ -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_exponential_biased -labsl_hash -labsl_bad_variant_access -labsl_city -labsl_status -labsl_cord -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_bad_optional_access -labsl_raw_logging_internal -labsl_log_severity"
+ "-lgrpc++ -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_exponential_biased -labsl_hash -labsl_city -labsl_statusor -labsl_bad_variant_access -labsl_status -labsl_cord -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_bad_optional_access -labsl_raw_logging_internal -labsl_log_severity"
""
"grpc++.pc")
@@ -16316,6 +16323,6 @@ generate_pkgconfig(
"C++ wrapper for gRPC without SSL"
"${gRPC_CPP_VERSION}"
"grpc_unsecure"
- "-lgrpc++_unsecure -labsl_status -labsl_cord -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_bad_optional_access -labsl_raw_logging_internal -labsl_log_severity"
+ "-lgrpc++_unsecure -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_exponential_biased -labsl_hash -labsl_city -labsl_statusor -labsl_bad_variant_access -labsl_status -labsl_cord -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_bad_optional_access -labsl_raw_logging_internal -labsl_log_severity"
""
"grpc++_unsecure.pc")
diff --git a/Makefile b/Makefile
index eed15f1c9d4..67dcf0a2794 100644
--- a/Makefile
+++ b/Makefile
@@ -4343,6 +4343,7 @@ LIBGRPC_ABSEIL_SRC = \
third_party/abseil-cpp/absl/numeric/int128.cc \
third_party/abseil-cpp/absl/status/status.cc \
third_party/abseil-cpp/absl/status/status_payload_printer.cc \
+ third_party/abseil-cpp/absl/status/statusor.cc \
third_party/abseil-cpp/absl/strings/ascii.cc \
third_party/abseil-cpp/absl/strings/charconv.cc \
third_party/abseil-cpp/absl/strings/cord.cc \
diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml
index 16ae58c7c46..c4d06626e64 100644
--- a/build_autogenerated.yaml
+++ b/build_autogenerated.yaml
@@ -1395,10 +1395,12 @@ libs:
- upb
- absl/types:optional
- absl/strings:strings
+ - absl/status:statusor
- absl/status:status
- absl/functional:bind_front
- absl/container:inlined_vector
- absl/container:flat_hash_set
+ - absl/container:flat_hash_map
baselib: true
deps_linkage: static
dll: true
@@ -2079,8 +2081,10 @@ libs:
- upb
- absl/types:optional
- absl/strings:strings
+ - absl/status:statusor
- absl/status:status
- absl/container:inlined_vector
+ - absl/container:flat_hash_map
baselib: true
deps_linkage: static
dll: true
diff --git a/config.m4 b/config.m4
index a397d3ac8c3..564013dc9c1 100644
--- a/config.m4
+++ b/config.m4
@@ -644,6 +644,7 @@ if test "$PHP_GRPC" != "no"; then
third_party/abseil-cpp/absl/numeric/int128.cc \
third_party/abseil-cpp/absl/status/status.cc \
third_party/abseil-cpp/absl/status/status_payload_printer.cc \
+ third_party/abseil-cpp/absl/status/statusor.cc \
third_party/abseil-cpp/absl/strings/ascii.cc \
third_party/abseil-cpp/absl/strings/charconv.cc \
third_party/abseil-cpp/absl/strings/cord.cc \
diff --git a/config.w32 b/config.w32
index 46809387632..824d7fd69d1 100644
--- a/config.w32
+++ b/config.w32
@@ -611,6 +611,7 @@ if (PHP_GRPC != "no") {
"third_party\\abseil-cpp\\absl\\numeric\\int128.cc " +
"third_party\\abseil-cpp\\absl\\status\\status.cc " +
"third_party\\abseil-cpp\\absl\\status\\status_payload_printer.cc " +
+ "third_party\\abseil-cpp\\absl\\status\\statusor.cc " +
"third_party\\abseil-cpp\\absl\\strings\\ascii.cc " +
"third_party\\abseil-cpp\\absl\\strings\\charconv.cc " +
"third_party\\abseil-cpp\\absl\\strings\\cord.cc " +
diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec
index f07745cde53..af3cfcedc93 100644
--- a/gRPC-C++.podspec
+++ b/gRPC-C++.podspec
@@ -186,11 +186,13 @@ Pod::Spec.new do |s|
ss.dependency 'gRPC-Core', version
abseil_version = '1.20200923.2'
ss.dependency 'abseil/base/base', abseil_version
+ ss.dependency 'abseil/container/flat_hash_map', abseil_version
ss.dependency 'abseil/container/flat_hash_set', abseil_version
ss.dependency 'abseil/container/inlined_vector', abseil_version
ss.dependency 'abseil/functional/bind_front', abseil_version
ss.dependency 'abseil/memory/memory', abseil_version
ss.dependency 'abseil/status/status', abseil_version
+ ss.dependency 'abseil/status/statusor', abseil_version
ss.dependency 'abseil/strings/str_format', abseil_version
ss.dependency 'abseil/strings/strings', abseil_version
ss.dependency 'abseil/synchronization/synchronization', abseil_version
diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec
index f5a666e15f0..71c5a3be867 100644
--- a/gRPC-Core.podspec
+++ b/gRPC-Core.podspec
@@ -175,11 +175,13 @@ Pod::Spec.new do |s|
ss.dependency "#{s.name}/Interface", version
ss.dependency 'BoringSSL-GRPC', '0.0.14'
ss.dependency 'abseil/base/base', abseil_version
+ ss.dependency 'abseil/container/flat_hash_map', abseil_version
ss.dependency 'abseil/container/flat_hash_set', abseil_version
ss.dependency 'abseil/container/inlined_vector', abseil_version
ss.dependency 'abseil/functional/bind_front', abseil_version
ss.dependency 'abseil/memory/memory', abseil_version
ss.dependency 'abseil/status/status', abseil_version
+ ss.dependency 'abseil/status/statusor', abseil_version
ss.dependency 'abseil/strings/str_format', abseil_version
ss.dependency 'abseil/strings/strings', abseil_version
ss.dependency 'abseil/synchronization/synchronization', abseil_version
diff --git a/grpc.gemspec b/grpc.gemspec
index 24d607a0dbe..6930bae1f87 100644
--- a/grpc.gemspec
+++ b/grpc.gemspec
@@ -1242,6 +1242,7 @@ Gem::Specification.new do |s|
s.files += %w( third_party/abseil-cpp/absl/base/port.h )
s.files += %w( third_party/abseil-cpp/absl/base/thread_annotations.h )
s.files += %w( third_party/abseil-cpp/absl/container/fixed_array.h )
+ s.files += %w( third_party/abseil-cpp/absl/container/flat_hash_map.h )
s.files += %w( third_party/abseil-cpp/absl/container/flat_hash_set.h )
s.files += %w( third_party/abseil-cpp/absl/container/inlined_vector.h )
s.files += %w( third_party/abseil-cpp/absl/container/internal/common.h )
@@ -1256,6 +1257,7 @@ Gem::Specification.new do |s|
s.files += %w( third_party/abseil-cpp/absl/container/internal/have_sse.h )
s.files += %w( third_party/abseil-cpp/absl/container/internal/inlined_vector.h )
s.files += %w( third_party/abseil-cpp/absl/container/internal/layout.h )
+ s.files += %w( third_party/abseil-cpp/absl/container/internal/raw_hash_map.h )
s.files += %w( third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc )
s.files += %w( third_party/abseil-cpp/absl/container/internal/raw_hash_set.h )
s.files += %w( third_party/abseil-cpp/absl/debugging/internal/address_is_readable.cc )
@@ -1299,10 +1301,13 @@ Gem::Specification.new do |s|
s.files += %w( third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc )
s.files += %w( third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc )
s.files += %w( third_party/abseil-cpp/absl/status/internal/status_internal.h )
+ s.files += %w( third_party/abseil-cpp/absl/status/internal/statusor_internal.h )
s.files += %w( third_party/abseil-cpp/absl/status/status.cc )
s.files += %w( third_party/abseil-cpp/absl/status/status.h )
s.files += %w( third_party/abseil-cpp/absl/status/status_payload_printer.cc )
s.files += %w( third_party/abseil-cpp/absl/status/status_payload_printer.h )
+ s.files += %w( third_party/abseil-cpp/absl/status/statusor.cc )
+ s.files += %w( third_party/abseil-cpp/absl/status/statusor.h )
s.files += %w( third_party/abseil-cpp/absl/strings/ascii.cc )
s.files += %w( third_party/abseil-cpp/absl/strings/ascii.h )
s.files += %w( third_party/abseil-cpp/absl/strings/charconv.cc )
diff --git a/grpc.gyp b/grpc.gyp
index 965a66d14ed..a9cb7b9d473 100644
--- a/grpc.gyp
+++ b/grpc.gyp
@@ -444,10 +444,12 @@
'upb',
'absl/types:optional',
'absl/strings:strings',
+ 'absl/status:statusor',
'absl/status:status',
'absl/functional:bind_front',
'absl/container:inlined_vector',
'absl/container:flat_hash_set',
+ 'absl/container:flat_hash_map',
],
'sources': [
'src/core/ext/filters/census/grpc_context.cc',
@@ -1075,8 +1077,10 @@
'upb',
'absl/types:optional',
'absl/strings:strings',
+ 'absl/status:statusor',
'absl/status:status',
'absl/container:inlined_vector',
+ 'absl/container:flat_hash_map',
],
'sources': [
'src/core/ext/filters/census/grpc_context.cc',
diff --git a/package.xml b/package.xml
index 2ec60d6e5df..86a65539804 100644
--- a/package.xml
+++ b/package.xml
@@ -1244,6 +1244,7 @@
+
@@ -1258,6 +1259,7 @@
+
@@ -1301,10 +1303,13 @@
+
+
+
diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc
index 77b806cd050..d4b9a08724a 100644
--- a/src/core/ext/filters/client_channel/client_channel.cc
+++ b/src/core/ext/filters/client_channel/client_channel.cc
@@ -314,7 +314,7 @@ class ChannelData {
ClientChannelFactory* client_channel_factory_;
const grpc_channel_args* channel_args_;
RefCountedPtr default_service_config_;
- UniquePtr server_name_;
+ std::string server_name_;
UniquePtr target_uri_;
channelz::ChannelNode* channelz_node_;
@@ -1607,12 +1607,10 @@ ChannelData::ChannelData(grpc_channel_element_args* args, grpc_error** error)
default_service_config_.reset();
return;
}
- grpc_uri* uri = grpc_uri_parse(server_uri, true);
- if (uri != nullptr && uri->path[0] != '\0') {
- server_name_.reset(
- gpr_strdup(uri->path[0] == '/' ? uri->path + 1 : uri->path));
+ absl::StatusOr uri = URI::Parse(server_uri);
+ if (uri.ok() && !uri->path().empty()) {
+ server_name_ = std::string(absl::StripPrefix(uri->path(), "/"));
}
- grpc_uri_destroy(uri);
char* proxy_name = nullptr;
grpc_channel_args* new_args = nullptr;
ProxyMapperRegistry::MapName(server_uri, args->channel_args, &proxy_name,
@@ -1981,7 +1979,7 @@ void ChannelData::UpdateServiceConfigInDataPlaneLocked() {
RefCountedPtr retry_throttle_data;
if (retry_throttle_config.has_value()) {
retry_throttle_data = internal::ServerRetryThrottleMap::GetDataForServer(
- server_name_.get(), retry_throttle_config.value().max_milli_tokens,
+ server_name_, retry_throttle_config.value().max_milli_tokens,
retry_throttle_config.value().milli_token_ratio);
}
// Grab ref to service config.
diff --git a/src/core/ext/filters/client_channel/http_proxy.cc b/src/core/ext/filters/client_channel/http_proxy.cc
index 8425a7afccd..f061c424c05 100644
--- a/src/core/ext/filters/client_channel/http_proxy.cc
+++ b/src/core/ext/filters/client_channel/http_proxy.cc
@@ -24,6 +24,7 @@
#include
#include "absl/strings/str_cat.h"
+#include "absl/strings/strip.h"
#include
#include
@@ -47,9 +48,10 @@ namespace {
* credentials if present in the 'http_proxy' env var, otherwise leaves it
* unchanged. It is caller's responsibility to gpr_free user_cred.
*/
+// TODO(hork): change this to return std::string
char* GetHttpProxyServer(const grpc_channel_args* args, char** user_cred) {
GPR_ASSERT(user_cred != nullptr);
- grpc_uri* uri = nullptr;
+ absl::StatusOr uri;
char* proxy_name = nullptr;
char** authority_strs = nullptr;
size_t authority_nstrs;
@@ -69,17 +71,20 @@ char* GetHttpProxyServer(const grpc_channel_args* args, char** user_cred) {
if (uri_str == nullptr) return nullptr;
// an emtpy value means "don't use proxy"
if (uri_str[0] == '\0') goto done;
- uri = grpc_uri_parse(uri_str, false /* suppress_errors */);
- if (uri == nullptr || uri->authority == nullptr) {
- gpr_log(GPR_ERROR, "cannot parse value of 'http_proxy' env var");
+ uri = URI::Parse(uri_str);
+ if (!uri.ok() || uri->authority().empty()) {
+ gpr_log(GPR_ERROR, "cannot parse value of 'http_proxy' env var. Error: %s",
+ uri.status().ToString().c_str());
goto done;
}
- if (strcmp(uri->scheme, "http") != 0) {
- gpr_log(GPR_ERROR, "'%s' scheme not supported in proxy URI", uri->scheme);
+ if (uri->scheme() != "http") {
+ gpr_log(GPR_ERROR, "'%s' scheme not supported in proxy URI",
+ uri->scheme().c_str());
goto done;
}
/* Split on '@' to separate user credentials from host */
- gpr_string_split(uri->authority, "@", &authority_strs, &authority_nstrs);
+ gpr_string_split(uri->authority().c_str(), "@", &authority_strs,
+ &authority_nstrs);
GPR_ASSERT(authority_nstrs != 0); /* should have at least 1 string */
if (authority_nstrs == 1) {
/* User cred not present in authority */
@@ -99,7 +104,6 @@ char* GetHttpProxyServer(const grpc_channel_args* args, char** user_cred) {
gpr_free(authority_strs);
done:
gpr_free(uri_str);
- grpc_uri_destroy(uri);
return proxy_name;
}
@@ -114,15 +118,15 @@ class HttpProxyMapper : public ProxyMapperInterface {
*name_to_resolve = GetHttpProxyServer(args, &user_cred);
if (*name_to_resolve == nullptr) return false;
char* no_proxy_str = nullptr;
- grpc_uri* uri = grpc_uri_parse(server_uri, false /* suppress_errors */);
- if (uri == nullptr || uri->path[0] == '\0') {
+ absl::StatusOr uri = URI::Parse(server_uri);
+ if (!uri.ok() || uri->path().empty()) {
gpr_log(GPR_ERROR,
"'http_proxy' environment variable set, but cannot "
- "parse server URI '%s' -- not using proxy",
- server_uri);
+ "parse server URI '%s' -- not using proxy. Error: %s",
+ server_uri, uri.status().ToString().c_str());
goto no_use_proxy;
}
- if (strcmp(uri->scheme, "unix") == 0) {
+ if (uri->scheme() == "unix") {
gpr_log(GPR_INFO, "not using proxy for Unix domain socket '%s'",
server_uri);
goto no_use_proxy;
@@ -135,9 +139,8 @@ class HttpProxyMapper : public ProxyMapperInterface {
bool use_proxy = true;
std::string server_host;
std::string server_port;
- if (!grpc_core::SplitHostPort(
- uri->path[0] == '/' ? uri->path + 1 : uri->path, &server_host,
- &server_port)) {
+ if (!SplitHostPort(absl::StripPrefix(uri->path(), "/"), &server_host,
+ &server_port)) {
gpr_log(GPR_INFO,
"unable to split host and port, not checking no_proxy list for "
"host '%s'",
@@ -173,7 +176,7 @@ class HttpProxyMapper : public ProxyMapperInterface {
grpc_arg args_to_add[2];
args_to_add[0] = grpc_channel_arg_string_create(
const_cast(GRPC_ARG_HTTP_CONNECT_SERVER),
- uri->path[0] == '/' ? uri->path + 1 : uri->path);
+ const_cast(absl::StripPrefix(uri->path(), "/").data()));
if (user_cred != nullptr) {
/* Use base64 encoding for user credentials as stated in RFC 7617 */
char* encoded_user_cred =
@@ -188,11 +191,9 @@ class HttpProxyMapper : public ProxyMapperInterface {
} else {
*new_args = grpc_channel_args_copy_and_add(args, args_to_add, 1);
}
- grpc_uri_destroy(uri);
gpr_free(user_cred);
return true;
no_use_proxy:
- if (uri != nullptr) grpc_uri_destroy(uri);
gpr_free(*name_to_resolve);
*name_to_resolve = nullptr;
gpr_free(user_cred);
diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
index edb098bc865..6a46a0bbc30 100644
--- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
+++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
@@ -68,6 +68,7 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_join.h"
+#include "absl/strings/strip.h"
#include "upb/upb.hpp"
@@ -426,7 +427,7 @@ class GrpcLb : public LoadBalancingPolicy {
void CreateOrUpdateChildPolicyLocked();
// Who the client is trying to communicate with.
- const char* server_name_ = nullptr;
+ std::string server_name_;
// Configurations for the policy.
RefCountedPtr config_;
@@ -756,8 +757,7 @@ GrpcLb::BalancerCallState::BalancerCallState(
// Init the LB call. Note that the LB call will progress every time there's
// activity in grpclb_policy_->interested_parties(), which is comprised of
// the polling entities from client_channel.
- GPR_ASSERT(grpclb_policy()->server_name_ != nullptr);
- GPR_ASSERT(grpclb_policy()->server_name_[0] != '\0');
+ GPR_ASSERT(!grpclb_policy()->server_name_.empty());
// Closure Initialization
GRPC_CLOSURE_INIT(&lb_on_initial_request_sent_, OnInitialRequestSent, this,
grpc_schedule_on_exec_ctx);
@@ -780,7 +780,7 @@ GrpcLb::BalancerCallState::BalancerCallState(
upb::Arena arena;
grpc_slice request_payload_slice = GrpcLbRequestCreate(
grpclb_policy()->config_->service_name().empty()
- ? grpclb_policy()->server_name_
+ ? grpclb_policy()->server_name_.c_str()
: grpclb_policy()->config_->service_name().c_str(),
arena.ptr());
send_message_payload_ =
@@ -1340,15 +1340,14 @@ GrpcLb::GrpcLb(Args args)
const grpc_arg* arg = grpc_channel_args_find(args.args, GRPC_ARG_SERVER_URI);
const char* server_uri = grpc_channel_arg_get_string(arg);
GPR_ASSERT(server_uri != nullptr);
- grpc_uri* uri = grpc_uri_parse(server_uri, true);
- GPR_ASSERT(uri->path[0] != '\0');
- server_name_ = gpr_strdup(uri->path[0] == '/' ? uri->path + 1 : uri->path);
+ absl::StatusOr uri = URI::Parse(server_uri);
+ GPR_ASSERT(uri.ok() && !uri->path().empty());
+ server_name_ = std::string(absl::StripPrefix(uri->path(), "/"));
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
gpr_log(GPR_INFO,
"[grpclb %p] Will use '%s' as the server name for LB request.",
- this, server_name_);
+ this, server_name_.c_str());
}
- grpc_uri_destroy(uri);
// Record LB call timeout.
arg = grpc_channel_args_find(args.args, GRPC_ARG_GRPCLB_CALL_TIMEOUT_MS);
lb_call_timeout_ms_ = grpc_channel_arg_get_integer(arg, {0, 0, INT_MAX});
@@ -1358,10 +1357,7 @@ GrpcLb::GrpcLb(Args args)
arg, {GRPC_GRPCLB_DEFAULT_FALLBACK_TIMEOUT_MS, 0, INT_MAX});
}
-GrpcLb::~GrpcLb() {
- gpr_free(const_cast(server_name_));
- grpc_channel_args_destroy(args_);
-}
+GrpcLb::~GrpcLb() { grpc_channel_args_destroy(args_); }
void GrpcLb::ShutdownLocked() {
shutting_down_ = true;
diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc b/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc
index 22d7531f53c..c92ee1b3c16 100644
--- a/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc
+++ b/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc
@@ -315,15 +315,14 @@ EdsLb::EdsLb(RefCountedPtr xds_client, Args args)
const char* server_uri =
grpc_channel_args_find_string(args.args, GRPC_ARG_SERVER_URI);
GPR_ASSERT(server_uri != nullptr);
- grpc_uri* uri = grpc_uri_parse(server_uri, true);
- GPR_ASSERT(uri->path[0] != '\0');
- server_name_ = uri->path[0] == '/' ? uri->path + 1 : uri->path;
- is_xds_uri_ = strcmp(uri->scheme, "xds") == 0;
+ absl::StatusOr uri = URI::Parse(server_uri);
+ GPR_ASSERT(uri.ok() && !uri->path().empty());
+ server_name_ = std::string(absl::StripPrefix(uri->path(), "/"));
+ is_xds_uri_ = uri->scheme() == "xds";
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
gpr_log(GPR_INFO, "[edslb %p] server name from channel (is_xds_uri=%d): %s",
this, is_xds_uri_, server_name_.c_str());
}
- grpc_uri_destroy(uri);
// EDS-only flow.
if (!is_xds_uri_) {
// Setup channelz linkage.
diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc
index f0bf0cda2fe..0060ad98820 100644
--- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc
+++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc
@@ -86,9 +86,9 @@ class AresDnsResolver : public Resolver {
void OnResolvedLocked(grpc_error* error);
/// DNS server to use (if not system default)
- char* dns_server_;
+ std::string dns_server_;
/// name to resolve (usually the same as target_name)
- char* name_to_resolve_;
+ std::string name_to_resolve_;
/// channel args
grpc_channel_args* channel_args_;
/// whether to request the service config
@@ -139,14 +139,9 @@ AresDnsResolver::AresDnsResolver(ResolverArgs args)
grpc_schedule_on_exec_ctx);
GRPC_CLOSURE_INIT(&on_resolved_, OnResolved, this, grpc_schedule_on_exec_ctx);
// Get name to resolve from URI path.
- const char* path = args.uri->path;
- if (path[0] == '/') ++path;
- name_to_resolve_ = gpr_strdup(path);
+ name_to_resolve_ = std::string(absl::StripPrefix(args.uri.path(), "/"));
// Get DNS server from URI authority.
- dns_server_ = nullptr;
- if (0 != strcmp(args.uri->authority, "")) {
- dns_server_ = gpr_strdup(args.uri->authority);
- }
+ dns_server_ = args.uri.authority();
channel_args_ = grpc_channel_args_copy(args.args);
// Disable service config option
const grpc_arg* arg = grpc_channel_args_find(
@@ -175,8 +170,6 @@ AresDnsResolver::AresDnsResolver(ResolverArgs args)
AresDnsResolver::~AresDnsResolver() {
GRPC_CARES_TRACE_LOG("resolver:%p destroying AresDnsResolver", this);
grpc_pollset_set_destroy(interested_parties_);
- gpr_free(dns_server_);
- gpr_free(name_to_resolve_);
grpc_channel_args_destroy(channel_args_);
}
@@ -439,8 +432,8 @@ void AresDnsResolver::StartResolvingLocked() {
resolving_ = true;
service_config_json_ = nullptr;
pending_request_ = grpc_dns_lookup_ares_locked(
- dns_server_, name_to_resolve_, kDefaultPort, interested_parties_,
- &on_resolved_, &addresses_,
+ dns_server_.c_str(), name_to_resolve_.c_str(), kDefaultPort,
+ interested_parties_, &on_resolved_, &addresses_,
enable_srv_queries_ ? &balancer_addresses_ : nullptr,
request_service_config_ ? &service_config_json_ : nullptr,
query_timeout_ms_, work_serializer());
@@ -455,7 +448,7 @@ void AresDnsResolver::StartResolvingLocked() {
class AresDnsResolverFactory : public ResolverFactory {
public:
- bool IsValidUri(const grpc_uri* /*uri*/) const override { return true; }
+ bool IsValidUri(const URI& /*uri*/) const override { return true; }
OrphanablePtr CreateResolver(ResolverArgs args) const override {
return MakeOrphanable(std::move(args));
diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc
index 2fd902d0338..7bf8bff1bfb 100644
--- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc
+++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc
@@ -425,7 +425,7 @@ void grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(
if (error != GRPC_ERROR_NONE) goto error_cleanup;
channel = grpc_ares_ev_driver_get_channel_locked(r->ev_driver);
// If dns_server is specified, use it.
- if (dns_server != nullptr) {
+ if (dns_server != nullptr && dns_server[0] != '\0') {
GRPC_CARES_TRACE_LOG("request:%p Using DNS server %s", r, dns_server);
grpc_resolved_address addr;
if (grpc_parse_ipv4_hostport(dns_server, &addr, false /* log_errors */)) {
diff --git a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc
index e17d84f414d..3e072aa3b11 100644
--- a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc
+++ b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc
@@ -74,7 +74,7 @@ class NativeDnsResolver : public Resolver {
void OnResolvedLocked(grpc_error* error);
/// name to resolve
- char* name_to_resolve_ = nullptr;
+ std::string name_to_resolve_;
/// channel args
grpc_channel_args* channel_args_ = nullptr;
/// pollset_set to drive the name resolution process
@@ -107,9 +107,7 @@ NativeDnsResolver::NativeDnsResolver(ResolverArgs args)
.set_multiplier(GRPC_DNS_RECONNECT_BACKOFF_MULTIPLIER)
.set_jitter(GRPC_DNS_RECONNECT_JITTER)
.set_max_backoff(GRPC_DNS_RECONNECT_MAX_BACKOFF_SECONDS * 1000)) {
- char* path = args.uri->path;
- if (path[0] == '/') ++path;
- name_to_resolve_ = gpr_strdup(path);
+ name_to_resolve_ = std::string(absl::StripPrefix(args.uri.path(), "/"));
channel_args_ = grpc_channel_args_copy(args.args);
const grpc_arg* arg = grpc_channel_args_find(
args.args, GRPC_ARG_DNS_MIN_TIME_BETWEEN_RESOLUTIONS_MS);
@@ -124,7 +122,6 @@ NativeDnsResolver::NativeDnsResolver(ResolverArgs args)
NativeDnsResolver::~NativeDnsResolver() {
grpc_channel_args_destroy(channel_args_);
grpc_pollset_set_destroy(interested_parties_);
- gpr_free(name_to_resolve_);
}
void NativeDnsResolver::StartLocked() { MaybeStartResolvingLocked(); }
@@ -269,8 +266,8 @@ void NativeDnsResolver::StartResolvingLocked() {
addresses_ = nullptr;
GRPC_CLOSURE_INIT(&on_resolved_, NativeDnsResolver::OnResolved, this,
grpc_schedule_on_exec_ctx);
- grpc_resolve_address(name_to_resolve_, kDefaultPort, interested_parties_,
- &on_resolved_, &addresses_);
+ grpc_resolve_address(name_to_resolve_.c_str(), kDefaultPort,
+ interested_parties_, &on_resolved_, &addresses_);
last_resolution_timestamp_ = grpc_core::ExecCtx::Get()->Now();
}
@@ -280,8 +277,8 @@ void NativeDnsResolver::StartResolvingLocked() {
class NativeDnsResolverFactory : public ResolverFactory {
public:
- bool IsValidUri(const grpc_uri* uri) const override {
- if (GPR_UNLIKELY(0 != strcmp(uri->authority, ""))) {
+ bool IsValidUri(const URI& uri) const override {
+ if (GPR_UNLIKELY(!uri.authority().empty())) {
gpr_log(GPR_ERROR, "authority based dns uri's not supported");
return false;
}
diff --git a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc
index 8b405f717e0..a779cd47dfc 100644
--- a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc
+++ b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc
@@ -362,7 +362,7 @@ namespace {
class FakeResolverFactory : public ResolverFactory {
public:
- bool IsValidUri(const grpc_uri* /*uri*/) const override { return true; }
+ bool IsValidUri(const URI& /*uri*/) const override { return true; }
OrphanablePtr CreateResolver(ResolverArgs args) const override {
return MakeOrphanable(std::move(args));
diff --git a/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc b/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc
index 4b1f0a1833d..dfa2dd9b972 100644
--- a/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc
+++ b/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc
@@ -23,6 +23,8 @@
#include
#include
+#include "absl/strings/str_split.h"
+
#include
#include
@@ -78,30 +80,20 @@ void SockaddrResolver::StartLocked() {
// Factory
//
-void DoNothing(void* /*ignored*/) {}
-
-bool ParseUri(const grpc_uri* uri,
- bool parse(const grpc_uri* uri, grpc_resolved_address* dst),
+bool ParseUri(const URI& uri,
+ bool parse(const URI& uri, grpc_resolved_address* dst),
ServerAddressList* addresses) {
- if (0 != strcmp(uri->authority, "")) {
+ if (!uri.authority().empty()) {
gpr_log(GPR_ERROR, "authority-based URIs not supported by the %s scheme",
- uri->scheme);
+ uri.scheme().c_str());
return false;
}
// Construct addresses.
- grpc_slice path_slice =
- grpc_slice_new(uri->path, strlen(uri->path), DoNothing);
- grpc_slice_buffer path_parts;
- grpc_slice_buffer_init(&path_parts);
- grpc_slice_split(path_slice, ",", &path_parts);
bool errors_found = false;
- for (size_t i = 0; i < path_parts.count; i++) {
- grpc_uri ith_uri = *uri;
- grpc_core::UniquePtr part_str(
- grpc_slice_to_c_string(path_parts.slices[i]));
- ith_uri.path = part_str.get();
+ for (absl::string_view ith_path : absl::StrSplit(uri.path(), ',')) {
+ URI ith_uri(uri.scheme(), "", std::string(ith_path), {}, "");
grpc_resolved_address addr;
- if (!parse(&ith_uri, &addr)) {
+ if (!parse(ith_uri, &addr)) {
errors_found = true;
break;
}
@@ -109,14 +101,11 @@ bool ParseUri(const grpc_uri* uri,
addresses->emplace_back(addr, nullptr /* args */);
}
}
- grpc_slice_buffer_destroy_internal(&path_parts);
- grpc_slice_unref_internal(path_slice);
return !errors_found;
}
OrphanablePtr CreateSockaddrResolver(
- ResolverArgs args,
- bool parse(const grpc_uri* uri, grpc_resolved_address* dst)) {
+ ResolverArgs args, bool parse(const URI& uri, grpc_resolved_address* dst)) {
ServerAddressList addresses;
if (!ParseUri(args.uri, parse, &addresses)) return nullptr;
// Instantiate resolver.
@@ -126,7 +115,7 @@ OrphanablePtr CreateSockaddrResolver(
class IPv4ResolverFactory : public ResolverFactory {
public:
- bool IsValidUri(const grpc_uri* uri) const override {
+ bool IsValidUri(const URI& uri) const override {
return ParseUri(uri, grpc_parse_ipv4, nullptr);
}
@@ -139,7 +128,7 @@ class IPv4ResolverFactory : public ResolverFactory {
class IPv6ResolverFactory : public ResolverFactory {
public:
- bool IsValidUri(const grpc_uri* uri) const override {
+ bool IsValidUri(const URI& uri) const override {
return ParseUri(uri, grpc_parse_ipv6, nullptr);
}
@@ -153,7 +142,7 @@ class IPv6ResolverFactory : public ResolverFactory {
#ifdef GRPC_HAVE_UNIX_SOCKET
class UnixResolverFactory : public ResolverFactory {
public:
- bool IsValidUri(const grpc_uri* uri) const override {
+ bool IsValidUri(const URI& uri) const override {
return ParseUri(uri, grpc_parse_unix, nullptr);
}
@@ -161,9 +150,8 @@ class UnixResolverFactory : public ResolverFactory {
return CreateSockaddrResolver(std::move(args), grpc_parse_unix);
}
- grpc_core::UniquePtr GetDefaultAuthority(
- grpc_uri* /*uri*/) const override {
- return grpc_core::UniquePtr(gpr_strdup("localhost"));
+ std::string GetDefaultAuthority(const URI& uri) const override {
+ return "localhost";
}
const char* scheme() const override { return "unix"; }
@@ -171,7 +159,7 @@ class UnixResolverFactory : public ResolverFactory {
class UnixAbstractResolverFactory : public ResolverFactory {
public:
- bool IsValidUri(const grpc_uri* uri) const override {
+ bool IsValidUri(const URI& uri) const override {
return ParseUri(uri, grpc_parse_unix_abstract, nullptr);
}
@@ -179,9 +167,8 @@ class UnixAbstractResolverFactory : public ResolverFactory {
return CreateSockaddrResolver(std::move(args), grpc_parse_unix_abstract);
}
- grpc_core::UniquePtr GetDefaultAuthority(
- grpc_uri* /*uri*/) const override {
- return grpc_core::UniquePtr(gpr_strdup("localhost"));
+ std::string GetDefaultAuthority(const URI& /*uri*/) const override {
+ return "localhost";
}
const char* scheme() const override { return "unix-abstract"; }
diff --git a/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc b/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc
index af957f74993..e9028099a6f 100644
--- a/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc
+++ b/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc
@@ -48,11 +48,9 @@ class XdsResolver : public Resolver {
explicit XdsResolver(ResolverArgs args)
: Resolver(std::move(args.work_serializer),
std::move(args.result_handler)),
+ server_name_(absl::StripPrefix(args.uri.path(), "/")),
args_(grpc_channel_args_copy(args.args)),
interested_parties_(args.pollset_set) {
- char* path = args.uri->path;
- if (path[0] == '/') ++path;
- server_name_ = path;
if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_resolver_trace)) {
gpr_log(GPR_INFO, "[xds_resolver %p] created for server name %s", this,
server_name_.c_str());
@@ -762,8 +760,8 @@ void XdsResolver::MaybeRemoveUnusedClusters() {
class XdsResolverFactory : public ResolverFactory {
public:
- bool IsValidUri(const grpc_uri* uri) const override {
- if (GPR_UNLIKELY(0 != strcmp(uri->authority, ""))) {
+ bool IsValidUri(const URI& uri) const override {
+ if (GPR_UNLIKELY(!uri.authority().empty())) {
gpr_log(GPR_ERROR, "URI authority not supported");
return false;
}
diff --git a/src/core/ext/filters/client_channel/resolver_factory.h b/src/core/ext/filters/client_channel/resolver_factory.h
index d8dd801ae09..7b967461525 100644
--- a/src/core/ext/filters/client_channel/resolver_factory.h
+++ b/src/core/ext/filters/client_channel/resolver_factory.h
@@ -21,6 +21,8 @@
#include
+#include "absl/strings/strip.h"
+
#include
#include "src/core/ext/filters/client_channel/resolver.h"
@@ -33,7 +35,7 @@ namespace grpc_core {
struct ResolverArgs {
/// The parsed URI to resolve.
- grpc_uri* uri = nullptr;
+ URI uri;
/// Channel args to be included in resolver results.
const grpc_channel_args* args = nullptr;
/// Used to drive I/O in the name resolution process.
@@ -48,17 +50,15 @@ class ResolverFactory {
public:
/// Returns a bool indicating whether the input uri is valid to create a
/// resolver.
- virtual bool IsValidUri(const grpc_uri* uri) const = 0;
+ virtual bool IsValidUri(const URI& uri) const = 0;
/// Returns a new resolver instance.
virtual OrphanablePtr CreateResolver(ResolverArgs args) const = 0;
/// Returns a string representing the default authority to use for this
/// scheme.
- virtual grpc_core::UniquePtr GetDefaultAuthority(grpc_uri* uri) const {
- const char* path = uri->path;
- if (path[0] == '/') ++path;
- return grpc_core::UniquePtr(gpr_strdup(path));
+ virtual std::string GetDefaultAuthority(const URI& uri) const {
+ return std::string(absl::StripPrefix(uri.path(), "/"));
}
/// Returns the URI scheme that this factory implements.
diff --git a/src/core/ext/filters/client_channel/resolver_registry.cc b/src/core/ext/filters/client_channel/resolver_registry.cc
index c8b7d8dcc02..42b69bbb2ee 100644
--- a/src/core/ext/filters/client_channel/resolver_registry.cc
+++ b/src/core/ext/filters/client_channel/resolver_registry.cc
@@ -24,6 +24,7 @@
#include "absl/container/inlined_vector.h"
#include "absl/strings/str_cat.h"
+#include "absl/strings/str_format.h"
#include
#include
@@ -50,9 +51,9 @@ class RegistryState {
factories_.push_back(std::move(factory));
}
- ResolverFactory* LookupResolverFactory(const char* scheme) const {
+ ResolverFactory* LookupResolverFactory(absl::string_view scheme) const {
for (size_t i = 0; i < factories_.size(); ++i) {
- if (strcmp(scheme, factories_[i]->scheme()) == 0) {
+ if (scheme == factories_[i]->scheme()) {
return factories_[i].get();
}
}
@@ -65,26 +66,35 @@ class RegistryState {
// point to the parsed URI.
// If \a default_prefix_ needs to be prepended, sets \a canonical_target
// to the canonical target string.
- ResolverFactory* FindResolverFactory(const char* target, grpc_uri** uri,
+ ResolverFactory* FindResolverFactory(absl::string_view target, URI* uri,
std::string* canonical_target) const {
GPR_ASSERT(uri != nullptr);
- *uri = grpc_uri_parse(target, true);
+ absl::StatusOr tmp_uri = URI::Parse(target);
ResolverFactory* factory =
- *uri == nullptr ? nullptr : LookupResolverFactory((*uri)->scheme);
- if (factory == nullptr) {
- grpc_uri_destroy(*uri);
- *canonical_target = absl::StrCat(default_prefix_.get(), target);
- *uri = grpc_uri_parse(canonical_target->c_str(), true);
- factory =
- *uri == nullptr ? nullptr : LookupResolverFactory((*uri)->scheme);
- if (factory == nullptr) {
- grpc_uri_destroy(grpc_uri_parse(target, false));
- grpc_uri_destroy(grpc_uri_parse(canonical_target->c_str(), false));
- gpr_log(GPR_ERROR, "don't know how to resolve '%s' or '%s'", target,
- canonical_target->c_str());
- }
+ tmp_uri.ok() ? LookupResolverFactory(tmp_uri->scheme()) : nullptr;
+ if (factory != nullptr) {
+ *uri = *tmp_uri;
+ return factory;
+ }
+ *canonical_target = absl::StrCat(default_prefix_.get(), target);
+ absl::StatusOr tmp_uri2 = URI::Parse(*canonical_target);
+ factory =
+ tmp_uri2.ok() ? LookupResolverFactory(tmp_uri2->scheme()) : nullptr;
+ if (factory != nullptr) {
+ *uri = *tmp_uri2;
+ return factory;
}
- return factory;
+ if (!tmp_uri.ok() || !tmp_uri2.ok()) {
+ gpr_log(GPR_ERROR, "%s",
+ absl::StrFormat("Error parsing URI(s). '%s':%s; '%s':%s", target,
+ tmp_uri.status().ToString(), *canonical_target,
+ tmp_uri2.status().ToString())
+ .c_str());
+ return nullptr;
+ }
+ gpr_log(GPR_ERROR, "Don't know how to resolve '%s' or '%s'.",
+ std::string(target).c_str(), canonical_target->c_str());
+ return nullptr;
}
private:
@@ -134,14 +144,12 @@ ResolverFactory* ResolverRegistry::LookupResolverFactory(const char* scheme) {
return g_state->LookupResolverFactory(scheme);
}
-bool ResolverRegistry::IsValidTarget(const char* target) {
- grpc_uri* uri = nullptr;
+bool ResolverRegistry::IsValidTarget(absl::string_view target) {
+ URI uri;
std::string canonical_target;
ResolverFactory* factory =
g_state->FindResolverFactory(target, &uri, &canonical_target);
- bool result = factory == nullptr ? false : factory->IsValidUri(uri);
- grpc_uri_destroy(uri);
- return result;
+ return factory == nullptr ? false : factory->IsValidUri(uri);
}
OrphanablePtr ResolverRegistry::CreateResolver(
@@ -150,12 +158,10 @@ OrphanablePtr ResolverRegistry::CreateResolver(
std::shared_ptr work_serializer,
std::unique_ptr result_handler) {
GPR_ASSERT(g_state != nullptr);
- grpc_uri* uri = nullptr;
std::string canonical_target;
- ResolverFactory* factory =
- g_state->FindResolverFactory(target, &uri, &canonical_target);
ResolverArgs resolver_args;
- resolver_args.uri = uri;
+ ResolverFactory* factory = g_state->FindResolverFactory(
+ target, &resolver_args.uri, &canonical_target);
resolver_args.args = args;
resolver_args.pollset_set = pollset_set;
resolver_args.work_serializer = std::move(work_serializer);
@@ -163,30 +169,26 @@ OrphanablePtr ResolverRegistry::CreateResolver(
OrphanablePtr resolver =
factory == nullptr ? nullptr
: factory->CreateResolver(std::move(resolver_args));
- grpc_uri_destroy(uri);
return resolver;
}
-grpc_core::UniquePtr ResolverRegistry::GetDefaultAuthority(
- const char* target) {
+std::string ResolverRegistry::GetDefaultAuthority(absl::string_view target) {
GPR_ASSERT(g_state != nullptr);
- grpc_uri* uri = nullptr;
+ URI uri;
std::string canonical_target;
ResolverFactory* factory =
g_state->FindResolverFactory(target, &uri, &canonical_target);
- grpc_core::UniquePtr authority =
- factory == nullptr ? nullptr : factory->GetDefaultAuthority(uri);
- grpc_uri_destroy(uri);
+ std::string authority =
+ factory == nullptr ? "" : factory->GetDefaultAuthority(uri);
return authority;
}
grpc_core::UniquePtr ResolverRegistry::AddDefaultPrefixIfNeeded(
const char* target) {
GPR_ASSERT(g_state != nullptr);
- grpc_uri* uri = nullptr;
+ URI uri;
std::string canonical_target;
g_state->FindResolverFactory(target, &uri, &canonical_target);
- grpc_uri_destroy(uri);
return grpc_core::UniquePtr(canonical_target.empty()
? gpr_strdup(target)
: gpr_strdup(canonical_target.c_str()));
diff --git a/src/core/ext/filters/client_channel/resolver_registry.h b/src/core/ext/filters/client_channel/resolver_registry.h
index bf34216b2cf..f2e5b9c195f 100644
--- a/src/core/ext/filters/client_channel/resolver_registry.h
+++ b/src/core/ext/filters/client_channel/resolver_registry.h
@@ -51,7 +51,7 @@ class ResolverRegistry {
};
/// Checks whether the user input \a target is valid to create a resolver.
- static bool IsValidTarget(const char* target);
+ static bool IsValidTarget(absl::string_view target);
/// Creates a resolver given \a target.
/// First tries to parse \a target as a URI. If this succeeds, tries
@@ -73,7 +73,7 @@ class ResolverRegistry {
std::unique_ptr result_handler);
/// Returns the default authority to pass from a client for \a target.
- static grpc_core::UniquePtr GetDefaultAuthority(const char* target);
+ static std::string GetDefaultAuthority(absl::string_view target);
/// Returns \a target with the default prefix prepended, if needed.
static grpc_core::UniquePtr AddDefaultPrefixIfNeeded(
diff --git a/src/core/ext/filters/client_channel/retry_throttle.cc b/src/core/ext/filters/client_channel/retry_throttle.cc
index 65df8034d71..03c7a673efd 100644
--- a/src/core/ext/filters/client_channel/retry_throttle.cc
+++ b/src/core/ext/filters/client_channel/retry_throttle.cc
@@ -23,6 +23,8 @@
#include
#include
+#include
+
#include
#include
#include
@@ -164,20 +166,20 @@ void ServerRetryThrottleMap::Shutdown() {
}
RefCountedPtr ServerRetryThrottleMap::GetDataForServer(
- const char* server_name, intptr_t max_milli_tokens,
+ const std::string& server_name, intptr_t max_milli_tokens,
intptr_t milli_token_ratio) {
RefCountedPtr result;
gpr_mu_lock(&g_mu);
ServerRetryThrottleData* throttle_data =
static_cast(
- grpc_avl_get(g_avl, const_cast(server_name), nullptr));
+ grpc_avl_get(g_avl, const_cast(server_name.c_str()), nullptr));
if (throttle_data == nullptr ||
throttle_data->max_milli_tokens() != max_milli_tokens ||
throttle_data->milli_token_ratio() != milli_token_ratio) {
// Entry not found, or found with old parameters. Create a new one.
result = MakeRefCounted(
max_milli_tokens, milli_token_ratio, throttle_data);
- g_avl = grpc_avl_add(g_avl, gpr_strdup(server_name),
+ g_avl = grpc_avl_add(g_avl, gpr_strdup(server_name.c_str()),
result->Ref().release(), nullptr);
} else {
// Entry found. Return a new ref to it.
diff --git a/src/core/ext/filters/client_channel/retry_throttle.h b/src/core/ext/filters/client_channel/retry_throttle.h
index e40363fd3d1..583def35c93 100644
--- a/src/core/ext/filters/client_channel/retry_throttle.h
+++ b/src/core/ext/filters/client_channel/retry_throttle.h
@@ -67,7 +67,7 @@ class ServerRetryThrottleMap {
/// Returns the failure data for \a server_name, creating a new entry if
/// needed.
static RefCountedPtr GetDataForServer(
- const char* server_name, intptr_t max_milli_tokens,
+ const std::string& server_name, intptr_t max_milli_tokens,
intptr_t milli_token_ratio);
};
diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc
index 6834ec65224..9885f4cdcff 100644
--- a/src/core/ext/filters/client_channel/subchannel.cc
+++ b/src/core/ext/filters/client_channel/subchannel.cc
@@ -929,10 +929,12 @@ const char* Subchannel::GetUriFromSubchannelAddressArg(
namespace {
void UriToSockaddr(const char* uri_str, grpc_resolved_address* addr) {
- grpc_uri* uri = grpc_uri_parse(uri_str, false /* suppress_errors */);
- GPR_ASSERT(uri != nullptr);
- if (!grpc_parse_uri(uri, addr)) memset(addr, 0, sizeof(*addr));
- grpc_uri_destroy(uri);
+ absl::StatusOr uri = URI::Parse(uri_str);
+ if (!uri.ok()) {
+ gpr_log(GPR_ERROR, "%s", uri.status().ToString().c_str());
+ GPR_ASSERT(uri.ok());
+ }
+ if (!grpc_parse_uri(*uri, addr)) memset(addr, 0, sizeof(*addr));
}
} // namespace
diff --git a/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc b/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc
index b3f99281054..5d578307a9e 100644
--- a/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc
+++ b/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc
@@ -134,18 +134,18 @@ std::string ServerLoadReportingCallData::GetCensusSafeClientIpString() {
"metadata.");
return "";
}
- // Parse the client URI string into grpc_uri.
- grpc_uri* client_uri = grpc_uri_parse(client_uri_str, true);
- if (client_uri == nullptr) {
+ absl::StatusOr client_uri =
+ grpc_core::URI::Parse(client_uri_str);
+ if (!client_uri.ok()) {
gpr_log(GPR_ERROR,
"Unable to parse the client URI string (peer string) to a client "
- "URI.");
+ "URI. Error: %s",
+ client_uri.status().ToString().c_str());
return "";
}
// Parse the client URI into grpc_resolved_address.
grpc_resolved_address resolved_address;
- bool success = grpc_parse_uri(client_uri, &resolved_address);
- grpc_uri_destroy(client_uri);
+ bool success = grpc_parse_uri(*client_uri, &resolved_address);
if (!success) {
gpr_log(GPR_ERROR,
"Unable to parse client URI into a grpc_resolved_address.");
diff --git a/src/core/ext/transport/chttp2/client/authority.cc b/src/core/ext/transport/chttp2/client/authority.cc
index bad3153b013..8e4f8c1bbdf 100644
--- a/src/core/ext/transport/chttp2/client/authority.cc
+++ b/src/core/ext/transport/chttp2/client/authority.cc
@@ -26,7 +26,7 @@ grpc_channel_args* grpc_default_authority_add_if_not_present(
grpc_channel_args_find(args, GRPC_ARG_DEFAULT_AUTHORITY) != nullptr;
grpc_arg new_args[1];
size_t num_new_args = 0;
- grpc_core::UniquePtr default_authority;
+ std::string default_authority;
if (!has_default_authority) {
const grpc_arg* server_uri_arg =
grpc_channel_args_find(args, GRPC_ARG_SERVER_URI);
@@ -34,9 +34,9 @@ grpc_channel_args* grpc_default_authority_add_if_not_present(
GPR_ASSERT(server_uri_str != nullptr);
default_authority =
grpc_core::ResolverRegistry::GetDefaultAuthority(server_uri_str);
- GPR_ASSERT(default_authority != nullptr);
new_args[num_new_args++] = grpc_channel_arg_string_create(
- const_cast(GRPC_ARG_DEFAULT_AUTHORITY), default_authority.get());
+ const_cast(GRPC_ARG_DEFAULT_AUTHORITY),
+ const_cast(default_authority.c_str()));
}
return grpc_channel_args_copy_and_add(args, new_args, num_new_args);
}
diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc
index 0b22c7de367..7edf6aa34ed 100644
--- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc
+++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc
@@ -78,9 +78,8 @@ class Chttp2SecureClientChannelFactory : public ClientChannelFactory {
// First, check the authority override channel arg.
// Otherwise, get it from the server name used to construct the
// channel.
- grpc_core::UniquePtr authority(
- gpr_strdup(FindAuthorityOverrideInArgs(args)));
- if (authority == nullptr) {
+ std::string authority(FindAuthorityOverrideInArgs(args));
+ if (authority.empty()) {
const char* server_uri_str =
grpc_channel_args_find_string(args, GRPC_ARG_SERVER_URI);
GPR_ASSERT(server_uri_str != nullptr);
@@ -92,7 +91,8 @@ class Chttp2SecureClientChannelFactory : public ClientChannelFactory {
// If the channel args don't already contain GRPC_ARG_DEFAULT_AUTHORITY,
// add the arg, setting it to the value just obtained.
args_to_add[num_args_to_add++] = grpc_channel_arg_string_create(
- const_cast(GRPC_ARG_DEFAULT_AUTHORITY), authority.get());
+ const_cast(GRPC_ARG_DEFAULT_AUTHORITY),
+ const_cast(authority.c_str()));
}
grpc_channel_args* args_with_authority =
grpc_channel_args_copy_and_add(args, args_to_add, num_args_to_add);
@@ -101,12 +101,12 @@ class Chttp2SecureClientChannelFactory : public ClientChannelFactory {
RefCountedPtr
subchannel_security_connector =
channel_credentials->create_security_connector(
- /*call_creds=*/nullptr, authority.get(), args_with_authority,
+ /*call_creds=*/nullptr, authority.c_str(), args_with_authority,
&new_args_from_connector);
if (subchannel_security_connector == nullptr) {
gpr_log(GPR_ERROR,
"Failed to create secure subchannel for secure name '%s'",
- authority.get());
+ authority.c_str());
grpc_channel_args_destroy(args_with_authority);
return nullptr;
}
diff --git a/src/core/lib/channel/channelz.cc b/src/core/lib/channel/channelz.cc
index c0dbfd05f48..188203cbbbe 100644
--- a/src/core/lib/channel/channelz.cc
+++ b/src/core/lib/channel/channelz.cc
@@ -20,6 +20,8 @@
#include "src/core/lib/channel/channelz.h"
+#include "absl/strings/strip.h"
+
#include
#include
#include
@@ -344,14 +346,12 @@ void PopulateSocketAddressJson(Json::Object* json, const char* name,
const char* addr_str) {
if (addr_str == nullptr) return;
Json::Object data;
- grpc_uri* uri = grpc_uri_parse(addr_str, true);
- if ((uri != nullptr) && ((strcmp(uri->scheme, "ipv4") == 0) ||
- (strcmp(uri->scheme, "ipv6") == 0))) {
- const char* host_port = uri->path;
- if (*host_port == '/') ++host_port;
+ absl::StatusOr uri = URI::Parse(addr_str);
+ if (uri.ok() && (uri->scheme() == "ipv4" || uri->scheme() == "ipv6")) {
std::string host;
std::string port;
- GPR_ASSERT(SplitHostPort(host_port, &host, &port));
+ GPR_ASSERT(
+ SplitHostPort(absl::StripPrefix(uri->path(), "/"), &host, &port));
int port_num = -1;
if (!port.empty()) {
port_num = atoi(port.data());
@@ -362,16 +362,15 @@ void PopulateSocketAddressJson(Json::Object* json, const char* name,
{"ip_address", b64_host},
};
gpr_free(b64_host);
- } else if (uri != nullptr && strcmp(uri->scheme, "unix") == 0) {
+ } else if (uri.ok() && uri->scheme() == "unix") {
data["uds_address"] = Json::Object{
- {"filename", uri->path},
+ {"filename", uri->path()},
};
} else {
data["other_address"] = Json::Object{
{"name", addr_str},
};
}
- grpc_uri_destroy(uri);
(*json)[name] = std::move(data);
}
diff --git a/src/core/lib/iomgr/parse_address.cc b/src/core/lib/iomgr/parse_address.cc
index 9e8f7859e00..9afac74fd41 100644
--- a/src/core/lib/iomgr/parse_address.cc
+++ b/src/core/lib/iomgr/parse_address.cc
@@ -18,18 +18,20 @@
#include
-#include "absl/strings/str_cat.h"
-
-#include "src/core/lib/iomgr/grpc_if_nametoindex.h"
#include "src/core/lib/iomgr/parse_address.h"
-#include "src/core/lib/iomgr/sockaddr.h"
-#include "src/core/lib/iomgr/socket_utils.h"
#include
#include
#ifdef GRPC_HAVE_UNIX_SOCKET
#include
#endif
+#ifdef GRPC_POSIX_SOCKET
+#include
+#include
+#endif
+
+#include "absl/strings/str_cat.h"
+#include "absl/strings/strip.h"
#include
#include
@@ -37,21 +39,21 @@
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/host_port.h"
-
-#ifdef GRPC_POSIX_SOCKET
-#include
-#include
-#endif
+#include "src/core/lib/iomgr/grpc_if_nametoindex.h"
+#include "src/core/lib/iomgr/sockaddr.h"
+#include "src/core/lib/iomgr/socket_utils.h"
#ifdef GRPC_HAVE_UNIX_SOCKET
-bool grpc_parse_unix(const grpc_uri* uri,
+bool grpc_parse_unix(const grpc_core::URI& uri,
grpc_resolved_address* resolved_addr) {
- if (strcmp("unix", uri->scheme) != 0) {
- gpr_log(GPR_ERROR, "Expected 'unix' scheme, got '%s'", uri->scheme);
+ if (uri.scheme() != "unix") {
+ gpr_log(GPR_ERROR, "Expected 'unix' scheme, got '%s'",
+ uri.scheme().c_str());
return false;
}
- grpc_error* error = grpc_core::UnixSockaddrPopulate(uri->path, resolved_addr);
+ grpc_error* error =
+ grpc_core::UnixSockaddrPopulate(uri.path(), resolved_addr);
if (error != GRPC_ERROR_NONE) {
gpr_log(GPR_ERROR, "%s", grpc_error_string(error));
GRPC_ERROR_UNREF(error);
@@ -60,15 +62,15 @@ bool grpc_parse_unix(const grpc_uri* uri,
return true;
}
-bool grpc_parse_unix_abstract(const grpc_uri* uri,
+bool grpc_parse_unix_abstract(const grpc_core::URI& uri,
grpc_resolved_address* resolved_addr) {
- if (strcmp("unix-abstract", uri->scheme) != 0) {
+ if (uri.scheme() != "unix-abstract") {
gpr_log(GPR_ERROR, "Expected 'unix-abstract' scheme, got '%s'",
- uri->scheme);
+ uri.scheme().c_str());
return false;
}
grpc_error* error =
- grpc_core::UnixAbstractSockaddrPopulate(uri->path, resolved_addr);
+ grpc_core::UnixAbstractSockaddrPopulate(uri.path(), resolved_addr);
if (error != GRPC_ERROR_NONE) {
gpr_log(GPR_ERROR, "%s", grpc_error_string(error));
GRPC_ERROR_UNREF(error);
@@ -120,12 +122,12 @@ grpc_error* UnixAbstractSockaddrPopulate(absl::string_view path,
#else /* GRPC_HAVE_UNIX_SOCKET */
-bool grpc_parse_unix(const grpc_uri* uri,
+bool grpc_parse_unix(const grpc_core::URI& uri,
grpc_resolved_address* resolved_addr) {
abort();
}
-bool grpc_parse_unix_abstract(const grpc_uri* uri,
+bool grpc_parse_unix_abstract(const grpc_core::URI& uri,
grpc_resolved_address* resolved_addr) {
abort();
}
@@ -145,15 +147,16 @@ grpc_error* UnixAbstractSockaddrPopulate(absl::string_view path,
} // namespace grpc_core
#endif /* GRPC_HAVE_UNIX_SOCKET */
-bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr,
- bool log_errors) {
+bool grpc_parse_ipv4_hostport(absl::string_view hostport,
+ grpc_resolved_address* addr, bool log_errors) {
bool success = false;
// Split host and port.
std::string host;
std::string port;
if (!grpc_core::SplitHostPort(hostport, &host, &port)) {
if (log_errors) {
- gpr_log(GPR_ERROR, "Failed gpr_split_host_port(%s, ...)", hostport);
+ gpr_log(GPR_ERROR, "Failed gpr_split_host_port(%s, ...)",
+ std::string(hostport).c_str());
}
return false;
}
@@ -185,27 +188,27 @@ done:
return success;
}
-bool grpc_parse_ipv4(const grpc_uri* uri,
+bool grpc_parse_ipv4(const grpc_core::URI& uri,
grpc_resolved_address* resolved_addr) {
- if (strcmp("ipv4", uri->scheme) != 0) {
- gpr_log(GPR_ERROR, "Expected 'ipv4' scheme, got '%s'", uri->scheme);
+ if (uri.scheme() != "ipv4") {
+ gpr_log(GPR_ERROR, "Expected 'ipv4' scheme, got '%s'",
+ uri.scheme().c_str());
return false;
}
- const char* host_port = uri->path;
- if (*host_port == '/') ++host_port;
- return grpc_parse_ipv4_hostport(host_port, resolved_addr,
- true /* log_errors */);
+ return grpc_parse_ipv4_hostport(absl::StripPrefix(uri.path(), "/"),
+ resolved_addr, true /* log_errors */);
}
-bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
- bool log_errors) {
+bool grpc_parse_ipv6_hostport(absl::string_view hostport,
+ grpc_resolved_address* addr, bool log_errors) {
bool success = false;
// Split host and port.
std::string host;
std::string port;
if (!grpc_core::SplitHostPort(hostport, &host, &port)) {
if (log_errors) {
- gpr_log(GPR_ERROR, "Failed gpr_split_host_port(%s, ...)", hostport);
+ gpr_log(GPR_ERROR, "Failed gpr_split_host_port(%s, ...)",
+ std::string(hostport).c_str());
}
return false;
}
@@ -280,29 +283,32 @@ done:
return success;
}
-bool grpc_parse_ipv6(const grpc_uri* uri,
+bool grpc_parse_ipv6(const grpc_core::URI& uri,
grpc_resolved_address* resolved_addr) {
- if (strcmp("ipv6", uri->scheme) != 0) {
- gpr_log(GPR_ERROR, "Expected 'ipv6' scheme, got '%s'", uri->scheme);
+ if (uri.scheme() != "ipv6") {
+ gpr_log(GPR_ERROR, "Expected 'ipv6' scheme, got '%s'",
+ uri.scheme().c_str());
return false;
}
- const char* host_port = uri->path;
- if (*host_port == '/') ++host_port;
- return grpc_parse_ipv6_hostport(host_port, resolved_addr,
- true /* log_errors */);
+ return grpc_parse_ipv6_hostport(absl::StripPrefix(uri.path(), "/"),
+ resolved_addr, true /* log_errors */);
}
-bool grpc_parse_uri(const grpc_uri* uri, grpc_resolved_address* resolved_addr) {
- if (strcmp("unix", uri->scheme) == 0) {
+bool grpc_parse_uri(const grpc_core::URI& uri,
+ grpc_resolved_address* resolved_addr) {
+ if (uri.scheme() == "unix") {
return grpc_parse_unix(uri, resolved_addr);
- } else if (strcmp("unix-abstract", uri->scheme) == 0) {
+ }
+ if (uri.scheme() == "unix-abstract") {
return grpc_parse_unix_abstract(uri, resolved_addr);
- } else if (strcmp("ipv4", uri->scheme) == 0) {
+ }
+ if (uri.scheme() == "ipv4") {
return grpc_parse_ipv4(uri, resolved_addr);
- } else if (strcmp("ipv6", uri->scheme) == 0) {
+ }
+ if (uri.scheme() == "ipv6") {
return grpc_parse_ipv6(uri, resolved_addr);
}
- gpr_log(GPR_ERROR, "Can't parse scheme '%s'", uri->scheme);
+ gpr_log(GPR_ERROR, "Can't parse scheme '%s'", uri.scheme().c_str());
return false;
}
diff --git a/src/core/lib/iomgr/parse_address.h b/src/core/lib/iomgr/parse_address.h
index 29c8321a0cf..870afefa4eb 100644
--- a/src/core/lib/iomgr/parse_address.h
+++ b/src/core/lib/iomgr/parse_address.h
@@ -30,29 +30,33 @@
/** Populate \a resolved_addr from \a uri, whose path is expected to contain a
* unix socket path. Returns true upon success. */
-bool grpc_parse_unix(const grpc_uri* uri, grpc_resolved_address* resolved_addr);
+bool grpc_parse_unix(const grpc_core::URI& uri,
+ grpc_resolved_address* resolved_addr);
/** Populate \a resolved_addr from \a uri, whose path is expected to contain a
* unix socket path in the abstract namespace. Returns true upon success. */
-bool grpc_parse_unix_abstract(const grpc_uri* uri,
+bool grpc_parse_unix_abstract(const grpc_core::URI& uri,
grpc_resolved_address* resolved_addr);
/** Populate \a resolved_addr from \a uri, whose path is expected to contain an
* IPv4 host:port pair. Returns true upon success. */
-bool grpc_parse_ipv4(const grpc_uri* uri, grpc_resolved_address* resolved_addr);
+bool grpc_parse_ipv4(const grpc_core::URI& uri,
+ grpc_resolved_address* resolved_addr);
/** Populate \a resolved_addr from \a uri, whose path is expected to contain an
* IPv6 host:port pair. Returns true upon success. */
-bool grpc_parse_ipv6(const grpc_uri* uri, grpc_resolved_address* resolved_addr);
+bool grpc_parse_ipv6(const grpc_core::URI& uri,
+ grpc_resolved_address* resolved_addr);
/** Populate \a resolved_addr from \a uri. Returns true upon success. */
-bool grpc_parse_uri(const grpc_uri* uri, grpc_resolved_address* resolved_addr);
+bool grpc_parse_uri(const grpc_core::URI& uri,
+ grpc_resolved_address* resolved_addr);
/** Parse bare IPv4 or IPv6 "IP:port" strings. */
-bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr,
- bool log_errors);
-bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
- bool log_errors);
+bool grpc_parse_ipv4_hostport(absl::string_view hostport,
+ grpc_resolved_address* addr, bool log_errors);
+bool grpc_parse_ipv6_hostport(absl::string_view hostport,
+ grpc_resolved_address* addr, bool log_errors);
/* Converts named or numeric port to a uint16 suitable for use in a sockaddr. */
uint16_t grpc_strhtons(const char* port);
diff --git a/src/core/lib/security/authorization/evaluate_args.cc b/src/core/lib/security/authorization/evaluate_args.cc
index 68f6cb803d3..6eaf10670da 100644
--- a/src/core/lib/security/authorization/evaluate_args.cc
+++ b/src/core/lib/security/authorization/evaluate_args.cc
@@ -87,14 +87,12 @@ int EvaluateArgs::GetLocalPort() const {
if (endpoint_ == nullptr) {
return 0;
}
- grpc_uri* uri = grpc_uri_parse(
- std::string(grpc_endpoint_get_local_address(endpoint_)).c_str(), true);
+ absl::StatusOr uri =
+ URI::Parse(grpc_endpoint_get_local_address(endpoint_));
grpc_resolved_address resolved_addr;
- if (uri == nullptr || !grpc_parse_uri(uri, &resolved_addr)) {
- grpc_uri_destroy(uri);
+ if (!uri.ok() || !grpc_parse_uri(*uri, &resolved_addr)) {
return 0;
}
- grpc_uri_destroy(uri);
return grpc_sockaddr_get_port(&resolved_addr);
}
@@ -113,14 +111,11 @@ int EvaluateArgs::GetPeerPort() const {
if (endpoint_ == nullptr) {
return 0;
}
- grpc_uri* uri = grpc_uri_parse(
- std::string(grpc_endpoint_get_peer(endpoint_)).c_str(), true);
+ absl::StatusOr uri = URI::Parse(grpc_endpoint_get_peer(endpoint_));
grpc_resolved_address resolved_addr;
- if (uri == nullptr || !grpc_parse_uri(uri, &resolved_addr)) {
- grpc_uri_destroy(uri);
+ if (!uri.ok() || !grpc_parse_uri(*uri, &resolved_addr)) {
return 0;
}
- grpc_uri_destroy(uri);
return grpc_sockaddr_get_port(&resolved_addr);
}
diff --git a/src/core/lib/security/credentials/external/aws_external_account_credentials.cc b/src/core/lib/security/credentials/external/aws_external_account_credentials.cc
index 12428c8b2a6..01c7b005ce5 100644
--- a/src/core/lib/security/credentials/external/aws_external_account_credentials.cc
+++ b/src/core/lib/security/credentials/external/aws_external_account_credentials.cc
@@ -149,21 +149,20 @@ void AwsExternalAccountCredentials::RetrieveRegion() {
}
return;
}
- grpc_uri* uri = grpc_uri_parse(region_url_, false);
- if (uri == nullptr) {
- FinishRetrieveSubjectToken(
- "",
- GRPC_ERROR_CREATE_FROM_COPIED_STRING(
- absl::StrFormat("Invalid region url: %s.", region_url_).c_str()));
+ absl::StatusOr uri = URI::Parse(region_url_);
+ if (!uri.ok()) {
+ FinishRetrieveSubjectToken("", GRPC_ERROR_CREATE_FROM_COPIED_STRING(
+ absl::StrFormat("Invalid region url. %s",
+ uri.status().ToString())
+ .c_str()));
return;
}
grpc_httpcli_request request;
memset(&request, 0, sizeof(grpc_httpcli_request));
- request.host = const_cast(uri->authority);
- request.http.path = gpr_strdup(uri->path);
- request.handshaker = (strcmp(uri->scheme, "https") == 0)
- ? &grpc_httpcli_ssl
- : &grpc_httpcli_plaintext;
+ request.host = const_cast(uri->authority().c_str());
+ request.http.path = gpr_strdup(uri->path().c_str());
+ request.handshaker =
+ uri->scheme() == "https" ? &grpc_httpcli_ssl : &grpc_httpcli_plaintext;
grpc_resource_quota* resource_quota =
grpc_resource_quota_create("external_account_credentials");
grpc_http_response_destroy(&ctx_->response);
@@ -173,7 +172,6 @@ void AwsExternalAccountCredentials::RetrieveRegion() {
&request, ctx_->deadline, &ctx_->closure, &ctx_->response);
grpc_resource_quota_unref_internal(resource_quota);
grpc_http_request_destroy(&request.http);
- grpc_uri_destroy(uri);
}
void AwsExternalAccountCredentials::OnRetrieveRegion(void* arg,
@@ -201,20 +199,20 @@ void AwsExternalAccountCredentials::OnRetrieveRegionInternal(
}
void AwsExternalAccountCredentials::RetrieveRoleName() {
- grpc_uri* uri = grpc_uri_parse(url_, false);
- if (uri == nullptr) {
+ absl::StatusOr uri = URI::Parse(url_);
+ if (!uri.ok()) {
FinishRetrieveSubjectToken(
"", GRPC_ERROR_CREATE_FROM_COPIED_STRING(
- absl::StrFormat("Invalid url: %s.", url_).c_str()));
+ absl::StrFormat("Invalid url: %s.", uri.status().ToString())
+ .c_str()));
return;
}
grpc_httpcli_request request;
memset(&request, 0, sizeof(grpc_httpcli_request));
- request.host = const_cast(uri->authority);
- request.http.path = gpr_strdup(uri->path);
- request.handshaker = (strcmp(uri->scheme, "https") == 0)
- ? &grpc_httpcli_ssl
- : &grpc_httpcli_plaintext;
+ request.host = const_cast(uri->authority().c_str());
+ request.http.path = gpr_strdup(uri->path().c_str());
+ request.handshaker =
+ uri->scheme() == "https" ? &grpc_httpcli_ssl : &grpc_httpcli_plaintext;
grpc_resource_quota* resource_quota =
grpc_resource_quota_create("external_account_credentials");
grpc_http_response_destroy(&ctx_->response);
@@ -224,7 +222,6 @@ void AwsExternalAccountCredentials::RetrieveRoleName() {
&request, ctx_->deadline, &ctx_->closure, &ctx_->response);
grpc_resource_quota_unref_internal(resource_quota);
grpc_http_request_destroy(&request.http);
- grpc_uri_destroy(uri);
}
void AwsExternalAccountCredentials::OnRetrieveRoleName(void* arg,
@@ -264,22 +261,21 @@ void AwsExternalAccountCredentials::RetrieveSigningKeys() {
return;
}
std::string url_with_role_name = absl::StrCat(url_, "/", role_name_);
- grpc_uri* uri = grpc_uri_parse(url_with_role_name, false);
- if (uri == nullptr) {
+ absl::StatusOr uri = URI::Parse(url_with_role_name);
+ if (!uri.ok()) {
FinishRetrieveSubjectToken(
"", GRPC_ERROR_CREATE_FROM_COPIED_STRING(
absl::StrFormat("Invalid url with role name: %s.",
- url_with_role_name)
+ uri.status().ToString())
.c_str()));
return;
}
grpc_httpcli_request request;
memset(&request, 0, sizeof(grpc_httpcli_request));
- request.host = const_cast(uri->authority);
- request.http.path = gpr_strdup(uri->path);
- request.handshaker = (strcmp(uri->scheme, "https") == 0)
- ? &grpc_httpcli_ssl
- : &grpc_httpcli_plaintext;
+ request.host = const_cast(uri->authority().c_str());
+ request.http.path = gpr_strdup(uri->path().c_str());
+ request.handshaker =
+ uri->scheme() == "https" ? &grpc_httpcli_ssl : &grpc_httpcli_plaintext;
grpc_resource_quota* resource_quota =
grpc_resource_quota_create("external_account_credentials");
grpc_http_response_destroy(&ctx_->response);
@@ -289,7 +285,6 @@ void AwsExternalAccountCredentials::RetrieveSigningKeys() {
&request, ctx_->deadline, &ctx_->closure, &ctx_->response);
grpc_resource_quota_unref_internal(resource_quota);
grpc_http_request_destroy(&request.http);
- grpc_uri_destroy(uri);
}
void AwsExternalAccountCredentials::OnRetrieveSigningKeys(void* arg,
diff --git a/src/core/lib/security/credentials/external/aws_request_signer.cc b/src/core/lib/security/credentials/external/aws_request_signer.cc
index b51f595df36..af8531ee02a 100644
--- a/src/core/lib/security/credentials/external/aws_request_signer.cc
+++ b/src/core/lib/security/credentials/external/aws_request_signer.cc
@@ -95,15 +95,14 @@ AwsRequestSigner::AwsRequestSigner(
static_request_date_ =
absl::FormatTime(kXAmzDateFormat, request_date, absl::UTCTimeZone());
}
- url_ = grpc_uri_parse(url, false);
- if (url_ == nullptr) {
+ absl::StatusOr tmp_url = URI::Parse(url);
+ if (!tmp_url.ok()) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Invalid Aws request url.");
return;
}
+ url_ = tmp_url.value();
}
-AwsRequestSigner::~AwsRequestSigner() { grpc_uri_destroy(url_); }
-
std::map AwsRequestSigner::GetSignedRequestHeaders() {
std::string request_date_full;
if (!static_request_date_.empty()) {
@@ -124,15 +123,20 @@ std::map AwsRequestSigner::GetSignedRequestHeaders() {
canonical_request_vector.emplace_back(method_);
canonical_request_vector.emplace_back("\n");
// 2. CanonicalURI
-
- canonical_request_vector.emplace_back(*url_->path == '\0' ? "/" : url_->path);
+ canonical_request_vector.emplace_back(
+ url_.path().empty() ? "/" : absl::string_view(url_.path()));
canonical_request_vector.emplace_back("\n");
// 3. CanonicalQueryString
- canonical_request_vector.emplace_back(url_->query);
+ std::vector query_vector;
+ for (const URI::QueryParam& query_kv : url_.query_parameter_pairs()) {
+ query_vector.emplace_back(absl::StrCat(query_kv.key, "=", query_kv.value));
+ }
+ std::string query = absl::StrJoin(query_vector, "&");
+ canonical_request_vector.emplace_back(query);
canonical_request_vector.emplace_back("\n");
// 4. CanonicalHeaders
if (request_headers_.empty()) {
- request_headers_.insert({"host", url_->authority});
+ request_headers_.insert({"host", url_.authority()});
if (!token_.empty()) {
request_headers_.insert({"x-amz-security-token", token_});
}
@@ -177,7 +181,7 @@ std::map AwsRequestSigner::GetSignedRequestHeaders() {
string_to_sign_vector.emplace_back("\n");
// 3. CredentialScope
std::pair host_parts =
- absl::StrSplit(url_->authority, absl::MaxSplits('.', 1));
+ absl::StrSplit(url_.authority(), absl::MaxSplits('.', 1));
std::string service_name(host_parts.first);
std::string credential_scope = absl::StrFormat(
"%s/%s/%s/aws4_request", request_date_short, region_, service_name);
diff --git a/src/core/lib/security/credentials/external/aws_request_signer.h b/src/core/lib/security/credentials/external/aws_request_signer.h
index a4823e079ae..62e112cf0f4 100644
--- a/src/core/lib/security/credentials/external/aws_request_signer.h
+++ b/src/core/lib/security/credentials/external/aws_request_signer.h
@@ -46,7 +46,6 @@ class AwsRequestSigner {
std::string region, std::string request_payload,
std::map additional_headers,
grpc_error** error);
- ~AwsRequestSigner();
// This method triggers the signing process then returns the headers of the
// signed request as a map. In case there is an error, the input `error`
@@ -59,7 +58,7 @@ class AwsRequestSigner {
std::string secret_access_key_;
std::string token_;
std::string method_;
- grpc_uri* url_ = nullptr;
+ URI url_;
std::string region_;
std::string request_payload_;
std::map additional_headers_;
diff --git a/src/core/lib/security/credentials/external/external_account_credentials.cc b/src/core/lib/security/credentials/external/external_account_credentials.cc
index 599b718655f..eff0890a95b 100644
--- a/src/core/lib/security/credentials/external/external_account_credentials.cc
+++ b/src/core/lib/security/credentials/external/external_account_credentials.cc
@@ -89,16 +89,18 @@ void ExternalAccountCredentials::OnRetrieveSubjectTokenInternal(
void ExternalAccountCredentials::ExchangeToken(
absl::string_view subject_token) {
- grpc_uri* uri = grpc_uri_parse(options_.token_url, false);
- if (uri == nullptr) {
+ absl::StatusOr uri = URI::Parse(options_.token_url);
+ if (!uri.ok()) {
FinishTokenFetch(GRPC_ERROR_CREATE_FROM_COPIED_STRING(
- absl::StrFormat("Invalid token url: %s.", options_.token_url).c_str()));
+ absl::StrFormat("Invalid token url: %s. Error: %s", options_.token_url,
+ uri.status().ToString())
+ .c_str()));
return;
}
grpc_httpcli_request request;
memset(&request, 0, sizeof(grpc_httpcli_request));
- request.host = const_cast(uri->authority);
- request.http.path = gpr_strdup(uri->path);
+ request.host = const_cast(uri->authority().c_str());
+ request.http.path = gpr_strdup(uri->path().c_str());
grpc_http_header* headers = nullptr;
if (!options_.client_id.empty() && !options_.client_secret.empty()) {
request.http.hdr_count = 2;
@@ -122,9 +124,8 @@ void ExternalAccountCredentials::ExchangeToken(
headers[0].value = gpr_strdup("application/x-www-form-urlencoded");
}
request.http.hdrs = headers;
- request.handshaker = (strcmp(uri->scheme, "https") == 0)
- ? &grpc_httpcli_ssl
- : &grpc_httpcli_plaintext;
+ request.handshaker =
+ uri->scheme() == "https" ? &grpc_httpcli_ssl : &grpc_httpcli_plaintext;
std::vector body_parts;
body_parts.push_back(absl::StrFormat("%s=%s", "audience", options_.audience));
body_parts.push_back(absl::StrFormat(
@@ -152,7 +153,6 @@ void ExternalAccountCredentials::ExchangeToken(
&ctx_->closure, &ctx_->response);
grpc_resource_quota_unref_internal(resource_quota);
grpc_http_request_destroy(&request.http);
- grpc_uri_destroy(uri);
}
void ExternalAccountCredentials::OnExchangeToken(void* arg, grpc_error* error) {
@@ -195,19 +195,20 @@ void ExternalAccountCredentials::ImpersenateServiceAccount() {
return;
}
std::string access_token = it->second.string_value();
- grpc_uri* uri =
- grpc_uri_parse(options_.service_account_impersonation_url, false);
- if (uri == nullptr) {
+ absl::StatusOr uri =
+ URI::Parse(options_.service_account_impersonation_url);
+ if (!uri.ok()) {
FinishTokenFetch(GRPC_ERROR_CREATE_FROM_COPIED_STRING(
- absl::StrFormat("Invalid service account impersonation url: %s.",
- options_.service_account_impersonation_url)
+ absl::StrFormat(
+ "Invalid service account impersonation url: %s. Error: %s",
+ options_.service_account_impersonation_url, uri.status().ToString())
.c_str()));
return;
}
grpc_httpcli_request request;
memset(&request, 0, sizeof(grpc_httpcli_request));
- request.host = const_cast(uri->authority);
- request.http.path = gpr_strdup(uri->path);
+ request.host = const_cast(uri->authority().c_str());
+ request.http.path = gpr_strdup(uri->path().c_str());
request.http.hdr_count = 2;
grpc_http_header* headers = static_cast(
gpr_malloc(sizeof(grpc_http_header) * request.http.hdr_count));
@@ -217,9 +218,8 @@ void ExternalAccountCredentials::ImpersenateServiceAccount() {
headers[1].key = gpr_strdup("Authorization");
headers[1].value = gpr_strdup(str.c_str());
request.http.hdrs = headers;
- request.handshaker = (strcmp(uri->scheme, "https") == 0)
- ? &grpc_httpcli_ssl
- : &grpc_httpcli_plaintext;
+ request.handshaker =
+ uri->scheme() == "https" ? &grpc_httpcli_ssl : &grpc_httpcli_plaintext;
std::string scope = absl::StrJoin(scopes_, " ");
std::string body = absl::StrFormat("%s=%s", "scope", scope);
grpc_resource_quota* resource_quota =
@@ -232,7 +232,6 @@ void ExternalAccountCredentials::ImpersenateServiceAccount() {
&ctx_->closure, &ctx_->response);
grpc_resource_quota_unref_internal(resource_quota);
grpc_http_request_destroy(&request.http);
- grpc_uri_destroy(uri);
}
void ExternalAccountCredentials::OnImpersenateServiceAccount(
diff --git a/src/core/lib/security/credentials/external/url_external_account_credentials.cc b/src/core/lib/security/credentials/external/url_external_account_credentials.cc
index 43029e0deb4..af02a17ed9d 100644
--- a/src/core/lib/security/credentials/external/url_external_account_credentials.cc
+++ b/src/core/lib/security/credentials/external/url_external_account_credentials.cc
@@ -48,13 +48,15 @@ UrlExternalAccountCredentials::UrlExternalAccountCredentials(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("url field must be a string.");
return;
}
- grpc_uri* url = grpc_uri_parse(it->second.string_value(), false);
- if (url == nullptr) {
- *error =
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Invalid credential source url.");
+ absl::StatusOr tmp_url = URI::Parse(it->second.string_value());
+ if (!tmp_url.ok()) {
+ *error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(
+ absl::StrFormat("Invalid credential source url. Error: %s",
+ tmp_url.status().ToString())
+ .c_str());
return;
}
- url_ = url;
+ url_ = *tmp_url;
it = options.credential_source.object_value().find("headers");
if (it != options.credential_source.object_value().end()) {
if (it->second.type() != Json::Type::OBJECT) {
@@ -104,10 +106,6 @@ UrlExternalAccountCredentials::UrlExternalAccountCredentials(
}
}
-UrlExternalAccountCredentials::~UrlExternalAccountCredentials() {
- grpc_uri_destroy(url_);
-}
-
void UrlExternalAccountCredentials::RetrieveSubjectToken(
HTTPRequestContext* ctx, const ExternalAccountCredentialsOptions& options,
std::function cb) {
@@ -122,8 +120,8 @@ void UrlExternalAccountCredentials::RetrieveSubjectToken(
cb_ = cb;
grpc_httpcli_request request;
memset(&request, 0, sizeof(grpc_httpcli_request));
- request.host = const_cast(url_->authority);
- request.http.path = gpr_strdup(url_->path);
+ request.host = const_cast(url_.authority().c_str());
+ request.http.path = gpr_strdup(url_.path().c_str());
grpc_http_header* headers = nullptr;
request.http.hdr_count = headers_.size();
headers = static_cast(
@@ -135,9 +133,8 @@ void UrlExternalAccountCredentials::RetrieveSubjectToken(
++i;
}
request.http.hdrs = headers;
- request.handshaker = (strcmp(url_->scheme, "https") == 0)
- ? &grpc_httpcli_ssl
- : &grpc_httpcli_plaintext;
+ request.handshaker =
+ url_.scheme() == "https" ? &grpc_httpcli_ssl : &grpc_httpcli_plaintext;
grpc_resource_quota* resource_quota =
grpc_resource_quota_create("external_account_credentials");
grpc_http_response_destroy(&ctx_->response);
diff --git a/src/core/lib/security/credentials/external/url_external_account_credentials.h b/src/core/lib/security/credentials/external/url_external_account_credentials.h
index 8383ab523a7..16f6f36c035 100644
--- a/src/core/lib/security/credentials/external/url_external_account_credentials.h
+++ b/src/core/lib/security/credentials/external/url_external_account_credentials.h
@@ -32,7 +32,6 @@ class UrlExternalAccountCredentials final : public ExternalAccountCredentials {
UrlExternalAccountCredentials(ExternalAccountCredentialsOptions options,
std::vector scopes,
grpc_error** error);
- ~UrlExternalAccountCredentials() override;
private:
void RetrieveSubjectToken(
@@ -45,7 +44,7 @@ class UrlExternalAccountCredentials final : public ExternalAccountCredentials {
void FinishRetrieveSubjectToken(std::string subject_token, grpc_error* error);
// Fields of credential source
- grpc_uri* url_ = nullptr;
+ URI url_;
std::map headers_;
std::string format_type_;
std::string format_subject_token_field_name_;
diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
index 1ed839a57c9..bbd2cb5bae3 100644
--- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
+++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
@@ -538,9 +538,9 @@ grpc_error* LoadTokenFile(const char* path, gpr_slice* token) {
class StsTokenFetcherCredentials
: public grpc_oauth2_token_fetcher_credentials {
public:
- StsTokenFetcherCredentials(grpc_uri* sts_url, // Ownership transferred.
+ StsTokenFetcherCredentials(URI sts_url,
const grpc_sts_credentials_options* options)
- : sts_url_(sts_url),
+ : sts_url_(std::move(sts_url)),
resource_(gpr_strdup(options->resource)),
audience_(gpr_strdup(options->audience)),
scope_(gpr_strdup(options->scope)),
@@ -550,12 +550,10 @@ class StsTokenFetcherCredentials
actor_token_path_(gpr_strdup(options->actor_token_path)),
actor_token_type_(gpr_strdup(options->actor_token_type)) {}
- ~StsTokenFetcherCredentials() override { grpc_uri_destroy(sts_url_); }
-
std::string debug_string() override {
return absl::StrFormat(
- "StsTokenFetcherCredentials{Path:%s,Authority:%s,%s}", sts_url_->path,
- sts_url_->authority,
+ "StsTokenFetcherCredentials{Path:%s,Authority:%s,%s}", sts_url_.path(),
+ sts_url_.authority(),
grpc_oauth2_token_fetcher_credentials::debug_string());
}
@@ -578,11 +576,11 @@ class StsTokenFetcherCredentials
const_cast("application/x-www-form-urlencoded")};
grpc_httpcli_request request;
memset(&request, 0, sizeof(grpc_httpcli_request));
- request.host = sts_url_->authority;
- request.http.path = sts_url_->path;
+ request.host = const_cast(sts_url_.authority().c_str());
+ request.http.path = const_cast(sts_url_.path().c_str());
request.http.hdr_count = 1;
request.http.hdrs = &header;
- request.handshaker = (strcmp(sts_url_->scheme, "https") == 0)
+ request.handshaker = (sts_url_.scheme() == "https")
? &grpc_httpcli_ssl
: &grpc_httpcli_plaintext;
/* TODO(ctiller): Carry the resource_quota in ctx and share it with the host
@@ -642,7 +640,7 @@ class StsTokenFetcherCredentials
return cleanup();
}
- grpc_uri* sts_url_;
+ URI sts_url_;
grpc_closure http_post_cb_closure_;
grpc_core::UniquePtr resource_;
grpc_core::UniquePtr audience_;
@@ -656,26 +654,21 @@ class StsTokenFetcherCredentials
} // namespace
-grpc_error* ValidateStsCredentialsOptions(
- const grpc_sts_credentials_options* options, grpc_uri** sts_url_out) {
- struct GrpcUriDeleter {
- void operator()(grpc_uri* uri) { grpc_uri_destroy(uri); }
- };
- *sts_url_out = nullptr;
+absl::StatusOr ValidateStsCredentialsOptions(
+ const grpc_sts_credentials_options* options) {
absl::InlinedVector error_list;
- std::unique_ptr sts_url(
- options->token_exchange_service_uri != nullptr
- ? grpc_uri_parse(options->token_exchange_service_uri, false)
- : nullptr);
- if (sts_url == nullptr) {
+ absl::StatusOr sts_url =
+ URI::Parse(options->token_exchange_service_uri == nullptr
+ ? ""
+ : options->token_exchange_service_uri);
+ if (!sts_url.ok()) {
+ error_list.push_back(GRPC_ERROR_CREATE_FROM_COPIED_STRING(
+ absl::StrFormat("Invalid or missing STS endpoint URL. Error: %s",
+ sts_url.status().ToString())
+ .c_str()));
+ } else if (sts_url->scheme() != "https" && sts_url->scheme() != "http") {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
- "Invalid or missing STS endpoint URL"));
- } else {
- if (strcmp(sts_url->scheme, "https") != 0 &&
- strcmp(sts_url->scheme, "http") != 0) {
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
- "Invalid URI scheme, must be https to http."));
- }
+ "Invalid URI scheme, must be https to http."));
}
if (options->subject_token_path == nullptr ||
strlen(options->subject_token_path) == 0) {
@@ -688,12 +681,13 @@ grpc_error* ValidateStsCredentialsOptions(
"subject_token_type needs to be specified"));
}
if (error_list.empty()) {
- *sts_url_out = sts_url.release();
- return GRPC_ERROR_NONE;
- } else {
- return GRPC_ERROR_CREATE_FROM_VECTOR("Invalid STS Credentials Options",
- &error_list);
+ return sts_url;
}
+ auto grpc_error_vec = GRPC_ERROR_CREATE_FROM_VECTOR(
+ "Invalid STS Credentials Options", &error_list);
+ auto retval = absl::InvalidArgumentError(grpc_error_string(grpc_error_vec));
+ GRPC_ERROR_UNREF(grpc_error_vec);
+ return retval;
}
} // namespace grpc_core
@@ -701,17 +695,15 @@ grpc_error* ValidateStsCredentialsOptions(
grpc_call_credentials* grpc_sts_credentials_create(
const grpc_sts_credentials_options* options, void* reserved) {
GPR_ASSERT(reserved == nullptr);
- grpc_uri* sts_url;
- grpc_error* error =
- grpc_core::ValidateStsCredentialsOptions(options, &sts_url);
- if (error != GRPC_ERROR_NONE) {
+ absl::StatusOr sts_url =
+ grpc_core::ValidateStsCredentialsOptions(options);
+ if (!sts_url.ok()) {
gpr_log(GPR_ERROR, "STS Credentials creation failed. Error: %s.",
- grpc_error_string(error));
- GRPC_ERROR_UNREF(error);
+ sts_url.status().ToString().c_str());
return nullptr;
}
return grpc_core::MakeRefCounted(
- sts_url, options)
+ std::move(*sts_url), options)
.release();
}
diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.h b/src/core/lib/security/credentials/oauth2/oauth2_credentials.h
index 6111d9adcaa..264291965eb 100644
--- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.h
+++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.h
@@ -165,8 +165,8 @@ namespace grpc_core {
// Exposed for testing only. This function validates the options, ensuring that
// the required fields are set, and outputs the parsed URL of the STS token
// exchanged service.
-grpc_error* ValidateStsCredentialsOptions(
- const grpc_sts_credentials_options* options, grpc_uri** sts_url);
+absl::StatusOr ValidateStsCredentialsOptions(
+ const grpc_sts_credentials_options* options);
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_OAUTH2_OAUTH2_CREDENTIALS_H */
diff --git a/src/core/lib/transport/authority_override.cc b/src/core/lib/transport/authority_override.cc
index 8c13320b73b..668507250fe 100644
--- a/src/core/lib/transport/authority_override.cc
+++ b/src/core/lib/transport/authority_override.cc
@@ -16,6 +16,8 @@
#include
+#include "absl/strings/string_view.h"
+
#include "src/core/lib/channel/channel_args.h"
// Channel arg key for the authority override.
@@ -23,16 +25,16 @@
namespace grpc_core {
-/// Returns a channel argument containing \a authority.
grpc_arg CreateAuthorityOverrideChannelArg(const char* authority) {
return grpc_channel_arg_string_create(
const_cast(GRPC_ARG_AUTHORITY_OVERRIDE),
const_cast(authority));
}
-/// Returns the authority override from \a args or nullptr.
-const char* FindAuthorityOverrideInArgs(const grpc_channel_args* args) {
- return grpc_channel_args_find_string(args, GRPC_ARG_AUTHORITY_OVERRIDE);
+absl::string_view FindAuthorityOverrideInArgs(const grpc_channel_args* args) {
+ const char* found =
+ grpc_channel_args_find_string(args, GRPC_ARG_AUTHORITY_OVERRIDE);
+ return found == nullptr ? "" : found;
}
} // namespace grpc_core
diff --git a/src/core/lib/transport/authority_override.h b/src/core/lib/transport/authority_override.h
index 0cbf27e316b..7af6526e0a3 100644
--- a/src/core/lib/transport/authority_override.h
+++ b/src/core/lib/transport/authority_override.h
@@ -19,6 +19,8 @@
#include
+#include "absl/strings/string_view.h"
+
#include
namespace grpc_core {
@@ -26,8 +28,9 @@ namespace grpc_core {
/// Returns a channel argument containing \a authority.
grpc_arg CreateAuthorityOverrideChannelArg(const char* authority);
-/// Returns the authority override from \a args or nullptr.
-const char* FindAuthorityOverrideInArgs(const grpc_channel_args* args);
+/// Returns the authority override from \a args or the empty string. The return
+/// value is a string_view into the `args` data structure.
+absl::string_view FindAuthorityOverrideInArgs(const grpc_channel_args* args);
} // namespace grpc_core
diff --git a/src/core/lib/uri/uri_parser.cc b/src/core/lib/uri/uri_parser.cc
index 28a76d9c094..e47daeb5a4b 100644
--- a/src/core/lib/uri/uri_parser.cc
+++ b/src/core/lib/uri/uri_parser.cc
@@ -22,288 +22,168 @@
#include
+#include