Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #include "bin/tls_socket.h" | |
| 6 | |
| 7 #include "bin/builtin.h" | |
| 8 #include "bin/dartutils.h" | |
| 9 #include "bin/thread.h" | |
| 10 #include "bin/utils.h" | |
| 11 | |
| 12 #include "include/dart_api.h" | |
| 13 | |
| 14 bool TlsFilter::library_initialized_ = false; | |
| 15 const char* TlsFilter::bufferNames[kNumBuffers] = { "readPlaintext", | |
| 16 "writePlaintext", | |
| 17 "readEncrypted", | |
| 18 "writeEncrypted" }; | |
| 19 | |
| 20 void FUNCTION_NAME(TlsSocket_Init)(Dart_NativeArguments args) { | |
| 21 Dart_EnterScope(); | |
| 22 TlsFilter* local_data = new TlsFilter; | |
| 23 Dart_Handle dart_this = HandleError(Dart_GetNativeArgument(args, 0)); | |
|
Mads Ager (google)
2012/07/31 10:16:01
I would prefer to just handle the error explicitly
Bill Hesse
2012/08/08 17:00:05
Done.
| |
| 24 local_data->Init(dart_this); | |
| 25 | |
| 26 Dart_SetReturnValue(args, Dart_Null()); | |
| 27 Dart_ExitScope(); | |
| 28 } | |
| 29 | |
|
Søren Gjesse
2012/07/31 09:07:15
Two empty lines functions.
Bill Hesse
2012/08/08 17:00:05
Done.
| |
| 30 void FUNCTION_NAME(TlsSocket_Connect)(Dart_NativeArguments args) { | |
| 31 Dart_EnterScope(); | |
| 32 TlsFilter* local_data; | |
| 33 | |
| 34 Dart_Handle dart_this = HandleError(Dart_GetNativeArgument(args, 0)); | |
| 35 ASSERT(Dart_IsInstance(dart_this)); | |
| 36 int count; | |
| 37 HandleError(Dart_GetNativeInstanceFieldCount(dart_this, &count)); | |
| 38 ASSERT(count == 1); | |
| 39 HandleError(Dart_GetNativeInstanceField(dart_this, 0, | |
| 40 reinterpret_cast<intptr_t*>(&local_data))); | |
| 41 | |
| 42 local_data->Connect(); | |
| 43 Dart_SetReturnValue(args, Dart_Null()); | |
| 44 Dart_ExitScope(); | |
| 45 } | |
| 46 | |
| 47 void FUNCTION_NAME(TlsSocket_Destroy)(Dart_NativeArguments args) { | |
| 48 Dart_EnterScope(); | |
| 49 TlsFilter* local_data; | |
| 50 | |
| 51 Dart_Handle dart_this = HandleError(Dart_GetNativeArgument(args, 0)); | |
| 52 ASSERT(Dart_IsInstance(dart_this)); | |
| 53 int count; | |
| 54 HandleError(Dart_GetNativeInstanceFieldCount(dart_this, &count)); | |
| 55 ASSERT(count == 1); | |
| 56 HandleError(Dart_GetNativeInstanceField(dart_this, 0, | |
| 57 reinterpret_cast<intptr_t*>(&local_data))); | |
| 58 | |
| 59 local_data->Destroy(); | |
| 60 Dart_SetReturnValue(args, Dart_Null()); | |
| 61 Dart_ExitScope(); | |
| 62 } | |
| 63 | |
| 64 void FUNCTION_NAME(TlsSocket_RegisterHandshakeCallbacks)( | |
| 65 Dart_NativeArguments args) { | |
| 66 Dart_EnterScope(); | |
| 67 TlsFilter* local_data; | |
| 68 | |
| 69 Dart_Handle dart_this = HandleError(Dart_GetNativeArgument(args, 0)); | |
| 70 Dart_Handle handshake_start = HandleError(Dart_GetNativeArgument(args, 1)); | |
| 71 Dart_Handle handshake_finish = HandleError(Dart_GetNativeArgument(args, 2)); | |
| 72 if (!Dart_IsInstance(dart_this) || | |
| 73 !Dart_IsClosure(handshake_start) || | |
| 74 !Dart_IsClosure(handshake_finish)) { | |
| 75 Dart_ThrowException(DartUtils::NewDartIllegalArgumentError( | |
| 76 "Illegal argument to RegisterHandshakeCallbacks")); | |
| 77 } | |
| 78 HandleError(Dart_GetNativeInstanceField(dart_this, 0, | |
| 79 reinterpret_cast<intptr_t*>(&local_data))); | |
| 80 | |
| 81 local_data->RegisterHandshakeCallbacks(handshake_start, handshake_finish); | |
| 82 Dart_SetReturnValue(args, Dart_Null()); | |
| 83 Dart_ExitScope(); | |
| 84 } | |
| 85 | |
| 86 void FUNCTION_NAME(TlsSocket_ProcessBuffer)(Dart_NativeArguments args) { | |
| 87 Dart_EnterScope(); | |
| 88 TlsFilter* local_data; | |
| 89 | |
| 90 Dart_Handle dart_this = HandleError(Dart_GetNativeArgument(args, 0)); | |
| 91 ASSERT(Dart_IsInstance(dart_this)); | |
| 92 HandleError(Dart_GetNativeInstanceField(dart_this, 0, | |
| 93 reinterpret_cast<intptr_t*>(&local_data))); | |
| 94 Dart_Handle buffer_id_object = HandleError(Dart_GetNativeArgument(args, 1)); | |
| 95 int64_t buffer_id = DartUtils::GetIntegerValue(buffer_id_object); | |
| 96 if (buffer_id < 0 || buffer_id >= TlsFilter::kNumBuffers) { | |
| 97 Dart_ThrowException(DartUtils::NewDartIllegalArgumentError( | |
| 98 "Illegal argument to ProcessBuffer")); | |
| 99 } | |
| 100 | |
| 101 intptr_t bytes_read = local_data->ProcessBuffer(static_cast<int>(buffer_id)); | |
| 102 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); | |
| 103 Dart_ExitScope(); | |
| 104 } | |
| 105 | |
| 106 void TlsFilter::Init(Dart_Handle dart_this) { | |
| 107 printf("Entering Init\n"); | |
| 108 ASSERT(Dart_IsInstance(dart_this)); | |
| 109 peer_ = HandleError(Dart_NewPersistentHandle(dart_this)); | |
| 110 int count; | |
| 111 HandleError(Dart_GetNativeInstanceFieldCount(dart_this, &count)); | |
| 112 ASSERT(count == 1); | |
| 113 HandleError(Dart_SetNativeInstanceField(dart_this, 0, | |
| 114 reinterpret_cast<intptr_t>(this))); | |
| 115 stringStart = HandleError( | |
| 116 Dart_NewPersistentHandle(Dart_NewString("start"))); | |
| 117 stringLength = HandleError( | |
| 118 Dart_NewPersistentHandle(Dart_NewString("length"))); | |
| 119 | |
| 120 InitializeBuffers(); | |
| 121 InitializePlatformData(); | |
| 122 printf("Exiting Init\n"); | |
|
Mads Ager (google)
2012/07/31 10:16:01
Please remove.
Bill Hesse
2012/08/08 17:00:05
Done.
| |
| 123 } | |
| 124 | |
| 125 void TlsFilter::InitializeBuffers() { | |
| 126 // Create TlsFilter buffers as ExternalUint8Array objects. | |
| 127 Dart_Handle dart_buffers_object = HandleError( | |
| 128 Dart_GetField(peer_, Dart_NewString("buffers"))); | |
| 129 Dart_Handle dart_buffer_object = HandleError( | |
| 130 Dart_ListGetAt(dart_buffers_object, kReadPlaintext)); | |
| 131 Dart_Handle tlsExternalBuffer_class = HandleError( | |
| 132 Dart_InstanceGetClass(dart_buffer_object)); | |
| 133 Dart_Handle dart_buffer_size = HandleError( | |
| 134 Dart_GetField(tlsExternalBuffer_class, Dart_NewString("kSize"))); | |
| 135 buffer_size = DartUtils::GetIntegerValue(dart_buffer_size); | |
| 136 if (buffer_size <= 0 || buffer_size > 1024 * 1024) { | |
| 137 Dart_ThrowException( | |
| 138 Dart_NewString("Invalid buffer size in _TlsExternalBuffer")); | |
| 139 } | |
| 140 | |
| 141 for (int i = 0; i < kNumBuffers; ++i) { | |
| 142 dart_buffer_objects[i] = HandleError( | |
| 143 Dart_NewPersistentHandle(Dart_ListGetAt(dart_buffers_object, i))); | |
| 144 buffers[i] = new uint8_t[buffer_size]; | |
| 145 Dart_Handle data = HandleError( | |
| 146 Dart_NewExternalByteArray(buffers[i], | |
| 147 buffer_size, NULL, NULL)); | |
| 148 HandleError( | |
| 149 Dart_SetField(dart_buffer_objects[i], Dart_NewString("data"), data)); | |
| 150 } | |
| 151 } | |
| 152 | |
| 153 void TlsFilter::RegisterHandshakeCallbacks(Dart_Handle start, | |
| 154 Dart_Handle finish) { | |
| 155 handshake_start = HandleError(Dart_NewPersistentHandle(start)); | |
| 156 handshake_finish = HandleError(Dart_NewPersistentHandle(finish)); | |
| 157 } | |
| OLD | NEW |