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': {
'libraries': [
'-lgrpc',
'-levent',
'-levent_pthreads',
'-levent_core',
'-lrt',
'-lgpr',
'-lpthread'

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

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

@ -68,7 +68,7 @@ $CFLAGS << ' -Wno-return-type '
$CFLAGS << ' -Wall '
$CFLAGS << ' -pedantic '
$LDFLAGS << ' -lgrpc -lgpr -levent -levent_pthreads -levent_core'
$LDFLAGS << ' -lgrpc -lgpr'
# 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;
grpc_rb_credentials *wrapper = NULL;
grpc_credentials *creds = NULL;
/* TODO: Remove mandatory arg when we support default roots. */
/* "12" == 1 mandatory arg, 2 (credentials) is optional */
rb_scan_args(argc, argv, "12", &pem_root_certs, &pem_private_key,
&pem_cert_chain);
@ -225,22 +226,12 @@ static VALUE grpc_rb_credentials_init(int argc, VALUE *argv, VALUE self) {
return Qnil;
}
if (pem_private_key == Qnil && pem_cert_chain == Qnil) {
creds = grpc_ssl_credentials_create(RSTRING_PTR(pem_root_certs),
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));
creds = grpc_ssl_credentials_create(RSTRING_PTR(pem_root_certs), NULL);
} 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(
RSTRING_PTR(pem_root_certs), RSTRING_LEN(pem_root_certs),
RSTRING_PTR(pem_private_key), RSTRING_LEN(pem_private_key), NULL, 0);
RSTRING_PTR(pem_root_certs), &key_cert_pair);
}
if (creds == NULL) {
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,
VALUE pem_private_key,
VALUE pem_cert_chain) {
/* TODO support multiple key cert pairs in the ruby API. */
grpc_rb_server_credentials *wrapper = 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);
if (pem_cert_chain == Qnil) {
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");
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) {
creds = grpc_ssl_server_credentials_create(
NULL, 0, RSTRING_PTR(pem_private_key), RSTRING_LEN(pem_private_key),
RSTRING_PTR(pem_cert_chain), RSTRING_LEN(pem_cert_chain));
creds = grpc_ssl_server_credentials_create(NULL, &key_cert_pair, 1);
} else {
creds = grpc_ssl_server_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));
creds = grpc_ssl_server_credentials_create(RSTRING_PTR(pem_root_certs),
&key_cert_pair, 1);
}
if (creds == NULL) {
rb_raise(rb_eRuntimeError, "could not create a credentials, not sure why");

Loading…
Cancel
Save