Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient
In directory sc8-pr-cvs1:/tmp/cvs-serv18087
Modified Files:
PgDbClient.cs
Log Message:
2003-11-14 Carlos Guzmán Álvarez <car...@te...>
* source/NPgClient/PgDbClient.cs:
* Added changes for make use of the new scema of the SSL/TLS library.
Index: PgDbClient.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgDbClient.cs,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** PgDbClient.cs 12 Nov 2003 22:38:32 -0000 1.31
--- PgDbClient.cs 14 Nov 2003 13:44:23 -0000 1.32
***************
*** 51,60 ****
private int secretKey;
private Hashtable parameterStatus;
private BinaryReader receive;
private BinaryWriter send;
- private PgConnectionParams settings;
- private char transactionStatus;
- private TlsSession session;
private PgResponsePacket buffer;
#endregion
--- 51,62 ----
private int secretKey;
private Hashtable parameterStatus;
+ private Socket socket;
+ private NetworkStream networkStream;
+ private SslClientStream sslStream;
private BinaryReader receive;
private BinaryWriter send;
private PgResponsePacket buffer;
+ private PgConnectionParams settings;
+ private char transactionStatus;
#endregion
***************
*** 137,158 ****
PgDbClient.InitializeTypes();
PgDbClient.InitializeCharSets();
lock (this)
{
- // Configure TLS Session Settings
- TlsSessionSettings tlsSettings = new TlsSessionSettings();
-
- tlsSettings.Protocol = SecurityProtocolType.Tls1;
- tlsSettings.CompressionMethod = SecurityCompressionType.None;
- tlsSettings.ServerName = settings.ServerName;
- tlsSettings.ServerPort = settings.ServerPort;
-
- // Create a new TLS Session
- session = new TlsSession(tlsSettings);
-
- // Create objects for read & write
- receive = new BinaryReader(session.NetworkStream);
- send = new BinaryWriter(session.NetworkStream);
-
if (settings.SSL)
{
--- 139,147 ----
PgDbClient.InitializeTypes();
PgDbClient.InitializeCharSets();
+
+ initializeSocket();
lock (this)
{
if (settings.SSL)
{
***************
*** 162,177 ****
if (settings.SSL)
{
! try
! {
! // Start TLS Session
! session.Open();
! }
! catch (TlsException ex)
! {
! // If the exception is fatal close connection
! session.Close();
! throw new PgClientException(ex.Message);
! }
}
}
--- 151,162 ----
if (settings.SSL)
{
! sslStream = new SslClientStream(
! networkStream,
! settings.ServerName,
! true,
! SecurityProtocolType.Default);
! receive = new BinaryReader(sslStream);
! send = new BinaryWriter(sslStream);
}
}
***************
*** 202,208 ****
}
}
catch (PgClientException ex)
{
! session.Close();
throw ex;
}
--- 187,207 ----
}
}
+ catch (TlsException ex)
+ {
+ // If the exception is fatal close connection
+ sslStream.Close();
+
+ throw new PgClientException(ex.Message);
+ }
catch (PgClientException ex)
{
! if (sslStream != null)
! {
! sslStream.Close();
! }
! if (networkStream != null)
! {
! networkStream.Close();
! }
throw ex;
}
***************
*** 217,222 ****
SendData(packet.GetPacketBytes(PgFrontEndCodes.TERMINATE));
! // End session
! session.Close();
}
catch (PgClientException ex)
--- 216,232 ----
SendData(packet.GetPacketBytes(PgFrontEndCodes.TERMINATE));
! // Close streams
! if (sslStream != null)
! {
! sslStream.Close();
! }
! if (networkStream != null)
! {
! networkStream.Close();
! }
! }
! catch (TlsException ex)
! {
! throw new PgClientException(ex.Message);
}
catch (PgClientException ex)
***************
*** 784,787 ****
--- 794,827 ----
{
return new PgStatement(this, parseName, portalName, stmtText);
+ }
+
+ #endregion
+
+ #region PRIVATE_METHODS
+
+ private void initializeSocket()
+ {
+ IPAddress hostadd = Dns.Resolve(settings.ServerName).AddressList[0];
+ IPEndPoint EPhost = new IPEndPoint(hostadd, settings.ServerPort);
+
+ this.socket = new Socket(AddressFamily.InterNetwork,
+ SocketType.Stream,
+ ProtocolType.IP);
+
+ // Set Receive Buffer size.
+ socket.SetSocketOption(SocketOptionLevel.Socket,
+ SocketOptionName.ReceiveBuffer, settings.PacketSize);
+
+ // Set Send Buffer size.
+ socket.SetSocketOption(SocketOptionLevel.Socket,
+ SocketOptionName.SendBuffer, settings.PacketSize);
+
+ // Make the socket to connect to the Server
+ this.socket.Connect(EPhost);
+ this.networkStream = new NetworkStream(socket, true);
+
+ // Create objects for read & write
+ this.receive = new BinaryReader(this.networkStream);
+ this.send = new BinaryWriter(this.networkStream);
}
|