crypto, tls: make setSNICallback() compatible with domains

This commit is contained in:
Ben Noordhuis 2012-09-03 23:26:19 +02:00
parent 7d0543c128
commit 7dfa587d18
2 changed files with 12 additions and 15 deletions

View File

@ -938,23 +938,20 @@ int Connection::SelectSNIContextCallback_(SSL *s, int *ad, void* arg) {
} }
p->servername_ = Persistent<String>::New(String::New(servername)); p->servername_ = Persistent<String>::New(String::New(servername));
// Call sniCallback_ and use it's return value as context // Call the SNI callback and use its return value as context
if (!p->sniCallback_.IsEmpty()) { if (!p->sniObject_.IsEmpty()) {
if (!p->sniContext_.IsEmpty()) { if (!p->sniContext_.IsEmpty()) {
p->sniContext_.Dispose(); p->sniContext_.Dispose();
} }
// Get callback init args // Get callback init args
Local<Value> argv[1] = {*p->servername_}; Local<Value> argv[1] = {*p->servername_};
Local<Function> callback = *p->sniCallback_;
// Call it // Call it
// Local<Value> ret = Local<Value>::New(MakeCallback(p->sniObject_,
// XXX There should be an object connected to this that "onselect",
// we can attach a domain onto. ARRAY_SIZE(argv),
Local<Value> ret; argv));
ret = Local<Value>::New(MakeCallback(Context::GetCurrent()->Global(),
callback, ARRAY_SIZE(argv), argv));
// If ret is SecureContext // If ret is SecureContext
if (secure_context_constructor->HasInstance(ret)) { if (secure_context_constructor->HasInstance(ret)) {
@ -1774,11 +1771,11 @@ Handle<Value> Connection::SetSNICallback(const Arguments& args) {
} }
// Release old handle // Release old handle
if (!ss->sniCallback_.IsEmpty()) { if (!ss->sniObject_.IsEmpty()) {
ss->sniCallback_.Dispose(); ss->sniObject_.Dispose();
} }
ss->sniCallback_ = Persistent<Function>::New( ss->sniObject_ = Persistent<Object>::New(Object::New());
Local<Function>::Cast(args[0])); ss->sniObject_->Set(String::New("onselect"), args[0]);
return True(); return True();
} }

View File

@ -110,7 +110,7 @@ class Connection : ObjectWrap {
#endif #endif
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB #ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
v8::Persistent<v8::Function> sniCallback_; v8::Persistent<v8::Object> sniObject_;
v8::Persistent<v8::Value> sniContext_; v8::Persistent<v8::Value> sniContext_;
v8::Persistent<v8::String> servername_; v8::Persistent<v8::String> servername_;
#endif #endif
@ -185,7 +185,7 @@ class Connection : ObjectWrap {
#endif #endif
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB #ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
if (!sniCallback_.IsEmpty()) sniCallback_.Dispose(); if (!sniObject_.IsEmpty()) sniObject_.Dispose();
if (!sniContext_.IsEmpty()) sniContext_.Dispose(); if (!sniContext_.IsEmpty()) sniContext_.Dispose();
if (!servername_.IsEmpty()) servername_.Dispose(); if (!servername_.IsEmpty()) servername_.Dispose();
#endif #endif