Fixing node and ruby builds.

pull/141/head
Julien Boeuf 10 years ago
parent 68ad53edf3
commit 073d7b6cd9
  1. 3
      src/node/binding.gyp
  2. 24
      src/node/credentials.cc
  3. 18
      src/node/server_credentials.cc
  4. 2
      src/ruby/ext/grpc/extconf.rb
  5. 19
      src/ruby/ext/grpc/rb_credentials.c
  6. 14
      src/ruby/ext/grpc/rb_server_credentials.c

@ -19,9 +19,6 @@
'link_settings': { 'link_settings': {
'libraries': [ 'libraries': [
'-lgrpc', '-lgrpc',
'-levent',
'-levent_pthreads',
'-levent_core',
'-lrt', '-lrt',
'-lgpr', '-lgpr',
'-lpthread' '-lpthread'

@ -136,33 +136,29 @@ NAN_METHOD(Credentials::CreateDefault) {
NAN_METHOD(Credentials::CreateSsl) { NAN_METHOD(Credentials::CreateSsl) {
NanScope(); NanScope();
char *root_certs; char *root_certs = NULL;
char *private_key = NULL; grpc_ssl_pem_key_cert_pair key_cert_pair = {NULL, NULL};
char *cert_chain = NULL; if (Buffer::HasInstance(args[0])) {
int root_certs_length, private_key_length = 0, cert_chain_length = 0; root_certs = Buffer::Data(args[0]);
if (!Buffer::HasInstance(args[0])) { } else if (!(args[0]->IsNull() || args[0]->IsUndefined())) {
return NanThrowTypeError("createSsl's first argument must be a Buffer"); return NanThrowTypeError("createSsl's first argument must be a Buffer");
} }
root_certs = Buffer::Data(args[0]);
root_certs_length = Buffer::Length(args[0]);
if (Buffer::HasInstance(args[1])) { if (Buffer::HasInstance(args[1])) {
private_key = Buffer::Data(args[1]); key_cert_pair.private_key = Buffer::Data(args[1]);
private_key_length = Buffer::Length(args[1]);
} else if (!(args[1]->IsNull() || args[1]->IsUndefined())) { } else if (!(args[1]->IsNull() || args[1]->IsUndefined())) {
return NanThrowTypeError( return NanThrowTypeError(
"createSSl's second argument must be a Buffer if provided"); "createSSl's second argument must be a Buffer if provided");
} }
if (Buffer::HasInstance(args[2])) { if (Buffer::HasInstance(args[2])) {
cert_chain = Buffer::Data(args[2]); key_cert_pair.cert_chain = Buffer::Data(args[2]);
cert_chain_length = Buffer::Length(args[2]);
} else if (!(args[2]->IsNull() || args[2]->IsUndefined())) { } else if (!(args[2]->IsNull() || args[2]->IsUndefined())) {
return NanThrowTypeError( return NanThrowTypeError(
"createSSl's third argument must be a Buffer if provided"); "createSSl's third argument must be a Buffer if provided");
} }
NanReturnValue(WrapStruct(grpc_ssl_credentials_create( NanReturnValue(WrapStruct(grpc_ssl_credentials_create(
reinterpret_cast<unsigned char *>(root_certs), root_certs_length, root_certs,
reinterpret_cast<unsigned char *>(private_key), private_key_length, key_cert_pair.private_key == NULL ? NULL : &key_cert_pair)));
reinterpret_cast<unsigned char *>(cert_chain), cert_chain_length)));
} }
NAN_METHOD(Credentials::CreateComposite) { NAN_METHOD(Credentials::CreateComposite) {

@ -123,14 +123,12 @@ NAN_METHOD(ServerCredentials::New) {
} }
NAN_METHOD(ServerCredentials::CreateSsl) { NAN_METHOD(ServerCredentials::CreateSsl) {
// TODO: have the node API support multiple key/cert pairs.
NanScope(); NanScope();
char *root_certs = NULL; char *root_certs = NULL;
char *private_key; grpc_ssl_pem_key_cert_pair key_cert_pair;
char *cert_chain;
int root_certs_length = 0, private_key_length, cert_chain_length;
if (Buffer::HasInstance(args[0])) { if (Buffer::HasInstance(args[0])) {
root_certs = Buffer::Data(args[0]); root_certs = Buffer::Data(args[0]);
root_certs_length = Buffer::Length(args[0]);
} else if (!(args[0]->IsNull() || args[0]->IsUndefined())) { } else if (!(args[0]->IsNull() || args[0]->IsUndefined())) {
return NanThrowTypeError( return NanThrowTypeError(
"createSSl's first argument must be a Buffer if provided"); "createSSl's first argument must be a Buffer if provided");
@ -138,17 +136,13 @@ NAN_METHOD(ServerCredentials::CreateSsl) {
if (!Buffer::HasInstance(args[1])) { if (!Buffer::HasInstance(args[1])) {
return NanThrowTypeError("createSsl's second argument must be a Buffer"); return NanThrowTypeError("createSsl's second argument must be a Buffer");
} }
private_key = Buffer::Data(args[1]); key_cert_pair.private_key = Buffer::Data(args[1]);
private_key_length = Buffer::Length(args[1]);
if (!Buffer::HasInstance(args[2])) { if (!Buffer::HasInstance(args[2])) {
return NanThrowTypeError("createSsl's third argument must be a Buffer"); return NanThrowTypeError("createSsl's third argument must be a Buffer");
} }
cert_chain = Buffer::Data(args[2]); key_cert_pair.cert_chain = Buffer::Data(args[2]);
cert_chain_length = Buffer::Length(args[2]); NanReturnValue(WrapStruct(
NanReturnValue(WrapStruct(grpc_ssl_server_credentials_create( grpc_ssl_server_credentials_create(root_certs, &key_cert_pair, 1)));
reinterpret_cast<unsigned char *>(root_certs), root_certs_length,
reinterpret_cast<unsigned char *>(private_key), private_key_length,
reinterpret_cast<unsigned char *>(cert_chain), cert_chain_length)));
} }
NAN_METHOD(ServerCredentials::CreateFake) { NAN_METHOD(ServerCredentials::CreateFake) {

@ -68,7 +68,7 @@ $CFLAGS << ' -Wno-return-type '
$CFLAGS << ' -Wall ' $CFLAGS << ' -Wall '
$CFLAGS << ' -pedantic ' $CFLAGS << ' -pedantic '
$LDFLAGS << ' -lgrpc -lgpr -levent -levent_pthreads -levent_core' $LDFLAGS << ' -lgrpc -lgpr'
# crash('need grpc lib') unless have_library('grpc', 'grpc_channel_destroy') # crash('need grpc lib') unless have_library('grpc', 'grpc_channel_destroy')
# #

@ -214,6 +214,7 @@ static VALUE grpc_rb_credentials_init(int argc, VALUE *argv, VALUE self) {
VALUE pem_cert_chain = Qnil; VALUE pem_cert_chain = Qnil;
grpc_rb_credentials *wrapper = NULL; grpc_rb_credentials *wrapper = NULL;
grpc_credentials *creds = NULL; grpc_credentials *creds = NULL;
/* TODO: Remove mandatory arg when we support default roots. */
/* "12" == 1 mandatory arg, 2 (credentials) is optional */ /* "12" == 1 mandatory arg, 2 (credentials) is optional */
rb_scan_args(argc, argv, "12", &pem_root_certs, &pem_private_key, rb_scan_args(argc, argv, "12", &pem_root_certs, &pem_private_key,
&pem_cert_chain); &pem_cert_chain);
@ -225,22 +226,12 @@ static VALUE grpc_rb_credentials_init(int argc, VALUE *argv, VALUE self) {
return Qnil; return Qnil;
} }
if (pem_private_key == Qnil && pem_cert_chain == Qnil) { if (pem_private_key == Qnil && pem_cert_chain == Qnil) {
creds = grpc_ssl_credentials_create(RSTRING_PTR(pem_root_certs), creds = grpc_ssl_credentials_create(RSTRING_PTR(pem_root_certs), NULL);
RSTRING_LEN(pem_root_certs), NULL, 0,
NULL, 0);
} else if (pem_cert_chain == Qnil) {
creds = grpc_ssl_credentials_create(
RSTRING_PTR(pem_root_certs), RSTRING_LEN(pem_root_certs),
RSTRING_PTR(pem_private_key), RSTRING_LEN(pem_private_key),
RSTRING_PTR(pem_cert_chain), RSTRING_LEN(pem_cert_chain));
} else if (pem_private_key == Qnil) {
creds = grpc_ssl_credentials_create(
RSTRING_PTR(pem_root_certs), RSTRING_LEN(pem_root_certs), NULL, 0,
RSTRING_PTR(pem_cert_chain), RSTRING_LEN(pem_cert_chain));
} else { } else {
grpc_ssl_pem_key_cert_pair key_cert_pair = {RSTRING_PTR(pem_private_key),
RSTRING_PTR(pem_cert_chain)};
creds = grpc_ssl_credentials_create( creds = grpc_ssl_credentials_create(
RSTRING_PTR(pem_root_certs), RSTRING_LEN(pem_root_certs), RSTRING_PTR(pem_root_certs), &key_cert_pair);
RSTRING_PTR(pem_private_key), RSTRING_LEN(pem_private_key), NULL, 0);
} }
if (creds == NULL) { if (creds == NULL) {
rb_raise(rb_eRuntimeError, "could not create a credentials, not sure why"); rb_raise(rb_eRuntimeError, "could not create a credentials, not sure why");

@ -145,8 +145,10 @@ static ID id_pem_cert_chain;
static VALUE grpc_rb_server_credentials_init(VALUE self, VALUE pem_root_certs, static VALUE grpc_rb_server_credentials_init(VALUE self, VALUE pem_root_certs,
VALUE pem_private_key, VALUE pem_private_key,
VALUE pem_cert_chain) { VALUE pem_cert_chain) {
/* TODO support multiple key cert pairs in the ruby API. */
grpc_rb_server_credentials *wrapper = NULL; grpc_rb_server_credentials *wrapper = NULL;
grpc_server_credentials *creds = NULL; grpc_server_credentials *creds = NULL;
grpc_ssl_pem_key_cert_pair key_cert_pair = {NULL, NULL};
Data_Get_Struct(self, grpc_rb_server_credentials, wrapper); Data_Get_Struct(self, grpc_rb_server_credentials, wrapper);
if (pem_cert_chain == Qnil) { if (pem_cert_chain == Qnil) {
rb_raise(rb_eRuntimeError, rb_raise(rb_eRuntimeError,
@ -157,15 +159,13 @@ static VALUE grpc_rb_server_credentials_init(VALUE self, VALUE pem_root_certs,
"could not create a server credential: nil pem_private_key"); "could not create a server credential: nil pem_private_key");
return Qnil; return Qnil;
} }
key_cert_pair.private_key = RSTRING_PTR(pem_private_key);
key_cert_pair.cert_chain = RSTRING_PTR(pem_cert_chain);
if (pem_root_certs == Qnil) { if (pem_root_certs == Qnil) {
creds = grpc_ssl_server_credentials_create( creds = grpc_ssl_server_credentials_create(NULL, &key_cert_pair, 1);
NULL, 0, RSTRING_PTR(pem_private_key), RSTRING_LEN(pem_private_key),
RSTRING_PTR(pem_cert_chain), RSTRING_LEN(pem_cert_chain));
} else { } else {
creds = grpc_ssl_server_credentials_create( creds = grpc_ssl_server_credentials_create(RSTRING_PTR(pem_root_certs),
RSTRING_PTR(pem_root_certs), RSTRING_LEN(pem_root_certs), &key_cert_pair, 1);
RSTRING_PTR(pem_private_key), RSTRING_LEN(pem_private_key),
RSTRING_PTR(pem_cert_chain), RSTRING_LEN(pem_cert_chain));
} }
if (creds == NULL) { if (creds == NULL) {
rb_raise(rb_eRuntimeError, "could not create a credentials, not sure why"); rb_raise(rb_eRuntimeError, "could not create a credentials, not sure why");

Loading…
Cancel
Save