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

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

Issue 10704159: Start adding TLS (SSL) sockets to dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Stub out win32 and macos platforms. Created 8 years, 4 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
(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
16
17 void FUNCTION_NAME(TlsSocket_Init)(Dart_NativeArguments args) {
18 Dart_EnterScope();
19 TlsFilter* local_data = new TlsFilter;
20 Dart_Handle dart_this = Dart_GetNativeArgument(args, 0);
21 if (Dart_IsError(dart_this)) {
22 delete local_data;
23 Dart_PropagateError(dart_this);
24 }
25 local_data->Init(dart_this);
26
27 Dart_SetReturnValue(args, Dart_Null());
28 Dart_ExitScope();
29 }
30
31
32 void FUNCTION_NAME(TlsSocket_Connect)(Dart_NativeArguments args) {
33 Dart_EnterScope();
34 TlsFilter* local_data;
35
36 Dart_Handle dart_this = HandleError(Dart_GetNativeArgument(args, 0));
Søren Gjesse 2012/08/09 10:22:52 Maybe add a function fir getting the local_data na
Bill Hesse 2012/08/13 11:20:03 Done.
37 ASSERT(Dart_IsInstance(dart_this));
38 int count;
39 HandleError(Dart_GetNativeInstanceFieldCount(dart_this, &count));
40 ASSERT(count == 1);
41 HandleError(Dart_GetNativeInstanceField(dart_this, 0,
42 reinterpret_cast<intptr_t*>(&local_data)));
43
44 local_data->Connect();
45 Dart_SetReturnValue(args, Dart_Null());
46 Dart_ExitScope();
47 }
48
49
50 void FUNCTION_NAME(TlsSocket_Destroy)(Dart_NativeArguments args) {
51 Dart_EnterScope();
52 TlsFilter* local_data;
53
54 Dart_Handle dart_this = HandleError(Dart_GetNativeArgument(args, 0));
55 ASSERT(Dart_IsInstance(dart_this));
56 int count;
57 HandleError(Dart_GetNativeInstanceFieldCount(dart_this, &count));
58 ASSERT(count == 1);
59 HandleError(Dart_GetNativeInstanceField(dart_this, 0,
60 reinterpret_cast<intptr_t*>(&local_data)));
61 HandleError(Dart_SetNativeInstanceField(dart_this, 0, NULL));
62
63 local_data->Destroy();
64 delete local_data;
65 Dart_SetReturnValue(args, Dart_Null());
66 Dart_ExitScope();
67 }
68
69
70 void FUNCTION_NAME(TlsSocket_RegisterHandshakeCallbacks)(
71 Dart_NativeArguments args) {
72 Dart_EnterScope();
73 TlsFilter* local_data;
74
75 Dart_Handle dart_this = HandleError(Dart_GetNativeArgument(args, 0));
76 Dart_Handle handshake_start = HandleError(Dart_GetNativeArgument(args, 1));
77 Dart_Handle handshake_finish = HandleError(Dart_GetNativeArgument(args, 2));
78 if (!Dart_IsInstance(dart_this) ||
79 !Dart_IsClosure(handshake_start) ||
80 !Dart_IsClosure(handshake_finish)) {
81 Dart_ThrowException(DartUtils::NewDartIllegalArgumentException(
82 "Illegal argument to RegisterHandshakeCallbacks"));
83 }
84 HandleError(Dart_GetNativeInstanceField(dart_this, 0,
85 reinterpret_cast<intptr_t*>(&local_data)));
86
87 local_data->RegisterHandshakeCallbacks(handshake_start, handshake_finish);
88 Dart_SetReturnValue(args, Dart_Null());
89 Dart_ExitScope();
90 }
91
92
93 void FUNCTION_NAME(TlsSocket_ProcessBuffer)(Dart_NativeArguments args) {
94 Dart_EnterScope();
95 TlsFilter* local_data;
96
97 Dart_Handle dart_this = HandleError(Dart_GetNativeArgument(args, 0));
98 ASSERT(Dart_IsInstance(dart_this));
99 HandleError(Dart_GetNativeInstanceField(dart_this, 0,
100 reinterpret_cast<intptr_t*>(&local_data)));
101 Dart_Handle buffer_id_object = HandleError(Dart_GetNativeArgument(args, 1));
102 int64_t buffer_id = DartUtils::GetIntegerValue(buffer_id_object);
103 if (buffer_id < 0 || buffer_id >= TlsFilter::kNumBuffers) {
104 Dart_ThrowException(DartUtils::NewDartIllegalArgumentException(
105 "Illegal argument to ProcessBuffer"));
106 }
107
108 intptr_t bytes_read = local_data->ProcessBuffer(static_cast<int>(buffer_id));
109 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read));
110 Dart_ExitScope();
111 }
112
113
114 void TlsFilter::Init(Dart_Handle dart_this) {
115 ASSERT(Dart_IsInstance(dart_this));
116 int count;
117 HandleError(Dart_GetNativeInstanceFieldCount(dart_this, &count));
118 ASSERT(count == 1);
119 HandleError(Dart_SetNativeInstanceField(dart_this, 0,
120 reinterpret_cast<intptr_t>(this)));
121 stringStart_ = HandleError(
122 Dart_NewPersistentHandle(Dart_NewString("start")));
Søren Gjesse 2012/08/09 10:22:52 I don't see these persistent handles being deleted
Bill Hesse 2012/08/13 11:20:03 Fixed - they are now freed in destroy(). On 2012/
123 stringLength_ = HandleError(
124 Dart_NewPersistentHandle(Dart_NewString("length")));
125
126 InitializeBuffers(dart_this);
127 InitializePlatformData();
128 }
129
130
131 void TlsFilter::InitializeBuffers(Dart_Handle dart_this) {
132 // Create TlsFilter buffers as ExternalUint8Array objects.
133 Dart_Handle dart_buffers_object = HandleError(
134 Dart_GetField(dart_this, Dart_NewString("buffers")));
135 Dart_Handle dart_buffer_object = HandleError(
136 Dart_ListGetAt(dart_buffers_object, kReadPlaintext));
137 Dart_Handle tlsExternalBuffer_class = HandleError(
138 Dart_InstanceGetClass(dart_buffer_object));
139 Dart_Handle dart_buffer_size = HandleError(
140 Dart_GetField(tlsExternalBuffer_class, Dart_NewString("kSize")));
141 buffer_size_ = DartUtils::GetIntegerValue(dart_buffer_size);
142 if (buffer_size_ <= 0 || buffer_size_ > 1024 * 1024) {
143 Dart_ThrowException(
144 Dart_NewString("Invalid buffer size in _TlsExternalBuffer"));
145 }
146
147 for (int i = 0; i < kNumBuffers; ++i) {
148 dart_buffer_objects_[i] = HandleError(
149 Dart_NewPersistentHandle(Dart_ListGetAt(dart_buffers_object, i)));
Søren Gjesse 2012/08/09 10:22:52 I don't see these persistent handles being deleted
Bill Hesse 2012/08/13 11:20:03 Right. Fixed.
150 buffers_[i] = new uint8_t[buffer_size_];
151 Dart_Handle data = HandleError(
152 Dart_NewExternalByteArray(buffers_[i],
153 buffer_size_, NULL, NULL));
154 HandleError(
155 Dart_SetField(dart_buffer_objects_[i], Dart_NewString("data"), data));
156 }
157 }
158
159
160 void TlsFilter::RegisterHandshakeCallbacks(Dart_Handle start,
161 Dart_Handle finish) {
162 handshake_start_ = HandleError(Dart_NewPersistentHandle(start));
163 handshake_finish_ = HandleError(Dart_NewPersistentHandle(finish));
164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698