sipxportlib  Version 3.3
OsTLSConnectionSocket.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 
12 #ifndef _OsTLSConnectionSocket_h_
13 #define _OsTLSConnectionSocket_h_
14 
15 #ifdef SIP_TLS
16 #ifdef SIP_TLS_NSS
17 
18 // SYSTEM INCLUDES
19 #include <prio.h>
20 #include <nspr.h>
21 #include <seccomon.h>
22 #include <secmod.h>
23 #include <ssl.h>
24 
25 // APPLICATION INCLUDES
26 #include <os/OsConnectionSocket.h>
27 
28 #include <os/OsMutex.h>
29 
30 // DEFINES
31 // MACROS
32 // EXTERNAL FUNCTIONS
33 // EXTERNAL VARIABLES
34 // CONSTANTS
35 // STRUCTS
36 // TYPEDEFS
37 // FORWARD DECLARATIONS
38 
40 class OsTLSConnectionSocket : public OsConnectionSocket
41 {
42 /* //////////////////////////// PUBLIC //////////////////////////////////// */
43 public:
44 
45 /* ============================ CREATORS ================================== */
46 
47  OsTLSConnectionSocket(int remoteHostPort,
48  const char* remoteHostName,
49  const UtlString certNickname,
50  const UtlString password,
51  const UtlString dbLocation,
52  long timeoutInSecs,
53  const char* localIp
54  );
55 
56  OsTLSConnectionSocket(int socketDescriptor,
57  const UtlString certNickname,
58  const UtlString password,
59  const UtlString dbLocation,
60  long timeoutInSecs = 0);
61 
62  virtual
63  ~OsTLSConnectionSocket();
64  //:Destructor
65 
66 /* ============================ MANIPULATORS ============================== */
67 
68  virtual UtlBoolean reconnect();
69  //: Sets up the connection again, assuming the connection failed
70 
71  virtual int write(const char* buffer, int bufferLength);
72  //:Blocking write to the socket
73  // Write the characters in the given buffer to the socket.
74  // This method will block until all of the bytes are written.
80 
81  virtual int write(const char* buffer, int bufferLength, long waitMilliseconds);
82  //:Non-blocking or limited blocking write to socket
83  // Same as blocking version except that this write will block
84  // for no more than the specified length of time.
86 
87  virtual int read(char* buffer, int bufferLength);
88  //:Blocking read from the socket
89  // Read bytes into the buffer from the socket up to a maximum of
90  // bufferLength bytes. This method will block until there is
91  // something to read from the socket.
95 
96  virtual int read(char* buffer, int bufferLength,
97  UtlString* ipAddress, int* port);
98  //:Blocking read from the socket
99  // Read bytes into the buffer from the socket up to a maximum of
100  // bufferLength bytes. This method will block until there is
101  // something to read from the socket.
107 
108  virtual int read(char* buffer, int bufferLength, long waitMilliseconds);
109  //: Non-blocking or limited blocking read from socket
110  // Same as blocking version except that this read will block
111  // for no more than the specified length of time.
113 
114  virtual UtlBoolean isReadyToReadEx(long waitMilliseconds, UtlBoolean &rSocketError) const;
115  //:Poll if there are bytes to read
116  // Returns TRUE if socket is read to read.
117  // Returns FALSE if wait expires or socket error.
118  // rSocketError returns TRUE is socket error occurred.
119 
120  virtual UtlBoolean isReadyToRead(long waitMilliseconds = 0) const;
121  //:Poll if there are bytes to read
122  // Returns TRUE if socket is read to read.
123  // Returns FALSE if wait expires or socket error.
124 
125  virtual UtlBoolean isReadyToWrite(long timeoutMilliSec) const;
126 
127  void setHandshakeComplete() { mbHandshakeComplete = true; }
128  bool waitForHandshake(long milliseconds) const;
129 
130 /* ============================ ACCESSORS ================================= */
131 
132  virtual void close();
133  //: Closes the TLS socket
134 
135 /* ============================ INQUIRY =================================== */
136 
138  //: Returns the protocol type of this socket
139 
140 /* //////////////////////////// PROTECTED ///////////////////////////////// */
141 protected:
142  virtual void NSSInitSocket(int socket, long timeoutInSecs, const char* szPassword) = 0;
143 
144  UtlBoolean mbExternalTLSSocket;
145 
146  OsTLSConnectionSocket(const OsTLSConnectionSocket& rOsTLSConnectionSocket);
147  //:Disable copy constructor
148 
149  OsTLSConnectionSocket();
150  //:Disable default constructor
151 
152  OsTLSConnectionSocket& operator=(const OsTLSConnectionSocket& rhs);
153  //:Assignment operator
154 
155  PRFileDesc* mpPRfd;
156  UtlString mCertNickname;
157  UtlString mCertPassword;
158  UtlString mDbLocation;
159  SECKEYPrivateKey * mpPrivKey;
160  CERTCertificate * mpCert;
161  mutable OsMutex mSocketGuard;
162  bool mbHandshakeComplete;
163 
164 /* //////////////////////////// PRIVATE /////////////////////////////////// */
165 
166 };
167 
168 /* ============================ INLINE METHODS ============================ */
169 
170 #endif // SIP_TLS
171 #endif // SIP_TLS_NSS
172 
173 #endif // _OsTLSConnectionSocket_h_
174 
IpProtocolSocketType
Definition: OsSocket.h:92
virtual int write(const char *buffer, int bufferLength, const char *ipAddress, int port)
Definition: OsSocket.h:117
virtual int read(char *buffer, int bufferLength)
param: waitMilliseconds - The maximum number of milliseconds to block. This may be set to zero...
Definition: OsConnectionSocket.cpp:304
virtual void close()
param: waitMilliseconds - The maximum number of milliseconds to block. This may be set to zero in whi...
Definition: OsSocket.cpp:692
virtual UtlBoolean isReadyToWrite(long waitMilliseconds=0) const
Definition: OsSocket.cpp:581
virtual UtlBoolean reconnect()
Definition: OsConnectionSocket.cpp:295
virtual UtlBoolean isReadyToRead(long waitMilliseconds=0) const
Definition: OsSocket.cpp:574
Definition: UtlString.h:48
virtual OsSocket::IpProtocolSocketType getIpProtocol() const
param: waitMilliseconds - The maximum number of milliseconds to block. This may be set to zero in whi...
Definition: OsConnectionSocket.cpp:340
Definition: OsConnectionSocket.h:34
int UtlBoolean
Definition: UtlDefs.h:41
virtual UtlBoolean isReadyToReadEx(long waitMilliseconds, UtlBoolean &rSocketError) const
Definition: OsSocket.cpp:406