aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/security
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib/security')
-rw-r--r--src/core/lib/security/context/security_context.cc30
-rw-r--r--src/core/lib/security/credentials/composite/composite_credentials.cc31
-rw-r--r--src/core/lib/security/credentials/credentials.cc17
-rw-r--r--src/core/lib/security/credentials/credentials_metadata.cc4
-rw-r--r--src/core/lib/security/credentials/fake/fake_credentials.cc19
-rw-r--r--src/core/lib/security/credentials/google_default/google_default_credentials.cc11
-rw-r--r--src/core/lib/security/credentials/iam/iam_credentials.cc8
-rw-r--r--src/core/lib/security/credentials/jwt/json_token.cc7
-rw-r--r--src/core/lib/security/credentials/jwt/jwt_credentials.cc14
-rw-r--r--src/core/lib/security/credentials/jwt/jwt_verifier.cc39
-rw-r--r--src/core/lib/security/credentials/oauth2/oauth2_credentials.cc41
-rw-r--r--src/core/lib/security/credentials/plugin/plugin_credentials.cc18
-rw-r--r--src/core/lib/security/credentials/ssl/ssl_credentials.cc43
-rw-r--r--src/core/lib/security/transport/client_auth_filter.cc69
-rw-r--r--src/core/lib/security/transport/lb_targets_info.cc12
-rw-r--r--src/core/lib/security/transport/secure_endpoint.cc42
-rw-r--r--src/core/lib/security/transport/security_connector.cc87
-rw-r--r--src/core/lib/security/transport/security_handshaker.cc37
-rw-r--r--src/core/lib/security/transport/server_auth_filter.cc42
19 files changed, 303 insertions, 268 deletions
diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc
index 63ec42cf86..c7e212bb21 100644
--- a/src/core/lib/security/context/security_context.cc
+++ b/src/core/lib/security/context/security_context.cc
@@ -44,8 +44,8 @@ grpc_call_error grpc_call_set_credentials(grpc_call* call,
gpr_log(GPR_ERROR, "Method is client-side only.");
return GRPC_CALL_ERROR_NOT_ON_SERVER;
}
- ctx = (grpc_client_security_context*)grpc_call_context_get(
- call, GRPC_CONTEXT_SECURITY);
+ ctx = static_cast<grpc_client_security_context*>(
+ grpc_call_context_get(call, GRPC_CONTEXT_SECURITY));
if (ctx == nullptr) {
ctx = grpc_client_security_context_create();
ctx->creds = grpc_call_credentials_ref(creds);
@@ -80,13 +80,14 @@ void grpc_auth_context_release(grpc_auth_context* context) {
/* --- grpc_client_security_context --- */
grpc_client_security_context* grpc_client_security_context_create(void) {
- return (grpc_client_security_context*)gpr_zalloc(
- sizeof(grpc_client_security_context));
+ return static_cast<grpc_client_security_context*>(
+ gpr_zalloc(sizeof(grpc_client_security_context)));
}
void grpc_client_security_context_destroy(void* ctx) {
grpc_core::ExecCtx exec_ctx;
- grpc_client_security_context* c = (grpc_client_security_context*)ctx;
+ grpc_client_security_context* c =
+ static_cast<grpc_client_security_context*>(ctx);
grpc_call_credentials_unref(c->creds);
GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "client_security_context");
if (c->extension.instance != nullptr && c->extension.destroy != nullptr) {
@@ -98,12 +99,13 @@ void grpc_client_security_context_destroy(void* ctx) {
/* --- grpc_server_security_context --- */
grpc_server_security_context* grpc_server_security_context_create(void) {
- return (grpc_server_security_context*)gpr_zalloc(
- sizeof(grpc_server_security_context));
+ return static_cast<grpc_server_security_context*>(
+ gpr_zalloc(sizeof(grpc_server_security_context)));
}
void grpc_server_security_context_destroy(void* ctx) {
- grpc_server_security_context* c = (grpc_server_security_context*)ctx;
+ grpc_server_security_context* c =
+ static_cast<grpc_server_security_context*>(ctx);
GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "server_security_context");
if (c->extension.instance != nullptr && c->extension.destroy != nullptr) {
c->extension.destroy(c->extension.instance);
@@ -117,7 +119,7 @@ static grpc_auth_property_iterator empty_iterator = {nullptr, 0, nullptr};
grpc_auth_context* grpc_auth_context_create(grpc_auth_context* chained) {
grpc_auth_context* ctx =
- (grpc_auth_context*)gpr_zalloc(sizeof(grpc_auth_context));
+ static_cast<grpc_auth_context*>(gpr_zalloc(sizeof(grpc_auth_context)));
gpr_ref_init(&ctx->refcount, 1);
if (chained != nullptr) {
ctx->chained = GRPC_AUTH_CONTEXT_REF(chained, "chained");
@@ -258,9 +260,9 @@ static void ensure_auth_context_capacity(grpc_auth_context* ctx) {
if (ctx->properties.count == ctx->properties.capacity) {
ctx->properties.capacity =
GPR_MAX(ctx->properties.capacity + 8, ctx->properties.capacity * 2);
- ctx->properties.array = (grpc_auth_property*)gpr_realloc(
- ctx->properties.array,
- ctx->properties.capacity * sizeof(grpc_auth_property));
+ ctx->properties.array = static_cast<grpc_auth_property*>(
+ gpr_realloc(ctx->properties.array,
+ ctx->properties.capacity * sizeof(grpc_auth_property)));
}
}
@@ -276,7 +278,7 @@ void grpc_auth_context_add_property(grpc_auth_context* ctx, const char* name,
ensure_auth_context_capacity(ctx);
prop = &ctx->properties.array[ctx->properties.count++];
prop->name = gpr_strdup(name);
- prop->value = (char*)gpr_malloc(value_length + 1);
+ prop->value = static_cast<char*>(gpr_malloc(value_length + 1));
memcpy(prop->value, value, value_length);
prop->value[value_length] = '\0';
prop->value_length = value_length;
@@ -329,7 +331,7 @@ grpc_auth_context* grpc_auth_context_from_arg(const grpc_arg* arg) {
GRPC_AUTH_CONTEXT_ARG);
return nullptr;
}
- return (grpc_auth_context*)arg->value.pointer.p;
+ return static_cast<grpc_auth_context*>(arg->value.pointer.p);
}
grpc_auth_context* grpc_find_auth_context_in_args(
diff --git a/src/core/lib/security/credentials/composite/composite_credentials.cc b/src/core/lib/security/credentials/composite/composite_credentials.cc
index e4c1604795..ea2c4e208f 100644
--- a/src/core/lib/security/credentials/composite/composite_credentials.cc
+++ b/src/core/lib/security/credentials/composite/composite_credentials.cc
@@ -40,7 +40,8 @@ typedef struct {
} grpc_composite_call_credentials_metadata_context;
static void composite_call_destruct(grpc_call_credentials* creds) {
- grpc_composite_call_credentials* c = (grpc_composite_call_credentials*)creds;
+ grpc_composite_call_credentials* c =
+ reinterpret_cast<grpc_composite_call_credentials*>(creds);
for (size_t i = 0; i < c->inner.num_creds; i++) {
grpc_call_credentials_unref(c->inner.creds_array[i]);
}
@@ -49,7 +50,7 @@ static void composite_call_destruct(grpc_call_credentials* creds) {
static void composite_call_metadata_cb(void* arg, grpc_error* error) {
grpc_composite_call_credentials_metadata_context* ctx =
- (grpc_composite_call_credentials_metadata_context*)arg;
+ static_cast<grpc_composite_call_credentials_metadata_context*>(arg);
if (error == GRPC_ERROR_NONE) {
/* See if we need to get some more metadata. */
if (ctx->creds_index < ctx->composite_creds->inner.num_creds) {
@@ -75,10 +76,11 @@ static bool composite_call_get_request_metadata(
grpc_auth_metadata_context auth_md_context,
grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata,
grpc_error** error) {
- grpc_composite_call_credentials* c = (grpc_composite_call_credentials*)creds;
+ grpc_composite_call_credentials* c =
+ reinterpret_cast<grpc_composite_call_credentials*>(creds);
grpc_composite_call_credentials_metadata_context* ctx;
- ctx = (grpc_composite_call_credentials_metadata_context*)gpr_zalloc(
- sizeof(grpc_composite_call_credentials_metadata_context));
+ ctx = static_cast<grpc_composite_call_credentials_metadata_context*>(
+ gpr_zalloc(sizeof(grpc_composite_call_credentials_metadata_context)));
ctx->composite_creds = c;
ctx->pollent = pollent;
ctx->auth_md_context = auth_md_context;
@@ -106,7 +108,8 @@ static bool composite_call_get_request_metadata(
static void composite_call_cancel_get_request_metadata(
grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array,
grpc_error* error) {
- grpc_composite_call_credentials* c = (grpc_composite_call_credentials*)creds;
+ grpc_composite_call_credentials* c =
+ reinterpret_cast<grpc_composite_call_credentials*>(creds);
for (size_t i = 0; i < c->inner.num_creds; ++i) {
grpc_call_credentials_cancel_get_request_metadata(
c->inner.creds_array[i], md_array, GRPC_ERROR_REF(error));
@@ -145,8 +148,8 @@ grpc_call_credentials* grpc_composite_call_credentials_create(
GPR_ASSERT(reserved == nullptr);
GPR_ASSERT(creds1 != nullptr);
GPR_ASSERT(creds2 != nullptr);
- c = (grpc_composite_call_credentials*)gpr_zalloc(
- sizeof(grpc_composite_call_credentials));
+ c = static_cast<grpc_composite_call_credentials*>(
+ gpr_zalloc(sizeof(grpc_composite_call_credentials)));
c->base.type = GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE;
c->base.vtable = &composite_call_credentials_vtable;
gpr_ref_init(&c->base.refcount, 1);
@@ -155,7 +158,7 @@ grpc_call_credentials* grpc_composite_call_credentials_create(
c->inner.num_creds = creds1_array.num_creds + creds2_array.num_creds;
creds_array_byte_size = c->inner.num_creds * sizeof(grpc_call_credentials*);
c->inner.creds_array =
- (grpc_call_credentials**)gpr_zalloc(creds_array_byte_size);
+ static_cast<grpc_call_credentials**>(gpr_zalloc(creds_array_byte_size));
for (i = 0; i < creds1_array.num_creds; i++) {
grpc_call_credentials* cur_creds = creds1_array.creds_array[i];
c->inner.creds_array[i] = grpc_call_credentials_ref(cur_creds);
@@ -171,7 +174,7 @@ grpc_call_credentials* grpc_composite_call_credentials_create(
const grpc_call_credentials_array*
grpc_composite_call_credentials_get_credentials(grpc_call_credentials* creds) {
const grpc_composite_call_credentials* c =
- (const grpc_composite_call_credentials*)creds;
+ reinterpret_cast<const grpc_composite_call_credentials*>(creds);
GPR_ASSERT(strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0);
return &c->inner;
}
@@ -200,7 +203,7 @@ grpc_call_credentials* grpc_credentials_contains_type(
static void composite_channel_destruct(grpc_channel_credentials* creds) {
grpc_composite_channel_credentials* c =
- (grpc_composite_channel_credentials*)creds;
+ reinterpret_cast<grpc_composite_channel_credentials*>(creds);
grpc_channel_credentials_unref(c->inner_creds);
grpc_call_credentials_unref(c->call_creds);
}
@@ -210,7 +213,7 @@ static grpc_security_status composite_channel_create_security_connector(
const char* target, const grpc_channel_args* args,
grpc_channel_security_connector** sc, grpc_channel_args** new_args) {
grpc_composite_channel_credentials* c =
- (grpc_composite_channel_credentials*)creds;
+ reinterpret_cast<grpc_composite_channel_credentials*>(creds);
grpc_security_status status = GRPC_SECURITY_ERROR;
GPR_ASSERT(c->inner_creds != nullptr && c->call_creds != nullptr &&
@@ -236,7 +239,7 @@ static grpc_channel_credentials*
composite_channel_duplicate_without_call_credentials(
grpc_channel_credentials* creds) {
grpc_composite_channel_credentials* c =
- (grpc_composite_channel_credentials*)creds;
+ reinterpret_cast<grpc_composite_channel_credentials*>(creds);
return grpc_channel_credentials_ref(c->inner_creds);
}
@@ -248,7 +251,7 @@ grpc_channel_credentials* grpc_composite_channel_credentials_create(
grpc_channel_credentials* channel_creds, grpc_call_credentials* call_creds,
void* reserved) {
grpc_composite_channel_credentials* c =
- (grpc_composite_channel_credentials*)gpr_zalloc(sizeof(*c));
+ static_cast<grpc_composite_channel_credentials*>(gpr_zalloc(sizeof(*c)));
GPR_ASSERT(channel_creds != nullptr && call_creds != nullptr &&
reserved == nullptr);
GRPC_API_TRACE(
diff --git a/src/core/lib/security/credentials/credentials.cc b/src/core/lib/security/credentials/credentials.cc
index 009a5ce4ec..17f7de58be 100644
--- a/src/core/lib/security/credentials/credentials.cc
+++ b/src/core/lib/security/credentials/credentials.cc
@@ -40,8 +40,8 @@
grpc_credentials_metadata_request* grpc_credentials_metadata_request_create(
grpc_call_credentials* creds) {
grpc_credentials_metadata_request* r =
- (grpc_credentials_metadata_request*)gpr_zalloc(
- sizeof(grpc_credentials_metadata_request));
+ static_cast<grpc_credentials_metadata_request*>(
+ gpr_zalloc(sizeof(grpc_credentials_metadata_request)));
r->creds = grpc_call_credentials_ref(creds);
return r;
}
@@ -145,11 +145,12 @@ grpc_channel_credentials_duplicate_without_call_credentials(
}
static void credentials_pointer_arg_destroy(void* p) {
- grpc_channel_credentials_unref((grpc_channel_credentials*)p);
+ grpc_channel_credentials_unref(static_cast<grpc_channel_credentials*>(p));
}
static void* credentials_pointer_arg_copy(void* p) {
- return grpc_channel_credentials_ref((grpc_channel_credentials*)p);
+ return grpc_channel_credentials_ref(
+ static_cast<grpc_channel_credentials*>(p));
}
static int credentials_pointer_cmp(void* a, void* b) { return GPR_ICMP(a, b); }
@@ -173,7 +174,7 @@ grpc_channel_credentials* grpc_channel_credentials_from_arg(
GRPC_ARG_CHANNEL_CREDENTIALS);
return nullptr;
}
- return (grpc_channel_credentials*)arg->value.pointer.p;
+ return static_cast<grpc_channel_credentials*>(arg->value.pointer.p);
}
grpc_channel_credentials* grpc_channel_credentials_find_in_args(
@@ -240,11 +241,11 @@ void grpc_server_credentials_set_auth_metadata_processor(
}
static void server_credentials_pointer_arg_destroy(void* p) {
- grpc_server_credentials_unref((grpc_server_credentials*)p);
+ grpc_server_credentials_unref(static_cast<grpc_server_credentials*>(p));
}
static void* server_credentials_pointer_arg_copy(void* p) {
- return grpc_server_credentials_ref((grpc_server_credentials*)p);
+ return grpc_server_credentials_ref(static_cast<grpc_server_credentials*>(p));
}
static int server_credentials_pointer_cmp(void* a, void* b) {
@@ -267,7 +268,7 @@ grpc_server_credentials* grpc_server_credentials_from_arg(const grpc_arg* arg) {
GRPC_SERVER_CREDENTIALS_ARG);
return nullptr;
}
- return (grpc_server_credentials*)arg->value.pointer.p;
+ return static_cast<grpc_server_credentials*>(arg->value.pointer.p);
}
grpc_server_credentials* grpc_find_server_credentials_in_args(
diff --git a/src/core/lib/security/credentials/credentials_metadata.cc b/src/core/lib/security/credentials/credentials_metadata.cc
index 9ceaf21139..250e384155 100644
--- a/src/core/lib/security/credentials/credentials_metadata.cc
+++ b/src/core/lib/security/credentials/credentials_metadata.cc
@@ -33,8 +33,8 @@ static void mdelem_list_ensure_capacity(grpc_credentials_mdelem_array* list,
while (new_size < target_size) {
new_size *= 2;
}
- list->md =
- (grpc_mdelem*)gpr_realloc(list->md, sizeof(grpc_mdelem) * new_size);
+ list->md = static_cast<grpc_mdelem*>(
+ gpr_realloc(list->md, sizeof(grpc_mdelem) * new_size));
}
void grpc_credentials_mdelem_array_add(grpc_credentials_mdelem_array* list,
diff --git a/src/core/lib/security/credentials/fake/fake_credentials.cc b/src/core/lib/security/credentials/fake/fake_credentials.cc
index 9065325cdd..3b29db2efa 100644
--- a/src/core/lib/security/credentials/fake/fake_credentials.cc
+++ b/src/core/lib/security/credentials/fake/fake_credentials.cc
@@ -59,8 +59,8 @@ static grpc_server_credentials_vtable
grpc_channel_credentials* grpc_fake_transport_security_credentials_create(
void) {
- grpc_channel_credentials* c =
- (grpc_channel_credentials*)gpr_zalloc(sizeof(grpc_channel_credentials));
+ grpc_channel_credentials* c = static_cast<grpc_channel_credentials*>(
+ gpr_zalloc(sizeof(grpc_channel_credentials)));
c->type = GRPC_CHANNEL_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY;
c->vtable = &fake_transport_security_credentials_vtable;
gpr_ref_init(&c->refcount, 1);
@@ -69,8 +69,8 @@ grpc_channel_credentials* grpc_fake_transport_security_credentials_create(
grpc_server_credentials* grpc_fake_transport_security_server_credentials_create(
void) {
- grpc_server_credentials* c =
- (grpc_server_credentials*)gpr_malloc(sizeof(grpc_server_credentials));
+ grpc_server_credentials* c = static_cast<grpc_server_credentials*>(
+ gpr_malloc(sizeof(grpc_server_credentials)));
memset(c, 0, sizeof(grpc_server_credentials));
c->type = GRPC_CHANNEL_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY;
gpr_ref_init(&c->refcount, 1);
@@ -97,7 +97,8 @@ const char* grpc_fake_transport_get_expected_targets(
/* -- Metadata-only test credentials. -- */
static void md_only_test_destruct(grpc_call_credentials* creds) {
- grpc_md_only_test_credentials* c = (grpc_md_only_test_credentials*)creds;
+ grpc_md_only_test_credentials* c =
+ reinterpret_cast<grpc_md_only_test_credentials*>(creds);
GRPC_MDELEM_UNREF(c->md);
}
@@ -105,7 +106,8 @@ static bool md_only_test_get_request_metadata(
grpc_call_credentials* creds, grpc_polling_entity* pollent,
grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array,
grpc_closure* on_request_metadata, grpc_error** error) {
- grpc_md_only_test_credentials* c = (grpc_md_only_test_credentials*)creds;
+ grpc_md_only_test_credentials* c =
+ reinterpret_cast<grpc_md_only_test_credentials*>(creds);
grpc_credentials_mdelem_array_add(md_array, c->md);
if (c->is_async) {
GRPC_CLOSURE_SCHED(on_request_metadata, GRPC_ERROR_NONE);
@@ -126,8 +128,9 @@ static grpc_call_credentials_vtable md_only_test_vtable = {
grpc_call_credentials* grpc_md_only_test_credentials_create(
const char* md_key, const char* md_value, bool is_async) {
- grpc_md_only_test_credentials* c = (grpc_md_only_test_credentials*)gpr_zalloc(
- sizeof(grpc_md_only_test_credentials));
+ grpc_md_only_test_credentials* c =
+ static_cast<grpc_md_only_test_credentials*>(
+ gpr_zalloc(sizeof(grpc_md_only_test_credentials)));
c->base.type = GRPC_CALL_CREDENTIALS_TYPE_OAUTH2;
c->base.vtable = &md_only_test_vtable;
gpr_ref_init(&c->base.refcount, 1);
diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.cc b/src/core/lib/security/credentials/google_default/google_default_credentials.cc
index dc19202033..65455f94b3 100644
--- a/src/core/lib/security/credentials/google_default/google_default_credentials.cc
+++ b/src/core/lib/security/credentials/google_default/google_default_credentials.cc
@@ -60,7 +60,8 @@ typedef struct {
static void on_compute_engine_detection_http_response(void* user_data,
grpc_error* error) {
- compute_engine_detector* detector = (compute_engine_detector*)user_data;
+ compute_engine_detector* detector =
+ static_cast<compute_engine_detector*>(user_data);
if (error == GRPC_ERROR_NONE && detector->response.status == 200 &&
detector->response.hdr_count > 0) {
/* Internet providers can return a generic response to all requests, so
@@ -85,7 +86,7 @@ static void on_compute_engine_detection_http_response(void* user_data,
}
static void destroy_pollset(void* p, grpc_error* e) {
- grpc_pollset_destroy((grpc_pollset*)p);
+ grpc_pollset_destroy(static_cast<grpc_pollset*>(p));
}
static int is_stack_running_on_compute_engine() {
@@ -98,7 +99,8 @@ static int is_stack_running_on_compute_engine() {
on compute engine. */
grpc_millis max_detection_delay = GPR_MS_PER_SEC;
- grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size());
+ grpc_pollset* pollset =
+ static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size()));
grpc_pollset_init(pollset, &g_polling_mu);
detector.pollent = grpc_polling_entity_create_from_pollset(pollset);
detector.is_done = 0;
@@ -171,7 +173,8 @@ static grpc_error* create_default_creds_from_path(
goto end;
}
json = grpc_json_parse_string_with_len(
- (char*)GRPC_SLICE_START_PTR(creds_data), GRPC_SLICE_LENGTH(creds_data));
+ reinterpret_cast<char*> GRPC_SLICE_START_PTR(creds_data),
+ GRPC_SLICE_LENGTH(creds_data));
if (json == nullptr) {
error = grpc_error_set_str(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to parse JSON"),
diff --git a/src/core/lib/security/credentials/iam/iam_credentials.cc b/src/core/lib/security/credentials/iam/iam_credentials.cc
index 75acb2a58e..7f19fbc785 100644
--- a/src/core/lib/security/credentials/iam/iam_credentials.cc
+++ b/src/core/lib/security/credentials/iam/iam_credentials.cc
@@ -28,7 +28,8 @@
#include <grpc/support/sync.h>
static void iam_destruct(grpc_call_credentials* creds) {
- grpc_google_iam_credentials* c = (grpc_google_iam_credentials*)creds;
+ grpc_google_iam_credentials* c =
+ reinterpret_cast<grpc_google_iam_credentials*>(creds);
grpc_credentials_mdelem_array_destroy(&c->md_array);
}
@@ -38,7 +39,8 @@ static bool iam_get_request_metadata(grpc_call_credentials* creds,
grpc_credentials_mdelem_array* md_array,
grpc_closure* on_request_metadata,
grpc_error** error) {
- grpc_google_iam_credentials* c = (grpc_google_iam_credentials*)creds;
+ grpc_google_iam_credentials* c =
+ reinterpret_cast<grpc_google_iam_credentials*>(creds);
grpc_credentials_mdelem_array_append(md_array, &c->md_array);
return true;
}
@@ -63,7 +65,7 @@ grpc_call_credentials* grpc_google_iam_credentials_create(
GPR_ASSERT(token != nullptr);
GPR_ASSERT(authority_selector != nullptr);
grpc_google_iam_credentials* c =
- (grpc_google_iam_credentials*)gpr_zalloc(sizeof(*c));
+ static_cast<grpc_google_iam_credentials*>(gpr_zalloc(sizeof(*c)));
c->base.type = GRPC_CALL_CREDENTIALS_TYPE_IAM;
c->base.vtable = &iam_vtable;
gpr_ref_init(&c->base.refcount, 1);
diff --git a/src/core/lib/security/credentials/jwt/json_token.cc b/src/core/lib/security/credentials/jwt/json_token.cc
index 078f04ed11..f7c9f57808 100644
--- a/src/core/lib/security/credentials/jwt/json_token.cc
+++ b/src/core/lib/security/credentials/jwt/json_token.cc
@@ -96,7 +96,7 @@ grpc_auth_json_key grpc_auth_json_key_create_from_json(const grpc_json* json) {
}
bio = BIO_new(BIO_s_mem());
success = BIO_puts(bio, prop_value);
- if ((success < 0) || ((size_t)success != strlen(prop_value))) {
+ if ((success < 0) || (static_cast<size_t>(success) != strlen(prop_value))) {
gpr_log(GPR_ERROR, "Could not write into openssl BIO.");
goto end;
}
@@ -219,7 +219,8 @@ static char* dot_concat_and_free_strings(char* str1, char* str2) {
size_t str1_len = strlen(str1);
size_t str2_len = strlen(str2);
size_t result_len = str1_len + 1 /* dot */ + str2_len;
- char* result = (char*)gpr_malloc(result_len + 1 /* NULL terminated */);
+ char* result =
+ static_cast<char*>(gpr_malloc(result_len + 1 /* NULL terminated */));
char* current = result;
memcpy(current, str1, str1_len);
current += str1_len;
@@ -271,7 +272,7 @@ char* compute_and_encode_signature(const grpc_auth_json_key* json_key,
gpr_log(GPR_ERROR, "DigestFinal (get signature length) failed.");
goto end;
}
- sig = (unsigned char*)gpr_malloc(sig_len);
+ sig = static_cast<unsigned char*>(gpr_malloc(sig_len));
if (EVP_DigestSignFinal(md_ctx, sig, &sig_len) != 1) {
gpr_log(GPR_ERROR, "DigestFinal (signature compute) failed.");
goto end;
diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.cc b/src/core/lib/security/credentials/jwt/jwt_credentials.cc
index 2404e860e4..05c08a68b0 100644
--- a/src/core/lib/security/credentials/jwt/jwt_credentials.cc
+++ b/src/core/lib/security/credentials/jwt/jwt_credentials.cc
@@ -42,7 +42,7 @@ static void jwt_reset_cache(grpc_service_account_jwt_access_credentials* c) {
static void jwt_destruct(grpc_call_credentials* creds) {
grpc_service_account_jwt_access_credentials* c =
- (grpc_service_account_jwt_access_credentials*)creds;
+ reinterpret_cast<grpc_service_account_jwt_access_credentials*>(creds);
grpc_auth_json_key_destruct(&c->key);
jwt_reset_cache(c);
gpr_mu_destroy(&c->cache_mu);
@@ -55,7 +55,7 @@ static bool jwt_get_request_metadata(grpc_call_credentials* creds,
grpc_closure* on_request_metadata,
grpc_error** error) {
grpc_service_account_jwt_access_credentials* c =
- (grpc_service_account_jwt_access_credentials*)creds;
+ reinterpret_cast<grpc_service_account_jwt_access_credentials*>(creds);
gpr_timespec refresh_threshold = gpr_time_from_seconds(
GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS, GPR_TIMESPAN);
@@ -123,8 +123,8 @@ grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
gpr_log(GPR_ERROR, "Invalid input for jwt credentials creation");
return nullptr;
}
- c = (grpc_service_account_jwt_access_credentials*)gpr_zalloc(
- sizeof(grpc_service_account_jwt_access_credentials));
+ c = static_cast<grpc_service_account_jwt_access_credentials*>(
+ gpr_zalloc(sizeof(grpc_service_account_jwt_access_credentials)));
c->base.type = GRPC_CALL_CREDENTIALS_TYPE_JWT;
gpr_ref_init(&c->base.refcount, 1);
c->base.vtable = &jwt_vtable;
@@ -133,7 +133,7 @@ grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
if (gpr_time_cmp(token_lifetime, max_token_lifetime) > 0) {
gpr_log(GPR_INFO,
"Cropping token lifetime to maximum allowed value (%d secs).",
- (int)max_token_lifetime.tv_sec);
+ static_cast<int>(max_token_lifetime.tv_sec));
token_lifetime = grpc_max_auth_token_lifetime();
}
c->jwt_lifetime = token_lifetime;
@@ -154,7 +154,7 @@ static char* redact_private_key(const char* json_key) {
while (current) {
if (current->type == GRPC_JSON_STRING &&
strcmp(current->key, "private_key") == 0) {
- current->value = (char*)redacted;
+ current->value = const_cast<char*>(redacted);
break;
}
current = current->next;
@@ -177,7 +177,7 @@ grpc_call_credentials* grpc_service_account_jwt_access_credentials_create(
", tv_nsec: %d, clock_type: %d }, "
"reserved=%p)",
clean_json, token_lifetime.tv_sec, token_lifetime.tv_nsec,
- (int)token_lifetime.clock_type, reserved);
+ static_cast<int>(token_lifetime.clock_type), reserved);
gpr_free(clean_json);
}
GPR_ASSERT(reserved == nullptr);
diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.cc b/src/core/lib/security/credentials/jwt/jwt_verifier.cc
index 860506df39..f5c1ada6ca 100644
--- a/src/core/lib/security/credentials/jwt/jwt_verifier.cc
+++ b/src/core/lib/security/credentials/jwt/jwt_verifier.cc
@@ -25,7 +25,6 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
-#include <grpc/support/useful.h>
extern "C" {
#include <openssl/pem.h>
@@ -83,8 +82,9 @@ static grpc_json* parse_json_part_from_jwt(const char* str, size_t len,
gpr_log(GPR_ERROR, "Invalid base64.");
return nullptr;
}
- json = grpc_json_parse_string_with_len((char*)GRPC_SLICE_START_PTR(*buffer),
- GRPC_SLICE_LENGTH(*buffer));
+ json = grpc_json_parse_string_with_len(
+ reinterpret_cast<char*> GRPC_SLICE_START_PTR(*buffer),
+ GRPC_SLICE_LENGTH(*buffer));
if (json == nullptr) {
grpc_slice_unref_internal(*buffer);
gpr_log(GPR_ERROR, "JSON parsing error.");
@@ -130,7 +130,7 @@ static void jose_header_destroy(jose_header* h) {
/* Takes ownership of json and buffer. */
static jose_header* jose_header_from_json(grpc_json* json, grpc_slice buffer) {
grpc_json* cur;
- jose_header* h = (jose_header*)gpr_zalloc(sizeof(jose_header));
+ jose_header* h = static_cast<jose_header*>(gpr_zalloc(sizeof(jose_header)));
h->buffer = buffer;
for (cur = json->child; cur != nullptr; cur = cur->next) {
if (strcmp(cur->key, "alg") == 0) {
@@ -232,7 +232,7 @@ gpr_timespec grpc_jwt_claims_not_before(const grpc_jwt_claims* claims) {
grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_json* json, grpc_slice buffer) {
grpc_json* cur;
grpc_jwt_claims* claims =
- (grpc_jwt_claims*)gpr_malloc(sizeof(grpc_jwt_claims));
+ static_cast<grpc_jwt_claims*>(gpr_malloc(sizeof(grpc_jwt_claims)));
memset(claims, 0, sizeof(grpc_jwt_claims));
claims->json = json;
claims->buffer = buffer;
@@ -348,7 +348,8 @@ static verifier_cb_ctx* verifier_cb_ctx_create(
const char* signed_jwt, size_t signed_jwt_len, void* user_data,
grpc_jwt_verification_done_cb cb) {
grpc_core::ExecCtx exec_ctx;
- verifier_cb_ctx* ctx = (verifier_cb_ctx*)gpr_zalloc(sizeof(verifier_cb_ctx));
+ verifier_cb_ctx* ctx =
+ static_cast<verifier_cb_ctx*>(gpr_zalloc(sizeof(verifier_cb_ctx)));
ctx->verifier = verifier;
ctx->pollent = grpc_polling_entity_create_from_pollset(pollset);
ctx->header = header;
@@ -430,7 +431,7 @@ static EVP_PKEY* extract_pkey_from_x509(const char* x509_str) {
BIO* bio = BIO_new(BIO_s_mem());
size_t len = strlen(x509_str);
GPR_ASSERT(len < INT_MAX);
- BIO_write(bio, x509_str, (int)len);
+ BIO_write(bio, x509_str, static_cast<int>(len));
x509 = PEM_read_bio_X509(bio, nullptr, nullptr, nullptr);
if (x509 == nullptr) {
gpr_log(GPR_ERROR, "Unable to parse x509 cert.");
@@ -626,7 +627,7 @@ end:
}
static void on_keys_retrieved(void* user_data, grpc_error* error) {
- verifier_cb_ctx* ctx = (verifier_cb_ctx*)user_data;
+ verifier_cb_ctx* ctx = static_cast<verifier_cb_ctx*>(user_data);
grpc_json* json = json_from_http(&ctx->responses[HTTP_RESPONSE_KEYS]);
EVP_PKEY* verification_key = nullptr;
grpc_jwt_verifier_status status = GRPC_JWT_VERIFIER_GENERIC_ERROR;
@@ -667,7 +668,7 @@ end:
static void on_openid_config_retrieved(void* user_data, grpc_error* error) {
const grpc_json* cur;
- verifier_cb_ctx* ctx = (verifier_cb_ctx*)user_data;
+ verifier_cb_ctx* ctx = static_cast<verifier_cb_ctx*>(user_data);
const grpc_http_response* response = &ctx->responses[HTTP_RESPONSE_OPENID];
grpc_json* json = json_from_http(response);
grpc_httpcli_request req;
@@ -690,7 +691,7 @@ static void on_openid_config_retrieved(void* user_data, grpc_error* error) {
jwks_uri += 8;
req.handshaker = &grpc_httpcli_ssl;
req.host = gpr_strdup(jwks_uri);
- req.http.path = (char*)strchr(jwks_uri, '/');
+ req.http.path = const_cast<char*>(strchr(jwks_uri, '/'));
if (req.http.path == nullptr) {
req.http.path = (char*)"";
} else {
@@ -755,8 +756,8 @@ const char* grpc_jwt_issuer_email_domain(const char* issuer) {
if (dot == nullptr || dot == email_domain) return email_domain;
GPR_ASSERT(dot > email_domain);
/* There may be a subdomain, we just want the domain. */
- dot = (const char*)gpr_memrchr((void*)email_domain, '.',
- (size_t)(dot - email_domain));
+ dot = static_cast<const char*>(gpr_memrchr(
+ (void*)email_domain, '.', static_cast<size_t>(dot - email_domain)));
if (dot == nullptr) return email_domain;
return dot + 1;
}
@@ -862,7 +863,8 @@ void grpc_jwt_verifier_verify(grpc_jwt_verifier* verifier,
cb != nullptr);
dot = strchr(cur, '.');
if (dot == nullptr) goto error;
- json = parse_json_part_from_jwt(cur, (size_t)(dot - cur), &header_buffer);
+ json = parse_json_part_from_jwt(cur, static_cast<size_t>(dot - cur),
+ &header_buffer);
if (json == nullptr) goto error;
header = jose_header_from_json(json, header_buffer);
if (header == nullptr) goto error;
@@ -870,12 +872,13 @@ void grpc_jwt_verifier_verify(grpc_jwt_verifier* verifier,
cur = dot + 1;
dot = strchr(cur, '.');
if (dot == nullptr) goto error;
- json = parse_json_part_from_jwt(cur, (size_t)(dot - cur), &claims_buffer);
+ json = parse_json_part_from_jwt(cur, static_cast<size_t>(dot - cur),
+ &claims_buffer);
if (json == nullptr) goto error;
claims = grpc_jwt_claims_from_json(json, claims_buffer);
if (claims == nullptr) goto error;
- signed_jwt_len = (size_t)(dot - jwt);
+ signed_jwt_len = static_cast<size_t>(dot - jwt);
cur = dot + 1;
signature = grpc_base64_decode(cur, 1);
if (GRPC_SLICE_IS_EMPTY(signature)) goto error;
@@ -894,13 +897,13 @@ grpc_jwt_verifier* grpc_jwt_verifier_create(
const grpc_jwt_verifier_email_domain_key_url_mapping* mappings,
size_t num_mappings) {
grpc_jwt_verifier* v =
- (grpc_jwt_verifier*)gpr_zalloc(sizeof(grpc_jwt_verifier));
+ static_cast<grpc_jwt_verifier*>(gpr_zalloc(sizeof(grpc_jwt_verifier)));
grpc_httpcli_context_init(&v->http_ctx);
/* We know at least of one mapping. */
v->allocated_mappings = 1 + num_mappings;
- v->mappings = (email_key_mapping*)gpr_malloc(v->allocated_mappings *
- sizeof(email_key_mapping));
+ v->mappings = static_cast<email_key_mapping*>(
+ gpr_malloc(v->allocated_mappings * sizeof(email_key_mapping)));
verifier_put_mapping(v, GRPC_GOOGLE_SERVICE_ACCOUNTS_EMAIL_DOMAIN,
GRPC_GOOGLE_SERVICE_ACCOUNTS_KEY_URL_PREFIX);
/* User-Provided mappings. */
diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
index e243ea52c6..afae7d8f2f 100644
--- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
+++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
@@ -105,7 +105,7 @@ void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token* refresh_token) {
static void oauth2_token_fetcher_destruct(grpc_call_credentials* creds) {
grpc_oauth2_token_fetcher_credentials* c =
- (grpc_oauth2_token_fetcher_credentials*)creds;
+ reinterpret_cast<grpc_oauth2_token_fetcher_credentials*>(creds);
GRPC_MDELEM_UNREF(c->access_token_md);
gpr_mu_destroy(&c->mu);
grpc_pollset_set_destroy(grpc_polling_entity_pollset_set(&c->pollent));
@@ -128,7 +128,8 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response(
}
if (response->body_length > 0) {
- null_terminated_body = (char*)gpr_malloc(response->body_length + 1);
+ null_terminated_body =
+ static_cast<char*>(gpr_malloc(response->body_length + 1));
null_terminated_body[response->body_length] = '\0';
memcpy(null_terminated_body, response->body, response->body_length);
}
@@ -204,9 +205,9 @@ static void on_oauth2_token_fetcher_http_response(void* user_data,
grpc_error* error) {
GRPC_LOG_IF_ERROR("oauth_fetch", GRPC_ERROR_REF(error));
grpc_credentials_metadata_request* r =
- (grpc_credentials_metadata_request*)user_data;
+ static_cast<grpc_credentials_metadata_request*>(user_data);
grpc_oauth2_token_fetcher_credentials* c =
- (grpc_oauth2_token_fetcher_credentials*)r->creds;
+ reinterpret_cast<grpc_oauth2_token_fetcher_credentials*>(r->creds);
grpc_mdelem access_token_md = GRPC_MDNULL;
grpc_millis token_lifetime;
grpc_credentials_status status =
@@ -249,7 +250,7 @@ static bool oauth2_token_fetcher_get_request_metadata(
grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array,
grpc_closure* on_request_metadata, grpc_error** error) {
grpc_oauth2_token_fetcher_credentials* c =
- (grpc_oauth2_token_fetcher_credentials*)creds;
+ reinterpret_cast<grpc_oauth2_token_fetcher_credentials*>(creds);
// Check if we can use the cached token.
grpc_millis refresh_threshold =
GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS * GPR_MS_PER_SEC;
@@ -269,8 +270,8 @@ static bool oauth2_token_fetcher_get_request_metadata(
// Couldn't get the token from the cache.
// Add request to c->pending_requests and start a new fetch if needed.
grpc_oauth2_pending_get_request_metadata* pending_request =
- (grpc_oauth2_pending_get_request_metadata*)gpr_malloc(
- sizeof(*pending_request));
+ static_cast<grpc_oauth2_pending_get_request_metadata*>(
+ gpr_malloc(sizeof(*pending_request)));
pending_request->md_array = md_array;
pending_request->on_request_metadata = on_request_metadata;
pending_request->pollent = pollent;
@@ -298,7 +299,7 @@ static void oauth2_token_fetcher_cancel_get_request_metadata(
grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array,
grpc_error* error) {
grpc_oauth2_token_fetcher_credentials* c =
- (grpc_oauth2_token_fetcher_credentials*)creds;
+ reinterpret_cast<grpc_oauth2_token_fetcher_credentials*>(creds);
gpr_mu_lock(&c->mu);
grpc_oauth2_pending_get_request_metadata* prev = nullptr;
grpc_oauth2_pending_get_request_metadata* pending_request =
@@ -371,8 +372,8 @@ static void compute_engine_fetch_oauth2(
grpc_call_credentials* grpc_google_compute_engine_credentials_create(
void* reserved) {
grpc_oauth2_token_fetcher_credentials* c =
- (grpc_oauth2_token_fetcher_credentials*)gpr_malloc(
- sizeof(grpc_oauth2_token_fetcher_credentials));
+ static_cast<grpc_oauth2_token_fetcher_credentials*>(
+ gpr_malloc(sizeof(grpc_oauth2_token_fetcher_credentials)));
GRPC_API_TRACE("grpc_compute_engine_credentials_create(reserved=%p)", 1,
(reserved));
GPR_ASSERT(reserved == nullptr);
@@ -387,7 +388,7 @@ grpc_call_credentials* grpc_google_compute_engine_credentials_create(
static void refresh_token_destruct(grpc_call_credentials* creds) {
grpc_google_refresh_token_credentials* c =
- (grpc_google_refresh_token_credentials*)creds;
+ reinterpret_cast<grpc_google_refresh_token_credentials*>(creds);
grpc_auth_refresh_token_destruct(&c->refresh_token);
oauth2_token_fetcher_destruct(&c->base.base);
}
@@ -401,7 +402,8 @@ static void refresh_token_fetch_oauth2(
grpc_httpcli_context* httpcli_context, grpc_polling_entity* pollent,
grpc_iomgr_cb_func response_cb, grpc_millis deadline) {
grpc_google_refresh_token_credentials* c =
- (grpc_google_refresh_token_credentials*)metadata_req->creds;
+ reinterpret_cast<grpc_google_refresh_token_credentials*>(
+ metadata_req->creds);
grpc_http_header header = {(char*)"Content-Type",
(char*)"application/x-www-form-urlencoded"};
grpc_httpcli_request request;
@@ -437,8 +439,8 @@ grpc_refresh_token_credentials_create_from_auth_refresh_token(
gpr_log(GPR_ERROR, "Invalid input for refresh token credentials creation");
return nullptr;
}
- c = (grpc_google_refresh_token_credentials*)gpr_zalloc(
- sizeof(grpc_google_refresh_token_credentials));
+ c = static_cast<grpc_google_refresh_token_credentials*>(
+ gpr_zalloc(sizeof(grpc_google_refresh_token_credentials)));
init_oauth2_token_fetcher(&c->base, refresh_token_fetch_oauth2);
c->base.base.vtable = &refresh_token_vtable;
c->refresh_token = refresh_token;
@@ -478,7 +480,8 @@ grpc_call_credentials* grpc_google_refresh_token_credentials_create(
//
static void access_token_destruct(grpc_call_credentials* creds) {
- grpc_access_token_credentials* c = (grpc_access_token_credentials*)creds;
+ grpc_access_token_credentials* c =
+ reinterpret_cast<grpc_access_token_credentials*>(creds);
GRPC_MDELEM_UNREF(c->access_token_md);
}
@@ -486,7 +489,8 @@ static bool access_token_get_request_metadata(
grpc_call_credentials* creds, grpc_polling_entity* pollent,
grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array,
grpc_closure* on_request_metadata, grpc_error** error) {
- grpc_access_token_credentials* c = (grpc_access_token_credentials*)creds;
+ grpc_access_token_credentials* c =
+ reinterpret_cast<grpc_access_token_credentials*>(creds);
grpc_credentials_mdelem_array_add(md_array, c->access_token_md);
return true;
}
@@ -503,8 +507,9 @@ static grpc_call_credentials_vtable access_token_vtable = {
grpc_call_credentials* grpc_access_token_credentials_create(
const char* access_token, void* reserved) {
- grpc_access_token_credentials* c = (grpc_access_token_credentials*)gpr_zalloc(
- sizeof(grpc_access_token_credentials));
+ grpc_access_token_credentials* c =
+ static_cast<grpc_access_token_credentials*>(
+ gpr_zalloc(sizeof(grpc_access_token_credentials)));
GRPC_API_TRACE(
"grpc_access_token_credentials_create(access_token=<redacted>, "
"reserved=%p)",
diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc
index 203ba58c67..ddb86e153b 100644
--- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc
+++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc
@@ -34,7 +34,8 @@
grpc_core::TraceFlag grpc_plugin_credentials_trace(false, "plugin_credentials");
static void plugin_destruct(grpc_call_credentials* creds) {
- grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds;
+ grpc_plugin_credentials* c =
+ reinterpret_cast<grpc_plugin_credentials*>(creds);
gpr_mu_destroy(&c->mu);
if (c->plugin.state != nullptr && c->plugin.destroy != nullptr) {
c->plugin.destroy(c->plugin.state);
@@ -118,7 +119,7 @@ static void plugin_md_request_metadata_ready(void* request,
grpc_core::ExecCtx exec_ctx(GRPC_EXEC_CTX_FLAG_IS_FINISHED |
GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP);
grpc_plugin_credentials_pending_request* r =
- (grpc_plugin_credentials_pending_request*)request;
+ static_cast<grpc_plugin_credentials_pending_request*>(request);
if (grpc_plugin_credentials_trace.enabled()) {
gpr_log(GPR_INFO,
"plugin_credentials[%p]: request %p: plugin returned "
@@ -147,13 +148,14 @@ static bool plugin_get_request_metadata(grpc_call_credentials* creds,
grpc_credentials_mdelem_array* md_array,
grpc_closure* on_request_metadata,
grpc_error** error) {
- grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds;
+ grpc_plugin_credentials* c =
+ reinterpret_cast<grpc_plugin_credentials*>(creds);
bool retval = true; // Synchronous return.
if (c->plugin.get_metadata != nullptr) {
// Create pending_request object.
grpc_plugin_credentials_pending_request* pending_request =
- (grpc_plugin_credentials_pending_request*)gpr_zalloc(
- sizeof(*pending_request));
+ static_cast<grpc_plugin_credentials_pending_request*>(
+ gpr_zalloc(sizeof(*pending_request)));
pending_request->creds = c;
pending_request->md_array = md_array;
pending_request->on_request_metadata = on_request_metadata;
@@ -225,7 +227,8 @@ static bool plugin_get_request_metadata(grpc_call_credentials* creds,
static void plugin_cancel_get_request_metadata(
grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array,
grpc_error* error) {
- grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds;
+ grpc_plugin_credentials* c =
+ reinterpret_cast<grpc_plugin_credentials*>(creds);
gpr_mu_lock(&c->mu);
for (grpc_plugin_credentials_pending_request* pending_request =
c->pending_requests;
@@ -252,7 +255,8 @@ static grpc_call_credentials_vtable plugin_vtable = {
grpc_call_credentials* grpc_metadata_credentials_create_from_plugin(
grpc_metadata_credentials_plugin plugin, void* reserved) {
- grpc_plugin_credentials* c = (grpc_plugin_credentials*)gpr_zalloc(sizeof(*c));
+ grpc_plugin_credentials* c =
+ static_cast<grpc_plugin_credentials*>(gpr_zalloc(sizeof(*c)));
GRPC_API_TRACE("grpc_metadata_credentials_create_from_plugin(reserved=%p)", 1,
(reserved));
GPR_ASSERT(reserved == nullptr);
diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.cc b/src/core/lib/security/credentials/ssl/ssl_credentials.cc
index d8546441c9..a4fce25f3a 100644
--- a/src/core/lib/security/credentials/ssl/ssl_credentials.cc
+++ b/src/core/lib/security/credentials/ssl/ssl_credentials.cc
@@ -42,7 +42,7 @@ void grpc_tsi_ssl_pem_key_cert_pairs_destroy(tsi_ssl_pem_key_cert_pair* kp,
}
static void ssl_destruct(grpc_channel_credentials* creds) {
- grpc_ssl_credentials* c = (grpc_ssl_credentials*)creds;
+ grpc_ssl_credentials* c = reinterpret_cast<grpc_ssl_credentials*>(creds);
gpr_free(c->config.pem_root_certs);
grpc_tsi_ssl_pem_key_cert_pairs_destroy(c->config.pem_key_cert_pair, 1);
}
@@ -51,7 +51,7 @@ static grpc_security_status ssl_create_security_connector(
grpc_channel_credentials* creds, grpc_call_credentials* call_creds,
const char* target, const grpc_channel_args* args,
grpc_channel_security_connector** sc, grpc_channel_args** new_args) {
- grpc_ssl_credentials* c = (grpc_ssl_credentials*)creds;
+ grpc_ssl_credentials* c = reinterpret_cast<grpc_ssl_credentials*>(creds);
grpc_security_status status = GRPC_SECURITY_OK;
const char* overridden_target_name = nullptr;
for (size_t i = 0; args && i < args->num_args; i++) {
@@ -85,8 +85,8 @@ static void ssl_build_config(const char* pem_root_certs,
if (pem_key_cert_pair != nullptr) {
GPR_ASSERT(pem_key_cert_pair->private_key != nullptr);
GPR_ASSERT(pem_key_cert_pair->cert_chain != nullptr);
- config->pem_key_cert_pair = (tsi_ssl_pem_key_cert_pair*)gpr_zalloc(
- sizeof(tsi_ssl_pem_key_cert_pair));
+ config->pem_key_cert_pair = static_cast<tsi_ssl_pem_key_cert_pair*>(
+ gpr_zalloc(sizeof(tsi_ssl_pem_key_cert_pair)));
config->pem_key_cert_pair->cert_chain =
gpr_strdup(pem_key_cert_pair->cert_chain);
config->pem_key_cert_pair->private_key =
@@ -97,8 +97,8 @@ static void ssl_build_config(const char* pem_root_certs,
grpc_channel_credentials* grpc_ssl_credentials_create(
const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
void* reserved) {
- grpc_ssl_credentials* c =
- (grpc_ssl_credentials*)gpr_zalloc(sizeof(grpc_ssl_credentials));
+ grpc_ssl_credentials* c = static_cast<grpc_ssl_credentials*>(
+ gpr_zalloc(sizeof(grpc_ssl_credentials)));
GRPC_API_TRACE(
"grpc_ssl_credentials_create(pem_root_certs=%s, "
"pem_key_cert_pair=%p, "
@@ -123,7 +123,8 @@ struct grpc_ssl_server_credentials_options {
};
static void ssl_server_destruct(grpc_server_credentials* creds) {
- grpc_ssl_server_credentials* c = (grpc_ssl_server_credentials*)creds;
+ grpc_ssl_server_credentials* c =
+ reinterpret_cast<grpc_ssl_server_credentials*>(creds);
grpc_tsi_ssl_pem_key_cert_pairs_destroy(c->config.pem_key_cert_pairs,
c->config.num_key_cert_pairs);
gpr_free(c->config.pem_root_certs);
@@ -143,8 +144,8 @@ tsi_ssl_pem_key_cert_pair* grpc_convert_grpc_to_tsi_cert_pairs(
tsi_ssl_pem_key_cert_pair* tsi_pairs = nullptr;
if (num_key_cert_pairs > 0) {
GPR_ASSERT(pem_key_cert_pairs != nullptr);
- tsi_pairs = (tsi_ssl_pem_key_cert_pair*)gpr_zalloc(
- num_key_cert_pairs * sizeof(tsi_ssl_pem_key_cert_pair));
+ tsi_pairs = static_cast<tsi_ssl_pem_key_cert_pair*>(
+ gpr_zalloc(num_key_cert_pairs * sizeof(tsi_ssl_pem_key_cert_pair)));
}
for (size_t i = 0; i < num_key_cert_pairs; i++) {
GPR_ASSERT(pem_key_cert_pairs[i].private_key != nullptr);
@@ -174,15 +175,15 @@ grpc_ssl_server_certificate_config* grpc_ssl_server_certificate_config_create(
const grpc_ssl_pem_key_cert_pair* pem_key_cert_pairs,
size_t num_key_cert_pairs) {
grpc_ssl_server_certificate_config* config =
- (grpc_ssl_server_certificate_config*)gpr_zalloc(
- sizeof(grpc_ssl_server_certificate_config));
+ static_cast<grpc_ssl_server_certificate_config*>(
+ gpr_zalloc(sizeof(grpc_ssl_server_certificate_config)));
if (pem_root_certs != nullptr) {
config->pem_root_certs = gpr_strdup(pem_root_certs);
}
if (num_key_cert_pairs > 0) {
GPR_ASSERT(pem_key_cert_pairs != nullptr);
- config->pem_key_cert_pairs = (grpc_ssl_pem_key_cert_pair*)gpr_zalloc(
- num_key_cert_pairs * sizeof(grpc_ssl_pem_key_cert_pair));
+ config->pem_key_cert_pairs = static_cast<grpc_ssl_pem_key_cert_pair*>(
+ gpr_zalloc(num_key_cert_pairs * sizeof(grpc_ssl_pem_key_cert_pair)));
}
config->num_key_cert_pairs = num_key_cert_pairs;
for (size_t i = 0; i < num_key_cert_pairs; i++) {
@@ -217,8 +218,8 @@ grpc_ssl_server_credentials_create_options_using_config(
gpr_log(GPR_ERROR, "Certificate config must not be NULL.");
goto done;
}
- options = (grpc_ssl_server_credentials_options*)gpr_zalloc(
- sizeof(grpc_ssl_server_credentials_options));
+ options = static_cast<grpc_ssl_server_credentials_options*>(
+ gpr_zalloc(sizeof(grpc_ssl_server_credentials_options)));
options->client_certificate_request = client_certificate_request;
options->certificate_config = config;
done:
@@ -235,14 +236,14 @@ grpc_ssl_server_credentials_create_options_using_config_fetcher(
}
grpc_ssl_server_certificate_config_fetcher* fetcher =
- (grpc_ssl_server_certificate_config_fetcher*)gpr_zalloc(
- sizeof(grpc_ssl_server_certificate_config_fetcher));
+ static_cast<grpc_ssl_server_certificate_config_fetcher*>(
+ gpr_zalloc(sizeof(grpc_ssl_server_certificate_config_fetcher)));
fetcher->cb = cb;
fetcher->user_data = user_data;
grpc_ssl_server_credentials_options* options =
- (grpc_ssl_server_credentials_options*)gpr_zalloc(
- sizeof(grpc_ssl_server_credentials_options));
+ static_cast<grpc_ssl_server_credentials_options*>(
+ gpr_zalloc(sizeof(grpc_ssl_server_credentials_options)));
options->client_certificate_request = client_certificate_request;
options->certificate_config_fetcher = fetcher;
@@ -307,8 +308,8 @@ grpc_server_credentials* grpc_ssl_server_credentials_create_with_options(
goto done;
}
- c = (grpc_ssl_server_credentials*)gpr_zalloc(
- sizeof(grpc_ssl_server_credentials));
+ c = static_cast<grpc_ssl_server_credentials*>(
+ gpr_zalloc(sizeof(grpc_ssl_server_credentials)));
c->base.type = GRPC_CHANNEL_CREDENTIALS_TYPE_SSL;
gpr_ref_init(&c->base.refcount, 1);
c->base.vtable = &ssl_server_vtable;
diff --git a/src/core/lib/security/transport/client_auth_filter.cc b/src/core/lib/security/transport/client_auth_filter.cc
index 045cb3e239..d2313807ff 100644
--- a/src/core/lib/security/transport/client_auth_filter.cc
+++ b/src/core/lib/security/transport/client_auth_filter.cc
@@ -70,11 +70,11 @@ struct channel_data {
void grpc_auth_metadata_context_reset(
grpc_auth_metadata_context* auth_md_context) {
if (auth_md_context->service_url != nullptr) {
- gpr_free((char*)auth_md_context->service_url);
+ gpr_free(const_cast<char*>(auth_md_context->service_url));
auth_md_context->service_url = nullptr;
}
if (auth_md_context->method_name != nullptr) {
- gpr_free((char*)auth_md_context->method_name);
+ gpr_free(const_cast<char*>(auth_md_context->method_name));
auth_md_context->method_name = nullptr;
}
GRPC_AUTH_CONTEXT_UNREF(
@@ -93,10 +93,11 @@ static void add_error(grpc_error** combined, grpc_error* error) {
}
static void on_credentials_metadata(void* arg, grpc_error* input_error) {
- grpc_transport_stream_op_batch* batch = (grpc_transport_stream_op_batch*)arg;
+ grpc_transport_stream_op_batch* batch =
+ static_cast<grpc_transport_stream_op_batch*>(arg);
grpc_call_element* elem =
- (grpc_call_element*)batch->handler_private.extra_arg;
- call_data* calld = (call_data*)elem->call_data;
+ static_cast<grpc_call_element*>(batch->handler_private.extra_arg);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
grpc_auth_metadata_context_reset(&calld->auth_md_context);
grpc_error* error = GRPC_ERROR_REF(input_error);
if (error == GRPC_ERROR_NONE) {
@@ -118,6 +119,7 @@ static void on_credentials_metadata(void* arg, grpc_error* input_error) {
grpc_transport_stream_op_batch_finish_with_failure(batch, error,
calld->call_combiner);
}
+ GRPC_CALL_STACK_UNREF(calld->owning_call, "get_request_metadata");
}
void grpc_auth_metadata_context_build(
@@ -158,8 +160,8 @@ void grpc_auth_metadata_context_build(
}
static void cancel_get_request_metadata(void* arg, grpc_error* error) {
- grpc_call_element* elem = (grpc_call_element*)arg;
- call_data* calld = (call_data*)elem->call_data;
+ grpc_call_element* elem = static_cast<grpc_call_element*>(arg);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
if (error != GRPC_ERROR_NONE) {
grpc_call_credentials_cancel_get_request_metadata(
calld->creds, &calld->md_array, GRPC_ERROR_REF(error));
@@ -169,12 +171,11 @@ static void cancel_get_request_metadata(void* arg, grpc_error* error) {
static void send_security_metadata(grpc_call_element* elem,
grpc_transport_stream_op_batch* batch) {
- call_data* calld = (call_data*)elem->call_data;
- channel_data* chand = (channel_data*)elem->channel_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
grpc_client_security_context* ctx =
- (grpc_client_security_context*)batch->payload
- ->context[GRPC_CONTEXT_SECURITY]
- .value;
+ static_cast<grpc_client_security_context*>(
+ batch->payload->context[GRPC_CONTEXT_SECURITY].value);
grpc_call_credentials* channel_call_creds =
chand->security_connector->request_metadata_creds;
int call_creds_has_md = (ctx != nullptr) && (ctx->creds != nullptr);
@@ -208,7 +209,7 @@ static void send_security_metadata(grpc_call_element* elem,
chand->auth_context, &calld->auth_md_context);
GPR_ASSERT(calld->pollent != nullptr);
-
+ GRPC_CALL_STACK_REF(calld->owning_call, "get_request_metadata");
GRPC_CLOSURE_INIT(&calld->async_result_closure, on_credentials_metadata,
batch, grpc_schedule_on_exec_ctx);
grpc_error* error = GRPC_ERROR_NONE;
@@ -230,10 +231,11 @@ static void send_security_metadata(grpc_call_element* elem,
}
static void on_host_checked(void* arg, grpc_error* error) {
- grpc_transport_stream_op_batch* batch = (grpc_transport_stream_op_batch*)arg;
+ grpc_transport_stream_op_batch* batch =
+ static_cast<grpc_transport_stream_op_batch*>(arg);
grpc_call_element* elem =
- (grpc_call_element*)batch->handler_private.extra_arg;
- call_data* calld = (call_data*)elem->call_data;
+ static_cast<grpc_call_element*>(batch->handler_private.extra_arg);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
if (error == GRPC_ERROR_NONE) {
send_security_metadata(elem, batch);
} else {
@@ -250,12 +252,13 @@ static void on_host_checked(void* arg, grpc_error* error) {
calld->call_combiner);
gpr_free(error_msg);
}
+ GRPC_CALL_STACK_UNREF(calld->owning_call, "check_call_host");
}
static void cancel_check_call_host(void* arg, grpc_error* error) {
- grpc_call_element* elem = (grpc_call_element*)arg;
- call_data* calld = (call_data*)elem->call_data;
- channel_data* chand = (channel_data*)elem->channel_data;
+ grpc_call_element* elem = static_cast<grpc_call_element*>(arg);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
if (error != GRPC_ERROR_NONE) {
grpc_channel_security_connector_cancel_check_call_host(
chand->security_connector, &calld->async_result_closure,
@@ -266,11 +269,11 @@ static void cancel_check_call_host(void* arg, grpc_error* error) {
static void auth_start_transport_stream_op_batch(
grpc_call_element* elem, grpc_transport_stream_op_batch* batch) {
- GPR_TIMER_BEGIN("auth_start_transport_stream_op_batch", 0);
+ GPR_TIMER_SCOPE("auth_start_transport_stream_op_batch", 0);
/* grab pointers to our data from the call element */
- call_data* calld = (call_data*)elem->call_data;
- channel_data* chand = (channel_data*)elem->channel_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
if (!batch->cancel_stream) {
GPR_ASSERT(batch->payload->context != nullptr);
@@ -281,9 +284,8 @@ static void auth_start_transport_stream_op_batch(
grpc_client_security_context_destroy;
}
grpc_client_security_context* sec_ctx =
- (grpc_client_security_context*)batch->payload
- ->context[GRPC_CONTEXT_SECURITY]
- .value;
+ static_cast<grpc_client_security_context*>(
+ batch->payload->context[GRPC_CONTEXT_SECURITY].value);
GRPC_AUTH_CONTEXT_UNREF(sec_ctx->auth_context, "client auth filter");
sec_ctx->auth_context =
GRPC_AUTH_CONTEXT_REF(chand->auth_context, "client_auth_filter");
@@ -312,6 +314,7 @@ static void auth_start_transport_stream_op_batch(
}
if (calld->have_host) {
batch->handler_private.extra_arg = elem;
+ 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);
@@ -332,20 +335,18 @@ static void auth_start_transport_stream_op_batch(
grpc_schedule_on_exec_ctx));
}
gpr_free(call_host);
- GPR_TIMER_END("auth_start_transport_stream_op_batch", 0);
return; /* early exit */
}
}
/* pass control down the stack */
grpc_call_next_op(elem, batch);
- GPR_TIMER_END("auth_start_transport_stream_op_batch", 0);
}
/* Constructor for call_data */
static grpc_error* init_call_elem(grpc_call_element* elem,
const grpc_call_element_args* args) {
- call_data* calld = (call_data*)elem->call_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
calld->owning_call = args->call_stack;
calld->call_combiner = args->call_combiner;
return GRPC_ERROR_NONE;
@@ -353,7 +354,7 @@ static grpc_error* init_call_elem(grpc_call_element* elem,
static void set_pollset_or_pollset_set(grpc_call_element* elem,
grpc_polling_entity* pollent) {
- call_data* calld = (call_data*)elem->call_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
calld->pollent = pollent;
}
@@ -361,7 +362,7 @@ static void set_pollset_or_pollset_set(grpc_call_element* elem,
static void destroy_call_elem(grpc_call_element* elem,
const grpc_call_final_info* final_info,
grpc_closure* ignored) {
- call_data* calld = (call_data*)elem->call_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
grpc_credentials_mdelem_array_destroy(&calld->md_array);
grpc_call_credentials_unref(calld->creds);
if (calld->have_host) {
@@ -390,7 +391,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem,
}
/* grab pointers to our data from the channel element */
- channel_data* chand = (channel_data*)elem->channel_data;
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
/* The first and the last filters tend to be implemented differently to
handle the case that there's no 'next' filter to call on the up or down
@@ -399,8 +400,8 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem,
/* initialize members */
chand->security_connector =
- (grpc_channel_security_connector*)GRPC_SECURITY_CONNECTOR_REF(
- sc, "client_auth_filter");
+ reinterpret_cast<grpc_channel_security_connector*>(
+ GRPC_SECURITY_CONNECTOR_REF(sc, "client_auth_filter"));
chand->auth_context =
GRPC_AUTH_CONTEXT_REF(auth_context, "client_auth_filter");
return GRPC_ERROR_NONE;
@@ -409,7 +410,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem,
/* Destructor for channel data */
static void destroy_channel_elem(grpc_channel_element* elem) {
/* grab pointers to our data from the channel element */
- channel_data* chand = (channel_data*)elem->channel_data;
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
grpc_channel_security_connector* sc = chand->security_connector;
if (sc != nullptr) {
GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "client_auth_filter");
diff --git a/src/core/lib/security/transport/lb_targets_info.cc b/src/core/lib/security/transport/lb_targets_info.cc
index 183b1ebf35..67a3c7449d 100644
--- a/src/core/lib/security/transport/lb_targets_info.cc
+++ b/src/core/lib/security/transport/lb_targets_info.cc
@@ -26,14 +26,15 @@
#define GRPC_ARG_LB_SECURE_NAMING_MAP "grpc.lb_secure_naming_map"
static void* targets_info_copy(void* p) {
- return grpc_slice_hash_table_ref((grpc_slice_hash_table*)p);
+ return grpc_slice_hash_table_ref(static_cast<grpc_slice_hash_table*>(p));
}
static void targets_info_destroy(void* p) {
- grpc_slice_hash_table_unref((grpc_slice_hash_table*)p);
+ grpc_slice_hash_table_unref(static_cast<grpc_slice_hash_table*>(p));
}
static int targets_info_cmp(void* a, void* b) {
- return grpc_slice_hash_table_cmp((const grpc_slice_hash_table*)a,
- (const grpc_slice_hash_table*)b);
+ return grpc_slice_hash_table_cmp(
+ static_cast<const grpc_slice_hash_table*>(a),
+ static_cast<const grpc_slice_hash_table*>(b));
}
static const grpc_arg_pointer_vtable server_to_balancer_names_vtable = {
targets_info_copy, targets_info_destroy, targets_info_cmp};
@@ -51,7 +52,8 @@ grpc_slice_hash_table* grpc_lb_targets_info_find_in_args(
grpc_channel_args_find(args, GRPC_ARG_LB_SECURE_NAMING_MAP);
if (targets_info_arg != nullptr) {
GPR_ASSERT(targets_info_arg->type == GRPC_ARG_POINTER);
- return (grpc_slice_hash_table*)targets_info_arg->value.pointer.p;
+ return static_cast<grpc_slice_hash_table*>(
+ targets_info_arg->value.pointer.p);
}
return nullptr;
}
diff --git a/src/core/lib/security/transport/secure_endpoint.cc b/src/core/lib/security/transport/secure_endpoint.cc
index bd8a6cd76a..f72f8b6121 100644
--- a/src/core/lib/security/transport/secure_endpoint.cc
+++ b/src/core/lib/security/transport/secure_endpoint.cc
@@ -144,7 +144,7 @@ static void on_read(void* user_data, grpc_error* error) {
unsigned i;
uint8_t keep_looping = 0;
tsi_result result = TSI_OK;
- secure_endpoint* ep = (secure_endpoint*)user_data;
+ secure_endpoint* ep = static_cast<secure_endpoint*>(user_data);
uint8_t* cur = GRPC_SLICE_START_PTR(ep->read_staging_buffer);
uint8_t* end = GRPC_SLICE_END_PTR(ep->read_staging_buffer);
@@ -168,7 +168,7 @@ static void on_read(void* user_data, grpc_error* error) {
size_t message_size = GRPC_SLICE_LENGTH(encrypted);
while (message_size > 0 || keep_looping) {
- size_t unprotected_buffer_size_written = (size_t)(end - cur);
+ size_t unprotected_buffer_size_written = static_cast<size_t>(end - cur);
size_t processed_message_size = message_size;
gpr_mu_lock(&ep->protector_mu);
result = tsi_frame_protector_unprotect(
@@ -205,7 +205,8 @@ static void on_read(void* user_data, grpc_error* error) {
ep->read_buffer,
grpc_slice_split_head(
&ep->read_staging_buffer,
- (size_t)(cur - GRPC_SLICE_START_PTR(ep->read_staging_buffer))));
+ static_cast<size_t>(
+ cur - GRPC_SLICE_START_PTR(ep->read_staging_buffer))));
}
}
@@ -226,7 +227,7 @@ static void on_read(void* user_data, grpc_error* error) {
static void endpoint_read(grpc_endpoint* secure_ep, grpc_slice_buffer* slices,
grpc_closure* cb) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
ep->read_cb = cb;
ep->read_buffer = slices;
grpc_slice_buffer_reset_and_unref_internal(ep->read_buffer);
@@ -252,11 +253,11 @@ static void flush_write_staging_buffer(secure_endpoint* ep, uint8_t** cur,
static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices,
grpc_closure* cb) {
- GPR_TIMER_BEGIN("secure_endpoint.endpoint_write", 0);
+ GPR_TIMER_SCOPE("secure_endpoint.endpoint_write", 0);
unsigned i;
tsi_result result = TSI_OK;
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
uint8_t* cur = GRPC_SLICE_START_PTR(ep->write_staging_buffer);
uint8_t* end = GRPC_SLICE_END_PTR(ep->write_staging_buffer);
@@ -282,7 +283,7 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices,
uint8_t* message_bytes = GRPC_SLICE_START_PTR(plain);
size_t message_size = GRPC_SLICE_LENGTH(plain);
while (message_size > 0) {
- size_t protected_buffer_size_to_send = (size_t)(end - cur);
+ size_t protected_buffer_size_to_send = static_cast<size_t>(end - cur);
size_t processed_message_size = message_size;
gpr_mu_lock(&ep->protector_mu);
result = tsi_frame_protector_protect(ep->protector, message_bytes,
@@ -307,7 +308,7 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices,
if (result == TSI_OK) {
size_t still_pending_size;
do {
- size_t protected_buffer_size_to_send = (size_t)(end - cur);
+ size_t protected_buffer_size_to_send = static_cast<size_t>(end - cur);
gpr_mu_lock(&ep->protector_mu);
result = tsi_frame_protector_protect_flush(
ep->protector, cur, &protected_buffer_size_to_send,
@@ -324,8 +325,8 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices,
&ep->output_buffer,
grpc_slice_split_head(
&ep->write_staging_buffer,
- (size_t)(cur -
- GRPC_SLICE_START_PTR(ep->write_staging_buffer))));
+ static_cast<size_t>(
+ cur - GRPC_SLICE_START_PTR(ep->write_staging_buffer))));
}
}
}
@@ -336,55 +337,53 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices,
GRPC_CLOSURE_SCHED(
cb, grpc_set_tsi_error_result(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Wrap failed"), result));
- GPR_TIMER_END("secure_endpoint.endpoint_write", 0);
return;
}
grpc_endpoint_write(ep->wrapped_ep, &ep->output_buffer, cb);
- GPR_TIMER_END("secure_endpoint.endpoint_write", 0);
}
static void endpoint_shutdown(grpc_endpoint* secure_ep, grpc_error* why) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
grpc_endpoint_shutdown(ep->wrapped_ep, why);
}
static void endpoint_destroy(grpc_endpoint* secure_ep) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
SECURE_ENDPOINT_UNREF(ep, "destroy");
}
static void endpoint_add_to_pollset(grpc_endpoint* secure_ep,
grpc_pollset* pollset) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
grpc_endpoint_add_to_pollset(ep->wrapped_ep, pollset);
}
static void endpoint_add_to_pollset_set(grpc_endpoint* secure_ep,
grpc_pollset_set* pollset_set) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
grpc_endpoint_add_to_pollset_set(ep->wrapped_ep, pollset_set);
}
static void endpoint_delete_from_pollset_set(grpc_endpoint* secure_ep,
grpc_pollset_set* pollset_set) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
grpc_endpoint_delete_from_pollset_set(ep->wrapped_ep, pollset_set);
}
static char* endpoint_get_peer(grpc_endpoint* secure_ep) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
return grpc_endpoint_get_peer(ep->wrapped_ep);
}
static int endpoint_get_fd(grpc_endpoint* secure_ep) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
return grpc_endpoint_get_fd(ep->wrapped_ep);
}
static grpc_resource_user* endpoint_get_resource_user(
grpc_endpoint* secure_ep) {
- secure_endpoint* ep = (secure_endpoint*)secure_ep;
+ secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
return grpc_endpoint_get_resource_user(ep->wrapped_ep);
}
@@ -405,7 +404,8 @@ grpc_endpoint* grpc_secure_endpoint_create(
grpc_endpoint* transport, grpc_slice* leftover_slices,
size_t leftover_nslices) {
size_t i;
- secure_endpoint* ep = (secure_endpoint*)gpr_malloc(sizeof(secure_endpoint));
+ secure_endpoint* ep =
+ static_cast<secure_endpoint*>(gpr_malloc(sizeof(secure_endpoint)));
ep->base.vtable = &vtable;
ep->wrapped_ep = transport;
ep->protector = protector;
diff --git a/src/core/lib/security/transport/security_connector.cc b/src/core/lib/security/transport/security_connector.cc
index 1d962f94b2..bd5da1bbd2 100644
--- a/src/core/lib/security/transport/security_connector.cc
+++ b/src/core/lib/security/transport/security_connector.cc
@@ -23,7 +23,6 @@
#include <grpc/slice_buffer.h>
#include <grpc/support/alloc.h>
-#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
@@ -31,6 +30,7 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/handshaker.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/iomgr/load_file.h"
#include "src/core/lib/security/context/security_context.h"
@@ -239,8 +239,8 @@ static void* connector_arg_copy(void* p) {
}
static int connector_cmp(void* a, void* b) {
- return grpc_security_connector_cmp((grpc_security_connector*)a,
- (grpc_security_connector*)b);
+ return grpc_security_connector_cmp(static_cast<grpc_security_connector*>(a),
+ static_cast<grpc_security_connector*>(b));
}
static const grpc_arg_pointer_vtable connector_arg_vtable = {
@@ -258,7 +258,7 @@ grpc_security_connector* grpc_security_connector_from_arg(const grpc_arg* arg) {
GRPC_ARG_SECURITY_CONNECTOR);
return nullptr;
}
- return (grpc_security_connector*)arg->value.pointer.p;
+ return static_cast<grpc_security_connector*>(arg->value.pointer.p);
}
grpc_security_connector* grpc_security_connector_find_in_args(
@@ -308,7 +308,7 @@ typedef struct {
static void fake_channel_destroy(grpc_security_connector* sc) {
grpc_fake_channel_security_connector* c =
- (grpc_fake_channel_security_connector*)sc;
+ reinterpret_cast<grpc_fake_channel_security_connector*>(sc);
grpc_call_credentials_unref(c->base.request_metadata_creds);
gpr_free(c->target);
gpr_free(c->expected_targets);
@@ -420,7 +420,7 @@ static void fake_channel_check_peer(grpc_security_connector* sc, tsi_peer peer,
grpc_closure* on_peer_checked) {
fake_check_peer(sc, peer, auth_context, on_peer_checked);
grpc_fake_channel_security_connector* c =
- (grpc_fake_channel_security_connector*)sc;
+ reinterpret_cast<grpc_fake_channel_security_connector*>(sc);
fake_secure_name_check(c->target, c->expected_targets, c->is_lb_channel);
}
@@ -433,9 +433,9 @@ static void fake_server_check_peer(grpc_security_connector* sc, tsi_peer peer,
static int fake_channel_cmp(grpc_security_connector* sc1,
grpc_security_connector* sc2) {
grpc_fake_channel_security_connector* c1 =
- (grpc_fake_channel_security_connector*)sc1;
+ reinterpret_cast<grpc_fake_channel_security_connector*>(sc1);
grpc_fake_channel_security_connector* c2 =
- (grpc_fake_channel_security_connector*)sc2;
+ reinterpret_cast<grpc_fake_channel_security_connector*>(sc2);
int c = grpc_channel_security_connector_cmp(&c1->base, &c2->base);
if (c != 0) return c;
c = strcmp(c1->target, c2->target);
@@ -452,8 +452,8 @@ static int fake_channel_cmp(grpc_security_connector* sc1,
static int fake_server_cmp(grpc_security_connector* sc1,
grpc_security_connector* sc2) {
return grpc_server_security_connector_cmp(
- (grpc_server_security_connector*)sc1,
- (grpc_server_security_connector*)sc2);
+ reinterpret_cast<grpc_server_security_connector*>(sc1),
+ reinterpret_cast<grpc_server_security_connector*>(sc2));
}
static bool fake_channel_check_call_host(grpc_channel_security_connector* sc,
@@ -498,7 +498,8 @@ grpc_channel_security_connector* grpc_fake_channel_security_connector_create(
grpc_call_credentials* request_metadata_creds, const char* target,
const grpc_channel_args* args) {
grpc_fake_channel_security_connector* c =
- (grpc_fake_channel_security_connector*)gpr_zalloc(sizeof(*c));
+ static_cast<grpc_fake_channel_security_connector*>(
+ gpr_zalloc(sizeof(*c)));
gpr_ref_init(&c->base.base.refcount, 1);
c->base.base.url_scheme = GRPC_FAKE_SECURITY_URL_SCHEME;
c->base.base.vtable = &fake_channel_vtable;
@@ -518,8 +519,8 @@ grpc_channel_security_connector* grpc_fake_channel_security_connector_create(
grpc_server_security_connector* grpc_fake_server_security_connector_create(
grpc_server_credentials* server_creds) {
grpc_server_security_connector* c =
- (grpc_server_security_connector*)gpr_zalloc(
- sizeof(grpc_server_security_connector));
+ static_cast<grpc_server_security_connector*>(
+ gpr_zalloc(sizeof(grpc_server_security_connector)));
gpr_ref_init(&c->base.refcount, 1);
c->base.vtable = &fake_server_vtable;
c->base.url_scheme = GRPC_FAKE_SECURITY_URL_SCHEME;
@@ -546,14 +547,14 @@ static bool server_connector_has_cert_config_fetcher(
grpc_ssl_server_security_connector* c) {
GPR_ASSERT(c != nullptr);
grpc_ssl_server_credentials* server_creds =
- (grpc_ssl_server_credentials*)c->base.server_creds;
+ reinterpret_cast<grpc_ssl_server_credentials*>(c->base.server_creds);
GPR_ASSERT(server_creds != nullptr);
return server_creds->certificate_config_fetcher.cb != nullptr;
}
static void ssl_channel_destroy(grpc_security_connector* sc) {
grpc_ssl_channel_security_connector* c =
- (grpc_ssl_channel_security_connector*)sc;
+ reinterpret_cast<grpc_ssl_channel_security_connector*>(sc);
grpc_channel_credentials_unref(c->base.channel_creds);
grpc_call_credentials_unref(c->base.request_metadata_creds);
tsi_ssl_client_handshaker_factory_unref(c->client_handshaker_factory);
@@ -565,7 +566,7 @@ static void ssl_channel_destroy(grpc_security_connector* sc) {
static void ssl_server_destroy(grpc_security_connector* sc) {
grpc_ssl_server_security_connector* c =
- (grpc_ssl_server_security_connector*)sc;
+ reinterpret_cast<grpc_ssl_server_security_connector*>(sc);
grpc_server_credentials_unref(c->base.server_creds);
tsi_ssl_server_handshaker_factory_unref(c->server_handshaker_factory);
c->server_handshaker_factory = nullptr;
@@ -575,7 +576,7 @@ static void ssl_server_destroy(grpc_security_connector* sc) {
static void ssl_channel_add_handshakers(grpc_channel_security_connector* sc,
grpc_handshake_manager* handshake_mgr) {
grpc_ssl_channel_security_connector* c =
- (grpc_ssl_channel_security_connector*)sc;
+ reinterpret_cast<grpc_ssl_channel_security_connector*>(sc);
// Instantiate TSI handshaker.
tsi_handshaker* tsi_hs = nullptr;
tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker(
@@ -597,8 +598,8 @@ static void ssl_channel_add_handshakers(grpc_channel_security_connector* sc,
static const char** fill_alpn_protocol_strings(size_t* num_alpn_protocols) {
GPR_ASSERT(num_alpn_protocols != nullptr);
*num_alpn_protocols = grpc_chttp2_num_alpn_versions();
- const char** alpn_protocol_strings =
- (const char**)gpr_malloc(sizeof(const char*) * (*num_alpn_protocols));
+ const char** alpn_protocol_strings = static_cast<const char**>(
+ gpr_malloc(sizeof(const char*) * (*num_alpn_protocols)));
for (size_t i = 0; i < *num_alpn_protocols; i++) {
alpn_protocol_strings[i] = grpc_chttp2_get_alpn_version_index(i);
}
@@ -627,13 +628,13 @@ static bool try_replace_server_handshaker_factory(
config->pem_key_cert_pairs, config->num_key_cert_pairs);
tsi_ssl_server_handshaker_factory* new_handshaker_factory = nullptr;
grpc_ssl_server_credentials* server_creds =
- (grpc_ssl_server_credentials*)sc->base.server_creds;
+ reinterpret_cast<grpc_ssl_server_credentials*>(sc->base.server_creds);
tsi_result result = tsi_create_ssl_server_handshaker_factory_ex(
cert_pairs, config->num_key_cert_pairs, config->pem_root_certs,
get_tsi_client_certificate_request_type(
server_creds->config.client_certificate_request),
- ssl_cipher_suites(), alpn_protocol_strings, (uint16_t)num_alpn_protocols,
- &new_handshaker_factory);
+ ssl_cipher_suites(), alpn_protocol_strings,
+ static_cast<uint16_t>(num_alpn_protocols), &new_handshaker_factory);
gpr_free(cert_pairs);
gpr_free((void*)alpn_protocol_strings);
@@ -659,7 +660,7 @@ static bool try_fetch_ssl_server_credentials(
if (!server_connector_has_cert_config_fetcher(sc)) return false;
grpc_ssl_server_credentials* server_creds =
- (grpc_ssl_server_credentials*)sc->base.server_creds;
+ reinterpret_cast<grpc_ssl_server_credentials*>(sc->base.server_creds);
grpc_ssl_certificate_config_reload_status cb_result =
server_creds->certificate_config_fetcher.cb(
server_creds->certificate_config_fetcher.user_data,
@@ -686,7 +687,7 @@ static bool try_fetch_ssl_server_credentials(
static void ssl_server_add_handshakers(grpc_server_security_connector* sc,
grpc_handshake_manager* handshake_mgr) {
grpc_ssl_server_security_connector* c =
- (grpc_ssl_server_security_connector*)sc;
+ reinterpret_cast<grpc_ssl_server_security_connector*>(sc);
// Instantiate TSI handshaker.
try_fetch_ssl_server_credentials(c);
tsi_handshaker* tsi_hs = nullptr;
@@ -788,7 +789,7 @@ static void ssl_channel_check_peer(grpc_security_connector* sc, tsi_peer peer,
grpc_auth_context** auth_context,
grpc_closure* on_peer_checked) {
grpc_ssl_channel_security_connector* c =
- (grpc_ssl_channel_security_connector*)sc;
+ reinterpret_cast<grpc_ssl_channel_security_connector*>(sc);
grpc_error* error = ssl_check_peer(sc,
c->overridden_target_name != nullptr
? c->overridden_target_name
@@ -809,9 +810,9 @@ static void ssl_server_check_peer(grpc_security_connector* sc, tsi_peer peer,
static int ssl_channel_cmp(grpc_security_connector* sc1,
grpc_security_connector* sc2) {
grpc_ssl_channel_security_connector* c1 =
- (grpc_ssl_channel_security_connector*)sc1;
+ reinterpret_cast<grpc_ssl_channel_security_connector*>(sc1);
grpc_ssl_channel_security_connector* c2 =
- (grpc_ssl_channel_security_connector*)sc2;
+ reinterpret_cast<grpc_ssl_channel_security_connector*>(sc2);
int c = grpc_channel_security_connector_cmp(&c1->base, &c2->base);
if (c != 0) return c;
c = strcmp(c1->target_name, c2->target_name);
@@ -825,15 +826,15 @@ static int ssl_channel_cmp(grpc_security_connector* sc1,
static int ssl_server_cmp(grpc_security_connector* sc1,
grpc_security_connector* sc2) {
return grpc_server_security_connector_cmp(
- (grpc_server_security_connector*)sc1,
- (grpc_server_security_connector*)sc2);
+ reinterpret_cast<grpc_server_security_connector*>(sc1),
+ reinterpret_cast<grpc_server_security_connector*>(sc2));
}
static void add_shallow_auth_property_to_peer(tsi_peer* peer,
const grpc_auth_property* prop,
const char* tsi_prop_name) {
tsi_peer_property* tsi_prop = &peer->properties[peer->property_count++];
- tsi_prop->name = (char*)tsi_prop_name;
+ tsi_prop->name = const_cast<char*>(tsi_prop_name);
tsi_prop->value.data = prop->value;
tsi_prop->value.length = prop->value_length;
}
@@ -850,8 +851,8 @@ tsi_peer tsi_shallow_peer_from_ssl_auth_context(
while (grpc_auth_property_iterator_next(&it) != nullptr) max_num_props++;
if (max_num_props > 0) {
- peer.properties = (tsi_peer_property*)gpr_malloc(max_num_props *
- sizeof(tsi_peer_property));
+ peer.properties = static_cast<tsi_peer_property*>(
+ gpr_malloc(max_num_props * sizeof(tsi_peer_property)));
it = grpc_auth_context_property_iterator(auth_context);
while ((prop = grpc_auth_property_iterator_next(&it)) != nullptr) {
if (strcmp(prop->name, GRPC_X509_SAN_PROPERTY_NAME) == 0) {
@@ -879,7 +880,7 @@ static bool ssl_channel_check_call_host(grpc_channel_security_connector* sc,
grpc_closure* on_call_host_checked,
grpc_error** error) {
grpc_ssl_channel_security_connector* c =
- (grpc_ssl_channel_security_connector*)sc;
+ reinterpret_cast<grpc_ssl_channel_security_connector*>(sc);
grpc_security_status status = GRPC_SECURITY_ERROR;
tsi_peer peer = tsi_shallow_peer_from_ssl_auth_context(auth_context);
if (ssl_host_matches_name(&peer, host)) status = GRPC_SECURITY_OK;
@@ -963,7 +964,8 @@ const char* grpc_get_default_ssl_roots(void) {
gpr_once_init(&once, init_default_pem_root_certs);
return GRPC_SLICE_IS_EMPTY(default_pem_root_certs)
? nullptr
- : (const char*)GRPC_SLICE_START_PTR(default_pem_root_certs);
+ : reinterpret_cast<const char*>
+ GRPC_SLICE_START_PTR(default_pem_root_certs);
}
grpc_security_status grpc_ssl_channel_security_connector_create(
@@ -994,8 +996,8 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
pem_root_certs = config->pem_root_certs;
}
- c = (grpc_ssl_channel_security_connector*)gpr_zalloc(
- sizeof(grpc_ssl_channel_security_connector));
+ c = static_cast<grpc_ssl_channel_security_connector*>(
+ gpr_zalloc(sizeof(grpc_ssl_channel_security_connector)));
gpr_ref_init(&c->base.base.refcount, 1);
c->base.base.vtable = &ssl_channel_vtable;
@@ -1017,8 +1019,8 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
config->pem_key_cert_pair->cert_chain != nullptr;
result = tsi_create_ssl_client_handshaker_factory(
has_key_cert_pair ? config->pem_key_cert_pair : nullptr, pem_root_certs,
- ssl_cipher_suites(), alpn_protocol_strings, (uint16_t)num_alpn_protocols,
- &c->client_handshaker_factory);
+ ssl_cipher_suites(), alpn_protocol_strings,
+ static_cast<uint16_t>(num_alpn_protocols), &c->client_handshaker_factory);
if (result != TSI_OK) {
gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.",
tsi_result_to_string(result));
@@ -1039,8 +1041,8 @@ static grpc_ssl_server_security_connector*
grpc_ssl_server_security_connector_initialize(
grpc_server_credentials* server_creds) {
grpc_ssl_server_security_connector* c =
- (grpc_ssl_server_security_connector*)gpr_zalloc(
- sizeof(grpc_ssl_server_security_connector));
+ static_cast<grpc_ssl_server_security_connector*>(
+ gpr_zalloc(sizeof(grpc_ssl_server_security_connector)));
gpr_ref_init(&c->base.base.refcount, 1);
c->base.base.url_scheme = GRPC_SSL_URL_SCHEME;
c->base.base.vtable = &ssl_server_vtable;
@@ -1053,7 +1055,7 @@ grpc_security_status grpc_ssl_server_security_connector_create(
grpc_server_credentials* gsc, grpc_server_security_connector** sc) {
tsi_result result = TSI_OK;
grpc_ssl_server_credentials* server_credentials =
- (grpc_ssl_server_credentials*)gsc;
+ reinterpret_cast<grpc_ssl_server_credentials*>(gsc);
grpc_security_status retval = GRPC_SECURITY_OK;
GPR_ASSERT(server_credentials != nullptr);
@@ -1078,7 +1080,8 @@ grpc_security_status grpc_ssl_server_security_connector_create(
get_tsi_client_certificate_request_type(
server_credentials->config.client_certificate_request),
ssl_cipher_suites(), alpn_protocol_strings,
- (uint16_t)num_alpn_protocols, &c->server_handshaker_factory);
+ static_cast<uint16_t>(num_alpn_protocols),
+ &c->server_handshaker_factory);
gpr_free((void*)alpn_protocol_strings);
if (result != TSI_OK) {
gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.",
diff --git a/src/core/lib/security/transport/security_handshaker.cc b/src/core/lib/security/transport/security_handshaker.cc
index 7623fbfd5b..b37392ab81 100644
--- a/src/core/lib/security/transport/security_handshaker.cc
+++ b/src/core/lib/security/transport/security_handshaker.cc
@@ -68,8 +68,8 @@ typedef struct {
static size_t move_read_buffer_into_handshake_buffer(security_handshaker* h) {
size_t bytes_in_read_buffer = h->args->read_buffer->length;
if (h->handshake_buffer_size < bytes_in_read_buffer) {
- h->handshake_buffer =
- (uint8_t*)gpr_realloc(h->handshake_buffer, bytes_in_read_buffer);
+ h->handshake_buffer = static_cast<uint8_t*>(
+ gpr_realloc(h->handshake_buffer, bytes_in_read_buffer));
h->handshake_buffer_size = bytes_in_read_buffer;
}
size_t offset = 0;
@@ -205,7 +205,7 @@ static void on_peer_checked_inner(security_handshaker* h, grpc_error* error) {
}
static void on_peer_checked(void* arg, grpc_error* error) {
- security_handshaker* h = (security_handshaker*)arg;
+ security_handshaker* h = static_cast<security_handshaker*>(arg);
gpr_mu_lock(&h->mu);
on_peer_checked_inner(h, error);
gpr_mu_unlock(&h->mu);
@@ -249,7 +249,7 @@ static grpc_error* on_handshake_next_done_locked(
if (bytes_to_send_size > 0) {
// Send data to peer, if needed.
grpc_slice to_send = grpc_slice_from_copied_buffer(
- (const char*)bytes_to_send, bytes_to_send_size);
+ reinterpret_cast<const char*>(bytes_to_send), bytes_to_send_size);
grpc_slice_buffer_reset_and_unref_internal(&h->outgoing);
grpc_slice_buffer_add(&h->outgoing, to_send);
grpc_endpoint_write(h->args->endpoint, &h->outgoing,
@@ -268,7 +268,7 @@ static grpc_error* on_handshake_next_done_locked(
static void on_handshake_next_done_grpc_wrapper(
tsi_result result, void* user_data, const unsigned char* bytes_to_send,
size_t bytes_to_send_size, tsi_handshaker_result* handshaker_result) {
- security_handshaker* h = (security_handshaker*)user_data;
+ security_handshaker* h = static_cast<security_handshaker*>(user_data);
// This callback will be invoked by TSI in a non-grpc thread, so it's
// safe to create our own exec_ctx here.
grpc_core::ExecCtx exec_ctx;
@@ -307,7 +307,7 @@ static grpc_error* do_handshaker_next_locked(
}
static void on_handshake_data_received_from_peer(void* arg, grpc_error* error) {
- security_handshaker* h = (security_handshaker*)arg;
+ security_handshaker* h = static_cast<security_handshaker*>(arg);
gpr_mu_lock(&h->mu);
if (error != GRPC_ERROR_NONE || h->shutdown) {
security_handshake_failed_locked(
@@ -333,7 +333,7 @@ static void on_handshake_data_received_from_peer(void* arg, grpc_error* error) {
}
static void on_handshake_data_sent_to_peer(void* arg, grpc_error* error) {
- security_handshaker* h = (security_handshaker*)arg;
+ security_handshaker* h = static_cast<security_handshaker*>(arg);
gpr_mu_lock(&h->mu);
if (error != GRPC_ERROR_NONE || h->shutdown) {
security_handshake_failed_locked(
@@ -364,13 +364,13 @@ static void on_handshake_data_sent_to_peer(void* arg, grpc_error* error) {
//
static void security_handshaker_destroy(grpc_handshaker* handshaker) {
- security_handshaker* h = (security_handshaker*)handshaker;
+ security_handshaker* h = reinterpret_cast<security_handshaker*>(handshaker);
security_handshaker_unref(h);
}
static void security_handshaker_shutdown(grpc_handshaker* handshaker,
grpc_error* why) {
- security_handshaker* h = (security_handshaker*)handshaker;
+ security_handshaker* h = reinterpret_cast<security_handshaker*>(handshaker);
gpr_mu_lock(&h->mu);
if (!h->shutdown) {
h->shutdown = true;
@@ -385,7 +385,7 @@ static void security_handshaker_do_handshake(grpc_handshaker* handshaker,
grpc_tcp_server_acceptor* acceptor,
grpc_closure* on_handshake_done,
grpc_handshaker_args* args) {
- security_handshaker* h = (security_handshaker*)handshaker;
+ security_handshaker* h = reinterpret_cast<security_handshaker*>(handshaker);
gpr_mu_lock(&h->mu);
h->args = args;
h->on_handshake_done = on_handshake_done;
@@ -408,15 +408,16 @@ static const grpc_handshaker_vtable security_handshaker_vtable = {
static grpc_handshaker* security_handshaker_create(
tsi_handshaker* handshaker, grpc_security_connector* connector) {
- security_handshaker* h =
- (security_handshaker*)gpr_zalloc(sizeof(security_handshaker));
+ security_handshaker* h = static_cast<security_handshaker*>(
+ gpr_zalloc(sizeof(security_handshaker)));
grpc_handshaker_init(&security_handshaker_vtable, &h->base);
h->handshaker = handshaker;
h->connector = GRPC_SECURITY_CONNECTOR_REF(connector, "handshake");
gpr_mu_init(&h->mu);
gpr_ref_init(&h->refs, 1);
h->handshake_buffer_size = GRPC_INITIAL_HANDSHAKE_BUFFER_SIZE;
- h->handshake_buffer = (uint8_t*)gpr_malloc(h->handshake_buffer_size);
+ h->handshake_buffer =
+ static_cast<uint8_t*>(gpr_malloc(h->handshake_buffer_size));
GRPC_CLOSURE_INIT(&h->on_handshake_data_sent_to_peer,
on_handshake_data_sent_to_peer, h,
grpc_schedule_on_exec_ctx);
@@ -456,7 +457,7 @@ static const grpc_handshaker_vtable fail_handshaker_vtable = {
fail_handshaker_do_handshake};
static grpc_handshaker* fail_handshaker_create() {
- grpc_handshaker* h = (grpc_handshaker*)gpr_malloc(sizeof(*h));
+ grpc_handshaker* h = static_cast<grpc_handshaker*>(gpr_malloc(sizeof(*h)));
grpc_handshaker_init(&fail_handshaker_vtable, h);
return h;
}
@@ -469,8 +470,8 @@ static void client_handshaker_factory_add_handshakers(
grpc_handshaker_factory* handshaker_factory, const grpc_channel_args* args,
grpc_handshake_manager* handshake_mgr) {
grpc_channel_security_connector* security_connector =
- (grpc_channel_security_connector*)grpc_security_connector_find_in_args(
- args);
+ reinterpret_cast<grpc_channel_security_connector*>(
+ grpc_security_connector_find_in_args(args));
grpc_channel_security_connector_add_handshakers(security_connector,
handshake_mgr);
}
@@ -479,8 +480,8 @@ static void server_handshaker_factory_add_handshakers(
grpc_handshaker_factory* hf, const grpc_channel_args* args,
grpc_handshake_manager* handshake_mgr) {
grpc_server_security_connector* security_connector =
- (grpc_server_security_connector*)grpc_security_connector_find_in_args(
- args);
+ reinterpret_cast<grpc_server_security_connector*>(
+ grpc_security_connector_find_in_args(args));
grpc_server_security_connector_add_handshakers(security_connector,
handshake_mgr);
}
diff --git a/src/core/lib/security/transport/server_auth_filter.cc b/src/core/lib/security/transport/server_auth_filter.cc
index f82971dc56..409aded650 100644
--- a/src/core/lib/security/transport/server_auth_filter.cc
+++ b/src/core/lib/security/transport/server_auth_filter.cc
@@ -65,8 +65,8 @@ static grpc_metadata_array metadata_batch_to_md_array(
grpc_slice value = GRPC_MDVALUE(md);
if (result.count == result.capacity) {
result.capacity = GPR_MAX(result.capacity + 8, result.capacity * 2);
- result.metadata = (grpc_metadata*)gpr_realloc(
- result.metadata, result.capacity * sizeof(grpc_metadata));
+ result.metadata = static_cast<grpc_metadata*>(gpr_realloc(
+ result.metadata, result.capacity * sizeof(grpc_metadata)));
}
usr_md = &result.metadata[result.count++];
usr_md->key = grpc_slice_ref_internal(key);
@@ -77,8 +77,8 @@ static grpc_metadata_array metadata_batch_to_md_array(
static grpc_filtered_mdelem remove_consumed_md(void* user_data,
grpc_mdelem md) {
- grpc_call_element* elem = (grpc_call_element*)user_data;
- call_data* calld = (call_data*)elem->call_data;
+ grpc_call_element* elem = static_cast<grpc_call_element*>(user_data);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
size_t i;
for (i = 0; i < calld->num_consumed_md; i++) {
const grpc_metadata* consumed_md = &calld->consumed_md[i];
@@ -95,7 +95,7 @@ static void on_md_processing_done_inner(grpc_call_element* elem,
const grpc_metadata* response_md,
size_t num_response_md,
grpc_error* error) {
- call_data* calld = (call_data*)elem->call_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
grpc_transport_stream_op_batch* batch = calld->recv_initial_metadata_batch;
/* TODO(jboeuf): Implement support for response_md. */
if (response_md != nullptr && num_response_md > 0) {
@@ -118,12 +118,12 @@ static void on_md_processing_done(
void* user_data, const grpc_metadata* consumed_md, size_t num_consumed_md,
const grpc_metadata* response_md, size_t num_response_md,
grpc_status_code status, const char* error_details) {
- grpc_call_element* elem = (grpc_call_element*)user_data;
- call_data* calld = (call_data*)elem->call_data;
+ grpc_call_element* elem = static_cast<grpc_call_element*>(user_data);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
grpc_core::ExecCtx exec_ctx;
// If the call was not cancelled while we were in flight, process the result.
- if (gpr_atm_full_cas(&calld->state, (gpr_atm)STATE_INIT,
- (gpr_atm)STATE_DONE)) {
+ if (gpr_atm_full_cas(&calld->state, static_cast<gpr_atm>(STATE_INIT),
+ static_cast<gpr_atm>(STATE_DONE))) {
grpc_error* error = GRPC_ERROR_NONE;
if (status != GRPC_STATUS_OK) {
if (error_details == nullptr) {
@@ -146,12 +146,12 @@ static void on_md_processing_done(
}
static void cancel_call(void* arg, grpc_error* error) {
- grpc_call_element* elem = (grpc_call_element*)arg;
- call_data* calld = (call_data*)elem->call_data;
+ grpc_call_element* elem = static_cast<grpc_call_element*>(arg);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
// If the result was not already processed, invoke the callback now.
if (error != GRPC_ERROR_NONE &&
- gpr_atm_full_cas(&calld->state, (gpr_atm)STATE_INIT,
- (gpr_atm)STATE_CANCELLED)) {
+ gpr_atm_full_cas(&calld->state, static_cast<gpr_atm>(STATE_INIT),
+ static_cast<gpr_atm>(STATE_CANCELLED))) {
on_md_processing_done_inner(elem, nullptr, 0, nullptr, 0,
GRPC_ERROR_REF(error));
}
@@ -159,9 +159,9 @@ static void cancel_call(void* arg, grpc_error* error) {
}
static void recv_initial_metadata_ready(void* arg, grpc_error* error) {
- grpc_call_element* elem = (grpc_call_element*)arg;
- channel_data* chand = (channel_data*)elem->channel_data;
- call_data* calld = (call_data*)elem->call_data;
+ grpc_call_element* elem = static_cast<grpc_call_element*>(arg);
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
+ call_data* calld = static_cast<call_data*>(elem->call_data);
grpc_transport_stream_op_batch* batch = calld->recv_initial_metadata_batch;
if (error == GRPC_ERROR_NONE) {
if (chand->creds != nullptr && chand->creds->processor.process != nullptr) {
@@ -187,7 +187,7 @@ static void recv_initial_metadata_ready(void* arg, grpc_error* error) {
static void auth_start_transport_stream_op_batch(
grpc_call_element* elem, grpc_transport_stream_op_batch* batch) {
- call_data* calld = (call_data*)elem->call_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
if (batch->recv_initial_metadata) {
// Inject our callback.
calld->recv_initial_metadata_batch = batch;
@@ -202,8 +202,8 @@ static void auth_start_transport_stream_op_batch(
/* Constructor for call_data */
static grpc_error* init_call_elem(grpc_call_element* elem,
const grpc_call_element_args* args) {
- call_data* calld = (call_data*)elem->call_data;
- channel_data* chand = (channel_data*)elem->channel_data;
+ call_data* calld = static_cast<call_data*>(elem->call_data);
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
calld->call_combiner = args->call_combiner;
calld->owning_call = args->call_stack;
GRPC_CLOSURE_INIT(&calld->recv_initial_metadata_ready,
@@ -234,7 +234,7 @@ static void destroy_call_elem(grpc_call_element* elem,
static grpc_error* init_channel_elem(grpc_channel_element* elem,
grpc_channel_element_args* args) {
GPR_ASSERT(!args->is_last);
- channel_data* chand = (channel_data*)elem->channel_data;
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
grpc_auth_context* auth_context =
grpc_find_auth_context_in_args(args->channel_args);
GPR_ASSERT(auth_context != nullptr);
@@ -248,7 +248,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem,
/* Destructor for channel data */
static void destroy_channel_elem(grpc_channel_element* elem) {
- channel_data* chand = (channel_data*)elem->channel_data;
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
GRPC_AUTH_CONTEXT_UNREF(chand->auth_context, "server_auth_filter");
grpc_server_credentials_unref(chand->creds);
}