|
|
@ -40,22 +40,20 @@ |
|
|
|
#include <grpc/support/string_util.h> |
|
|
|
#include <grpc/support/string_util.h> |
|
|
|
|
|
|
|
|
|
|
|
#define MAX_RESOLVERS 10 |
|
|
|
#define MAX_RESOLVERS 10 |
|
|
|
|
|
|
|
#define DEFAULT_RESOLVER_PREFIX_MAX_LENGTH 32 |
|
|
|
|
|
|
|
|
|
|
|
static grpc_resolver_factory *g_all_of_the_resolvers[MAX_RESOLVERS]; |
|
|
|
static grpc_resolver_factory *g_all_of_the_resolvers[MAX_RESOLVERS]; |
|
|
|
static int g_number_of_resolvers = 0; |
|
|
|
static int g_number_of_resolvers = 0; |
|
|
|
|
|
|
|
|
|
|
|
static char *g_default_resolver_prefix; |
|
|
|
static char g_default_resolver_prefix[DEFAULT_RESOLVER_PREFIX_MAX_LENGTH] = |
|
|
|
|
|
|
|
"dns:///"; |
|
|
|
|
|
|
|
|
|
|
|
void grpc_resolver_registry_init(const char *default_resolver_prefix) { |
|
|
|
void grpc_resolver_registry_init() {} |
|
|
|
g_default_resolver_prefix = gpr_strdup(default_resolver_prefix); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void grpc_resolver_registry_shutdown(void) { |
|
|
|
void grpc_resolver_registry_shutdown(void) { |
|
|
|
int i; |
|
|
|
for (int i = 0; i < g_number_of_resolvers; i++) { |
|
|
|
for (i = 0; i < g_number_of_resolvers; i++) { |
|
|
|
|
|
|
|
grpc_resolver_factory_unref(g_all_of_the_resolvers[i]); |
|
|
|
grpc_resolver_factory_unref(g_all_of_the_resolvers[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
gpr_free(g_default_resolver_prefix); |
|
|
|
|
|
|
|
// FIXME(ctiller): this should live in grpc_resolver_registry_init,
|
|
|
|
// FIXME(ctiller): this should live in grpc_resolver_registry_init,
|
|
|
|
// however that would have the client_config plugin call this AFTER we start
|
|
|
|
// however that would have the client_config plugin call this AFTER we start
|
|
|
|
// registering resolvers from third party plugins, and so they'd never show
|
|
|
|
// registering resolvers from third party plugins, and so they'd never show
|
|
|
@ -65,6 +63,17 @@ void grpc_resolver_registry_shutdown(void) { |
|
|
|
g_number_of_resolvers = 0; |
|
|
|
g_number_of_resolvers = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void grpc_resolver_registry_set_default_prefix( |
|
|
|
|
|
|
|
const char *default_resolver_prefix) { |
|
|
|
|
|
|
|
const size_t len = strlen(default_resolver_prefix); |
|
|
|
|
|
|
|
GPR_ASSERT(len < DEFAULT_RESOLVER_PREFIX_MAX_LENGTH && |
|
|
|
|
|
|
|
"default resolver prefix too long"); |
|
|
|
|
|
|
|
GPR_ASSERT(len > 0 && "default resolver prefix can't be empty"); |
|
|
|
|
|
|
|
// By the previous assert, default_resolver_prefix is safe to be copied with a
|
|
|
|
|
|
|
|
// plain strcpy.
|
|
|
|
|
|
|
|
strcpy(g_default_resolver_prefix, default_resolver_prefix); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void grpc_register_resolver_type(grpc_resolver_factory *factory) { |
|
|
|
void grpc_register_resolver_type(grpc_resolver_factory *factory) { |
|
|
|
int i; |
|
|
|
int i; |
|
|
|
for (i = 0; i < g_number_of_resolvers; i++) { |
|
|
|
for (i = 0; i < g_number_of_resolvers; i++) { |
|
|
@ -108,7 +117,6 @@ static grpc_resolver_factory *resolve_factory(const char *target, |
|
|
|
*uri = grpc_uri_parse(target, 1); |
|
|
|
*uri = grpc_uri_parse(target, 1); |
|
|
|
factory = lookup_factory_by_uri(*uri); |
|
|
|
factory = lookup_factory_by_uri(*uri); |
|
|
|
if (factory == NULL) { |
|
|
|
if (factory == NULL) { |
|
|
|
if (g_default_resolver_prefix != NULL) { |
|
|
|
|
|
|
|
grpc_uri_destroy(*uri); |
|
|
|
grpc_uri_destroy(*uri); |
|
|
|
gpr_asprintf(&tmp, "%s%s", g_default_resolver_prefix, target); |
|
|
|
gpr_asprintf(&tmp, "%s%s", g_default_resolver_prefix, target); |
|
|
|
*uri = grpc_uri_parse(tmp, 1); |
|
|
|
*uri = grpc_uri_parse(tmp, 1); |
|
|
@ -116,14 +124,9 @@ static grpc_resolver_factory *resolve_factory(const char *target, |
|
|
|
if (factory == NULL) { |
|
|
|
if (factory == NULL) { |
|
|
|
grpc_uri_destroy(grpc_uri_parse(target, 0)); |
|
|
|
grpc_uri_destroy(grpc_uri_parse(target, 0)); |
|
|
|
grpc_uri_destroy(grpc_uri_parse(tmp, 0)); |
|
|
|
grpc_uri_destroy(grpc_uri_parse(tmp, 0)); |
|
|
|
gpr_log(GPR_ERROR, "don't know how to resolve '%s' or '%s'", target, |
|
|
|
gpr_log(GPR_ERROR, "don't know how to resolve '%s' or '%s'", target, tmp); |
|
|
|
tmp); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
gpr_free(tmp); |
|
|
|
gpr_free(tmp); |
|
|
|
} else { |
|
|
|
|
|
|
|
grpc_uri_destroy(grpc_uri_parse(target, 0)); |
|
|
|
|
|
|
|
gpr_log(GPR_ERROR, "don't know how to resolve '%s'", target); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return factory; |
|
|
|
return factory; |
|
|
|
} |
|
|
|
} |
|
|
|