diff options
author | Fedor Indutny <fedor@indutny.com> | 2014-09-12 13:27:22 +0100 |
---|---|---|
committer | Fedor Indutny <fedor@indutny.com> | 2014-09-23 13:54:03 +0400 |
commit | 6e08bb94e8b1aaf913cf88106cb59f9d2ae85925 (patch) | |
tree | e94b9f1327fd86836ba3da6f2743c463122e1e78 | |
parent | 64d6de9f34abe63bf7602ab0b55ff268cf480e45 (diff) | |
download | nodejs-6e08bb94e8b1aaf913cf88106cb59f9d2ae85925.tar.gz nodejs-6e08bb94e8b1aaf913cf88106cb59f9d2ae85925.tar.bz2 nodejs-6e08bb94e8b1aaf913cf88106cb59f9d2ae85925.zip |
crypto: export externals to internal structs
Export External getters for a internal structs: SSL, SSL_CTX.
-rw-r--r-- | src/node_crypto.cc | 32 | ||||
-rw-r--r-- | src/node_crypto.h | 4 | ||||
-rw-r--r-- | src/node_internals.h | 15 |
3 files changed, 51 insertions, 0 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 5d8a9f5de..44ed4e09a 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -81,6 +81,7 @@ using v8::Boolean; using v8::Context; using v8::EscapableHandleScope; using v8::Exception; +using v8::External; using v8::False; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; @@ -286,6 +287,11 @@ void SecureContext::Initialize(Environment* env, Handle<Object> target) { "getIssuer", SecureContext::GetCertificate<false>); + NODE_SET_EXTERNAL( + t->PrototypeTemplate(), + "_external", + CtxGetter); + target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext"), t->GetFunction()); env->set_secure_context_constructor_template(t); @@ -956,6 +962,16 @@ void SecureContext::SetTicketKeys(const FunctionCallbackInfo<Value>& args) { } +void SecureContext::CtxGetter(Local<String> property, + const PropertyCallbackInfo<Value>& info) { + HandleScope scope(info.GetIsolate()); + + SSL_CTX* ctx = Unwrap<SecureContext>(info.Holder())->ctx_; + Local<External> ext = External::New(info.GetIsolate(), ctx); + info.GetReturnValue().Set(ext); +} + + template <bool primary> void SecureContext::GetCertificate(const FunctionCallbackInfo<Value>& args) { HandleScope scope(args.GetIsolate()); @@ -1008,6 +1024,11 @@ void SSLWrap<Base>::AddMethods(Environment* env, Handle<FunctionTemplate> t) { NODE_SET_PROTOTYPE_METHOD(t, "getNegotiatedProtocol", GetNegotiatedProto); NODE_SET_PROTOTYPE_METHOD(t, "setNPNProtocols", SetNPNProtocols); #endif // OPENSSL_NPN_NEGOTIATED + + NODE_SET_EXTERNAL( + t->PrototypeTemplate(), + "_external", + SSLGetter); } @@ -1846,6 +1867,17 @@ int SSLWrap<Base>::TLSExtStatusCallback(SSL* s, void* arg) { #endif // NODE__HAVE_TLSEXT_STATUS_CB +template <class Base> +void SSLWrap<Base>::SSLGetter(Local<String> property, + const PropertyCallbackInfo<Value>& info) { + HandleScope scope(info.GetIsolate()); + + SSL* ssl = Unwrap<Base>(info.Holder())->ssl_; + Local<External> ext = External::New(info.GetIsolate(), ssl); + info.GetReturnValue().Set(ext); +} + + void Connection::OnClientHelloParseEnd(void* arg) { Connection* conn = static_cast<Connection*>(arg); diff --git a/src/node_crypto.h b/src/node_crypto.h index 3c46e0c11..1a719b905 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -105,6 +105,8 @@ class SecureContext : public BaseObject { static void LoadPKCS12(const v8::FunctionCallbackInfo<v8::Value>& args); static void GetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args); static void SetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args); + static void CtxGetter(v8::Local<v8::String> property, + const v8::PropertyCallbackInfo<v8::Value>& info); template <bool primary> static void GetCertificate(const v8::FunctionCallbackInfo<v8::Value>& args); @@ -237,6 +239,8 @@ class SSLWrap { void* arg); #endif // OPENSSL_NPN_NEGOTIATED static int TLSExtStatusCallback(SSL* s, void* arg); + static void SSLGetter(v8::Local<v8::String> property, + const v8::PropertyCallbackInfo<v8::Value>& info); inline Environment* ssl_env() const { return env_; diff --git a/src/node_internals.h b/src/node_internals.h index d38a3f019..253bd38d9 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -216,6 +216,21 @@ NODE_DEPRECATED("Use ThrowUVException(isolate)", return ThrowUVException(isolate, errorno, syscall, message, path); }) +inline void NODE_SET_EXTERNAL(v8::Handle<v8::ObjectTemplate> target, + const char* key, + v8::AccessorGetterCallback getter) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::HandleScope handle_scope(isolate); + v8::Local<v8::String> prop = v8::String::NewFromUtf8(isolate, key); + target->SetAccessor(prop, + getter, + NULL, + v8::Handle<v8::Value>(), + v8::DEFAULT, + static_cast<v8::PropertyAttribute>(v8::ReadOnly | + v8::DontDelete)); +} + } // namespace node #endif // SRC_NODE_INTERNALS_H_ |