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

View File

@ -110,7 +110,7 @@ class Connection : ObjectWrap {
#endif
#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::String> servername_;
#endif
@ -185,7 +185,7 @@ class Connection : ObjectWrap {
#endif
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
if (!sniCallback_.IsEmpty()) sniCallback_.Dispose();
if (!sniObject_.IsEmpty()) sniObject_.Dispose();
if (!sniContext_.IsEmpty()) sniContext_.Dispose();
if (!servername_.IsEmpty()) servername_.Dispose();
#endif