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 #ifndef BIN_TLS_SOCKET_H_ | |
| 6 #define BIN_TLS_SOCKET_H_ | |
| 7 | |
| 8 #include <stdlib.h> | |
| 9 #include <string.h> | |
| 10 #include <stdio.h> | |
| 11 #include <sys/types.h> | |
| 12 | |
| 13 #include <prinit.h> | |
| 14 #include <prerror.h> | |
| 15 #include <prnetdb.h> | |
| 16 | |
| 17 #include "bin/builtin.h" | |
| 18 #include "bin/dartutils.h" | |
| 19 #include "platform/globals.h" | |
| 20 #include "platform/thread.h" | |
| 21 | |
| 22 /* Handle an error reported from the NSS library. */ | |
| 23 static void ReportError(const char* message, int error_code) { | |
| 24 // TODO(whesse): Throw SocketIOException here. The error_code can go in its | |
| 25 // OSError's errorCode field. | |
| 26 printf("Secure Socket error: %s Error code %d\n", message, error_code); | |
| 27 } | |
| 28 | |
| 29 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.
| |
| 30 public: | |
| 31 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.
| |
| 32 kWritePlaintext, | |
| 33 kReadEncrypted, | |
| 34 kWriteEncrypted, | |
| 35 kNumBuffers}; | |
| 36 | |
| 37 TlsFilter() : in_handshake_(false) { } | |
| 38 | |
| 39 void Init(Dart_Handle dart_this); | |
| 40 void Connect(const char* host); | |
| 41 void Destroy(); | |
| 42 void DestroyPlatformIndependent(); | |
| 43 void Handshake(); | |
| 44 void RegisterHandshakeCallbacks(Dart_Handle start, Dart_Handle finish); | |
| 45 static void InitializeLibrary(const char* pkcert_directory); | |
| 46 | |
| 47 intptr_t ProcessBuffer(int bufferIndex); | |
| 48 | |
| 49 private: | |
| 50 static const int kMemioBufferSize = 20 * KB; | |
| 51 static bool library_initialized_; // Should be mutex protected. | |
| 52 | |
| 53 uint8_t* buffers_[kNumBuffers]; | |
| 54 int64_t buffer_size_; | |
| 55 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.
| |
| 56 Dart_Handle stringLength_; | |
| 57 Dart_Handle dart_buffer_objects_[kNumBuffers]; | |
| 58 Dart_Handle handshake_start_; | |
| 59 Dart_Handle handshake_finish_; | |
| 60 bool in_handshake_; | |
| 61 PRFileDesc* memio_; | |
| 62 | |
| 63 void InitializeBuffers(Dart_Handle dart_this); | |
| 64 void InitializePlatformData(); | |
| 65 // 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.
| |
| 66 static void LockInitMutex() {} | |
| 67 static void UnlockInitMutex() {} | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(TlsFilter); | |
| 70 }; | |
| 71 | |
| 72 #endif // BIN_TLS_SOCKET_H_ | |
| OLD | NEW |