Chromium Code Reviews| Index: runtime/bin/tls_socket.h |
| diff --git a/runtime/bin/tls_socket.h b/runtime/bin/tls_socket.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..840b4a516a670fbfd549f3a6860c703ae1feac87 |
| --- /dev/null |
| +++ b/runtime/bin/tls_socket.h |
| @@ -0,0 +1,72 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +#ifndef BIN_TLS_SOCKET_H_ |
| +#define BIN_TLS_SOCKET_H_ |
| + |
| +#include <stdlib.h> |
| +#include <string.h> |
| +#include <stdio.h> |
| +#include <sys/types.h> |
| + |
| +#include <prinit.h> |
| +#include <prerror.h> |
| +#include <prnetdb.h> |
| + |
| +#include "bin/builtin.h" |
| +#include "bin/dartutils.h" |
| +#include "platform/globals.h" |
| +#include "platform/thread.h" |
| + |
| +/* Handle an error reported from the NSS library. */ |
| +static void ReportError(const char* message, int error_code) { |
| + // TODO(whesse): Throw SocketIOException here. The error_code can go in its |
| + // OSError's errorCode field. |
| + printf("Secure Socket error: %s Error code %d\n", message, error_code); |
| +} |
| + |
| +class TlsFilter { |
|
Mads Ager (google)
2012/11/12 11:39:08
Some overall comment on the filter would be nice a
Bill Hesse
2012/11/13 20:11:08
Done.
|
| + public: |
| + enum BufferIndex { kReadPlaintext, |
|
Mads Ager (google)
2012/11/12 11:39:08
We normally format enums like this:
enum BufferIn
Bill Hesse
2012/11/13 20:11:08
Done.
|
| + kWritePlaintext, |
| + kReadEncrypted, |
| + kWriteEncrypted, |
| + kNumBuffers}; |
| + |
| + TlsFilter() : in_handshake_(false) { } |
| + |
| + void Init(Dart_Handle dart_this); |
| + void Connect(const char* host); |
| + void Destroy(); |
| + void DestroyPlatformIndependent(); |
| + void Handshake(); |
| + void RegisterHandshakeCallbacks(Dart_Handle start, Dart_Handle finish); |
| + static void InitializeLibrary(const char* pkcert_directory); |
| + |
| + intptr_t ProcessBuffer(int bufferIndex); |
| + |
| + private: |
| + static const int kMemioBufferSize = 20 * KB; |
| + static bool library_initialized_; // Should be mutex protected. |
| + |
| + uint8_t* buffers_[kNumBuffers]; |
| + int64_t buffer_size_; |
| + Dart_Handle stringStart_; |
|
Mads Ager (google)
2012/11/12 11:39:08
Please use C++ naming convention for these.
Bill Hesse
2012/11/13 20:11:08
Done.
|
| + Dart_Handle stringLength_; |
| + Dart_Handle dart_buffer_objects_[kNumBuffers]; |
| + Dart_Handle handshake_start_; |
| + Dart_Handle handshake_finish_; |
| + bool in_handshake_; |
| + PRFileDesc* memio_; |
| + |
| + void InitializeBuffers(Dart_Handle dart_this); |
| + void InitializePlatformData(); |
| + // TODO(whesse): Implement thread-safety of NSS library initialization. |
|
Mads Ager (google)
2012/11/12 11:39:08
This seems like an important TODO and it should be
Bill Hesse
2012/11/13 20:11:08
Done.
|
| + static void LockInitMutex() {} |
| + static void UnlockInitMutex() {} |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TlsFilter); |
| +}; |
| + |
| +#endif // BIN_TLS_SOCKET_H_ |