You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2004--2005, Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef TALK_BASE_SCHANNELADAPTER_H__
  28. #define TALK_BASE_SCHANNELADAPTER_H__
  29. #include <string>
  30. #include "talk/base/ssladapter.h"
  31. #include "talk/base/messagequeue.h"
  32. struct _SecBufferDesc;
  33. namespace talk_base {
  34. ///////////////////////////////////////////////////////////////////////////////
  35. class SChannelAdapter : public SSLAdapter, public MessageHandler {
  36. public:
  37. SChannelAdapter(AsyncSocket* socket);
  38. virtual ~SChannelAdapter();
  39. virtual int StartSSL(const char* hostname, bool restartable);
  40. virtual int Send(const void* pv, size_t cb);
  41. virtual int Recv(void* pv, size_t cb);
  42. virtual int Close();
  43. // Note that the socket returns ST_CONNECTING while SSL is being negotiated.
  44. virtual ConnState GetState() const;
  45. protected:
  46. enum SSLState {
  47. SSL_NONE, SSL_WAIT, SSL_CONNECTING, SSL_CONNECTED, SSL_ERROR
  48. };
  49. struct SSLImpl;
  50. virtual void OnConnectEvent(AsyncSocket* socket);
  51. virtual void OnReadEvent(AsyncSocket* socket);
  52. virtual void OnWriteEvent(AsyncSocket* socket);
  53. virtual void OnCloseEvent(AsyncSocket* socket, int err);
  54. virtual void OnMessage(Message* pmsg);
  55. int BeginSSL();
  56. int ContinueSSL();
  57. int ProcessContext(long int status, _SecBufferDesc* sbd_in,
  58. _SecBufferDesc* sbd_out);
  59. int DecryptData();
  60. int Read();
  61. int Flush();
  62. void Error(const char* context, int err, bool signal = true);
  63. void Cleanup();
  64. void PostEvent();
  65. private:
  66. SSLState state_;
  67. std::string ssl_host_name_;
  68. // If true, socket will retain SSL configuration after Close.
  69. bool restartable_;
  70. // If true, we are delaying signalling close until all data is read.
  71. bool signal_close_;
  72. // If true, we are waiting to be woken up to signal readability or closure.
  73. bool message_pending_;
  74. SSLImpl* impl_;
  75. };
  76. /////////////////////////////////////////////////////////////////////////////
  77. } // namespace talk_base
  78. #endif // TALK_BASE_SCHANNELADAPTER_H__