Skip to content

Commit

Permalink
Support grpc 1.45+ with no insecure build
Browse files Browse the repository at this point in the history
Fixes joyrex2001#23.

See also grpc/grpc#25586, and particularly
compare to the changes in the first-party PHP extension.
  • Loading branch information
musicinmybrain committed May 9, 2022
1 parent 593d90f commit fe917b0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ grpc_google_default_credentials_create(NULL);
EOT
) and ($EXTRA_DEFINES .= " -DGRPC_GOOGLE_DEFAULT_CREDENTIALS_CREATE_HAS_1_ARG");

check_lib(
%CHECKLIB_ARGS,
debug => 1,
function => <<'EOT',
grpc_channel_credentials * cred = NULL;
return 0;
EOT
) and ($EXTRA_DEFINES .= " -DGRPC_NO_INSECURE_BUILD");


WriteMakefile(
NAME => 'Grpc::XS',
VERSION_FROM => 'lib/Grpc/XS.pm',
Expand Down
10 changes: 10 additions & 0 deletions ext/channel.xs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,21 @@ new(const char *class, const char* target, ... )
perl_grpc_read_args_array(hash, &args);

if (creds == NULL) {
#ifdef GRPC_NO_INSECURE_BUILD
grpc_channel_credentials * insecure_cred = grpc_insecure_credentials_create();
ctx->wrapped = grpc_channel_create(target, insecure_cred, &args);
grpc_channel_credentials_release(insecure_cred);
#else
ctx->wrapped = grpc_insecure_channel_create(target, &args, NULL);
#endif
} else {
gpr_log(GPR_DEBUG, "Initialized secure channel");
#ifdef GRPC_NO_INSECURE_BUILD
ctx->wrapped = grpc_channel_create(target, creds->wrapped, &args);
#else
ctx->wrapped =
grpc_secure_channel_create(creds->wrapped, target, &args, NULL);
#endif
}
free(args.args);

Expand Down
16 changes: 15 additions & 1 deletion ext/server.xs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,27 @@ requestCall(Grpc::XS::Server self)
long
addHttp2Port(Grpc::XS::Server self, SV* addr)
CODE:
#ifdef GRPC_NO_INSECURE_BUILD
{
grpc_server_credentials * insecure_cred = grpc_insecure_server_credentials_create();
RETVAL = grpc_server_add_http2_port(self->wrapped, SvPV_nolen(addr), insecure_cred);
grpc_server_credentials_release(insecure_cred);
}
#else
RETVAL = grpc_server_add_insecure_http2_port(self->wrapped, SvPV_nolen(addr));
#endif
OUTPUT: RETVAL
long
addSecureHttp2Port(Grpc::XS::Server self, SV* addr, Grpc::XS::ServerCredentials creds)
CODE:
RETVAL = grpc_server_add_secure_http2_port(self->wrapped, SvPV_nolen(addr), creds->wrapped);
RETVAL =
#ifdef GRPC_NO_INSECURE_BUILD
grpc_server_add_http2_port(
#else
grpc_server_add_secure_http2_port(
#endif
self->wrapped, SvPV_nolen(addr), creds->wrapped);
OUTPUT: RETVAL

void
Expand Down

0 comments on commit fe917b0

Please sign in to comment.