Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: runtime/bin/secure_socket.cc

Issue 15772005: - Add different types for persistent and weak persistent handles (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "bin/secure_socket.h" 5 #include "bin/secure_socket.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 start_validity_date, 265 start_validity_date,
266 end_validity_date }; 266 end_validity_date };
267 return Dart_New(x509_class, Dart_Null(), 4, arguments); 267 return Dart_New(x509_class, Dart_Null(), 4, arguments);
268 } 268 }
269 269
270 270
271 void SSLFilter::Init(Dart_Handle dart_this) { 271 void SSLFilter::Init(Dart_Handle dart_this) {
272 if (!library_initialized_) { 272 if (!library_initialized_) {
273 InitializeLibrary(NULL, "", true, false); 273 InitializeLibrary(NULL, "", true, false);
274 } 274 }
275 string_start_ = ThrowIfError( 275 string_start_ = Dart_NewPersistentHandle(DartUtils::NewString("start"));
276 Dart_NewPersistentHandle(DartUtils::NewString("start"))); 276 ASSERT(string_start_ != NULL);
277 string_length_ = ThrowIfError( 277 string_length_ = Dart_NewPersistentHandle(DartUtils::NewString("length"));
278 Dart_NewPersistentHandle(DartUtils::NewString("length"))); 278 ASSERT(string_length_ != NULL);
279 279
280 InitializeBuffers(dart_this); 280 InitializeBuffers(dart_this);
281 filter_ = memio_CreateIOLayer(kMemioBufferSize); 281 filter_ = memio_CreateIOLayer(kMemioBufferSize);
282 } 282 }
283 283
284 284
285 void SSLFilter::InitializeBuffers(Dart_Handle dart_this) { 285 void SSLFilter::InitializeBuffers(Dart_Handle dart_this) {
286 // Create SSLFilter buffers as ExternalUint8Array objects. 286 // Create SSLFilter buffers as ExternalUint8Array objects.
287 Dart_Handle dart_buffers_object = ThrowIfError( 287 Dart_Handle dart_buffers_object = ThrowIfError(
288 Dart_GetField(dart_this, DartUtils::NewString("buffers"))); 288 Dart_GetField(dart_this, DartUtils::NewString("buffers")));
(...skipping 17 matching lines...) Expand all
306 Dart_ThrowException(DartUtils::NewString( 306 Dart_ThrowException(DartUtils::NewString(
307 "Invalid encrypted buffer size in _ExternalBuffer")); 307 "Invalid encrypted buffer size in _ExternalBuffer"));
308 } 308 }
309 buffer_size_ = static_cast<int>(buffer_size); 309 buffer_size_ = static_cast<int>(buffer_size);
310 encrypted_buffer_size_ = static_cast<int>(encrypted_buffer_size); 310 encrypted_buffer_size_ = static_cast<int>(encrypted_buffer_size);
311 311
312 312
313 Dart_Handle data_identifier = DartUtils::NewString("data"); 313 Dart_Handle data_identifier = DartUtils::NewString("data");
314 for (int i = 0; i < kNumBuffers; ++i) { 314 for (int i = 0; i < kNumBuffers; ++i) {
315 int size = isEncrypted(i) ? encrypted_buffer_size_ : buffer_size_; 315 int size = isEncrypted(i) ? encrypted_buffer_size_ : buffer_size_;
316 dart_buffer_objects_[i] = ThrowIfError( 316 dart_buffer_objects_[i] =
317 Dart_NewPersistentHandle(Dart_ListGetAt(dart_buffers_object, i))); 317 Dart_NewPersistentHandle(Dart_ListGetAt(dart_buffers_object, i));
318 ASSERT(dart_buffer_objects_[i] != NULL);
318 buffers_[i] = new uint8_t[size]; 319 buffers_[i] = new uint8_t[size];
319 Dart_Handle data = ThrowIfError( 320 Dart_Handle data = ThrowIfError(
320 Dart_NewExternalTypedData(kUint8, buffers_[i], size, NULL, NULL)); 321 Dart_NewExternalTypedData(kUint8, buffers_[i], size));
321 ThrowIfError(Dart_SetField(dart_buffer_objects_[i], 322 ThrowIfError(Dart_SetField(Dart_NewHandleFromPersistent(dart_buffer_objects_ [i]),
322 data_identifier, 323 data_identifier,
323 data)); 324 data));
324 } 325 }
325 } 326 }
326 327
327 328
328 void SSLFilter::RegisterHandshakeCompleteCallback(Dart_Handle complete) { 329 void SSLFilter::RegisterHandshakeCompleteCallback(Dart_Handle complete) {
329 ASSERT(NULL == handshake_complete_); 330 ASSERT(NULL == handshake_complete_);
330 handshake_complete_ = ThrowIfError(Dart_NewPersistentHandle(complete)); 331 handshake_complete_ = Dart_NewPersistentHandle(complete);
332 ASSERT(handshake_complete_ != NULL);
331 } 333 }
332 334
333 335
334 void SSLFilter::RegisterBadCertificateCallback(Dart_Handle callback) { 336 void SSLFilter::RegisterBadCertificateCallback(Dart_Handle callback) {
335 if (NULL != bad_certificate_callback_) { 337 if (NULL != bad_certificate_callback_) {
336 Dart_DeletePersistentHandle(bad_certificate_callback_); 338 Dart_DeletePersistentHandle(bad_certificate_callback_);
337 } 339 }
338 bad_certificate_callback_ = ThrowIfError(Dart_NewPersistentHandle(callback)); 340 bad_certificate_callback_ = Dart_NewPersistentHandle(callback);
341 ASSERT(bad_certificate_callback_ != NULL);
339 } 342 }
340 343
341 static const char* builtin_roots_module = 344 static const char* builtin_roots_module =
342 #if defined(TARGET_OS_LINUX) || defined(TARGET_OS_ANDROID) 345 #if defined(TARGET_OS_LINUX) || defined(TARGET_OS_ANDROID)
343 "name=\"Root Certs\" library=\"libnssckbi.so\""; 346 "name=\"Root Certs\" library=\"libnssckbi.so\"";
344 #elif defined(TARGET_OS_MACOS) 347 #elif defined(TARGET_OS_MACOS)
345 "name=\"Root Certs\" library=\"libnssckbi.dylib\""; 348 "name=\"Root Certs\" library=\"libnssckbi.dylib\"";
346 #elif defined(TARGET_OS_WINDOWS) 349 #elif defined(TARGET_OS_WINDOWS)
347 "name=\"Root Certs\" library=\"nssckbi.dll\""; 350 "name=\"Root Certs\" library=\"nssckbi.dll\"";
348 #else 351 #else
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 578
576 memio_SetPeerName(filter_, &host_address); 579 memio_SetPeerName(filter_, &host_address);
577 PR_FreeAddrInfo(info); 580 PR_FreeAddrInfo(info);
578 } 581 }
579 582
580 583
581 void SSLFilter::Handshake() { 584 void SSLFilter::Handshake() {
582 SECStatus status = SSL_ForceHandshake(filter_); 585 SECStatus status = SSL_ForceHandshake(filter_);
583 if (status == SECSuccess) { 586 if (status == SECSuccess) {
584 if (in_handshake_) { 587 if (in_handshake_) {
585 ThrowIfError(Dart_InvokeClosure(handshake_complete_, 0, NULL)); 588 ThrowIfError(Dart_InvokeClosure(Dart_NewHandleFromPersistent(handshake_com plete_), 0, NULL));
586 in_handshake_ = false; 589 in_handshake_ = false;
587 } 590 }
588 } else { 591 } else {
589 PRErrorCode error = PR_GetError(); 592 PRErrorCode error = PR_GetError();
590 if (error == PR_WOULD_BLOCK_ERROR) { 593 if (error == PR_WOULD_BLOCK_ERROR) {
591 if (!in_handshake_) { 594 if (!in_handshake_) {
592 in_handshake_ = true; 595 in_handshake_ = true;
593 } 596 }
594 } else { 597 } else {
595 if (is_server_) { 598 if (is_server_) {
(...skipping 18 matching lines...) Expand all
614 Dart_DeletePersistentHandle(bad_certificate_callback_); 617 Dart_DeletePersistentHandle(bad_certificate_callback_);
615 } 618 }
616 free(client_certificate_name_); 619 free(client_certificate_name_);
617 620
618 PR_Close(filter_); 621 PR_Close(filter_);
619 } 622 }
620 623
621 624
622 intptr_t SSLFilter::ProcessBuffer(int buffer_index) { 625 intptr_t SSLFilter::ProcessBuffer(int buffer_index) {
623 int size = isEncrypted(buffer_index) ? encrypted_buffer_size_ : buffer_size_; 626 int size = isEncrypted(buffer_index) ? encrypted_buffer_size_ : buffer_size_;
624 Dart_Handle buffer_object = dart_buffer_objects_[buffer_index]; 627 Dart_Handle buffer_object = Dart_NewHandleFromPersistent(dart_buffer_objects_[ buffer_index]);
625 Dart_Handle start_object = ThrowIfError( 628 Dart_Handle start_object = ThrowIfError(
626 Dart_GetField(buffer_object, string_start_)); 629 Dart_GetField(buffer_object, Dart_NewHandleFromPersistent(string_start_))) ;
627 Dart_Handle length_object = ThrowIfError( 630 Dart_Handle length_object = ThrowIfError(
628 Dart_GetField(buffer_object, string_length_)); 631 Dart_GetField(buffer_object, Dart_NewHandleFromPersistent(string_length_)) );
629 int64_t unsafe_start = DartUtils::GetIntegerValue(start_object); 632 int64_t unsafe_start = DartUtils::GetIntegerValue(start_object);
630 int64_t unsafe_length = DartUtils::GetIntegerValue(length_object); 633 int64_t unsafe_length = DartUtils::GetIntegerValue(length_object);
631 ASSERT(unsafe_start >= 0); 634 ASSERT(unsafe_start >= 0);
632 ASSERT(unsafe_start < size); 635 ASSERT(unsafe_start < size);
633 ASSERT(unsafe_length >= 0); 636 ASSERT(unsafe_length >= 0);
634 ASSERT(unsafe_length <= size); 637 ASSERT(unsafe_length <= size);
635 int start = static_cast<int>(unsafe_start); 638 int start = static_cast<int>(unsafe_start);
636 int length = static_cast<int>(unsafe_length); 639 int length = static_cast<int>(unsafe_length);
637 uint8_t* buffer = buffers_[buffer_index]; 640 uint8_t* buffer = buffers_[buffer_index];
638 641
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 bytes_processed = 0; 717 bytes_processed = 0;
715 } 718 }
716 break; 719 break;
717 } 720 }
718 } 721 }
719 return bytes_processed; 722 return bytes_processed;
720 } 723 }
721 724
722 } // namespace bin 725 } // namespace bin
723 } // namespace dart 726 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698