[pgsqlclient-checkins] pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient PgAuthMethods.cs,
Status: Inactive
Brought to you by:
carlosga_fb
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient
In directory sc8-pr-cvs1:/tmp/cvs-serv771
Modified Files:
PgAuthMethods.cs PgConnectionParams.cs PgDbClient.cs
PgInetWriter.cs PgOutputPacket.cs PgStatement.cs
Log Message:
Added changes for better handling of net writes
Index: PgAuthMethods.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgAuthMethods.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** PgAuthMethods.cs 2 Aug 2003 19:43:01 -0000 1.1.1.1
--- PgAuthMethods.cs 15 Aug 2003 17:50:09 -0000 1.2
***************
*** 49,51 ****
}
}
! }
--- 49,51 ----
}
}
! }
\ No newline at end of file
Index: PgConnectionParams.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgConnectionParams.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** PgConnectionParams.cs 2 Aug 2003 19:43:02 -0000 1.1.1.1
--- PgConnectionParams.cs 15 Aug 2003 17:50:09 -0000 1.2
***************
*** 35,38 ****
--- 35,39 ----
private bool pooling;
private Encoding encoding;
+ private bool ssl;
#endregion
***************
*** 92,95 ****
--- 93,102 ----
get { return pooling; }
set { pooling = value; }
+ }
+
+ public bool SSL
+ {
+ get { return ssl; }
+ set { ssl = value; }
}
Index: PgDbClient.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgDbClient.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PgDbClient.cs 2 Aug 2003 21:12:16 -0000 1.2
--- PgDbClient.cs 15 Aug 2003 17:50:09 -0000 1.3
***************
*** 25,28 ****
--- 25,30 ----
using System.Text;
+ //using PgSqlClient.Security.TLS;
+
namespace PostgreSql.Data.NPgClient
{
***************
*** 143,147 ****
lock (this)
{
! PgOutputPacket packet = new PgOutputPacket(4, settings.Encoding);
packet.WriteInt(PgCodes.PROTOCOL_VERSION3);
--- 145,181 ----
lock (this)
{
! if (settings.SSL)
! {
! // Send SSL request message
! SSLRequest();
!
! if (settings.SSL)
! {
! /*
! TlsSession session = new TlsSession(new TlsSessionSettings(TlsProtocol.Tls1));
!
! TlsWriter tlsSend = session.GetWriter(new BufferedStream(this.networkStream));
! TlsReader tlsRead = session.GetReader(new BufferedStream(this.networkStream));
!
! try
! {
! // Start TLS Session
! session.StartSession();
! }
! catch (TlsException ex)
! {
! // If the exception is fatal close connection
! if (ex.AlertLevel == TlsAlertLevel.Fatal)
! {
! this.Detach();
! }
! throw new PgClientException(ex.Message);
! }
! */
! }
! }
!
! // Send Startup message
! PgOutputPacket packet = new PgOutputPacket(settings.Encoding);
packet.WriteInt(PgCodes.PROTOCOL_VERSION3);
***************
*** 155,159 ****
packet.Write((byte)0); // Terminator
! send.WriteSimplePacket(packet);
PgResponsePacket response = new PgResponsePacket();
--- 189,194 ----
packet.Write((byte)0); // Terminator
! send.Write(packet.GetSimplePacketBytes());
! send.Flush();
PgResponsePacket response = new PgResponsePacket();
***************
*** 163,167 ****
{
response = ReceiveResponsePacket();
! processResponsePacket(response);
}
}
--- 198,202 ----
{
response = ReceiveResponsePacket();
! processResponsePacket(response);
}
}
***************
*** 169,172 ****
--- 204,208 ----
catch (PgClientException ex)
{
+ this.Detach();
throw ex;
}
***************
*** 179,188 ****
// Send packet to the server
PgOutputPacket packet = new PgOutputPacket();
! send.WritePacket(PgFrontEndCodes.TERMINATE, packet);
! // Close all streams
! receive.Close();
! send.Close();
! socket.Close();
}
catch (PgClientException ex)
--- 215,224 ----
// Send packet to the server
PgOutputPacket packet = new PgOutputPacket();
!
! send.Write(packet.GetPacketBytes(PgFrontEndCodes.TERMINATE));
! send.Flush();
! // Close socket and streams
! this.Detach();
}
catch (PgClientException ex)
***************
*** 192,200 ****
}
#endregion
#region RESPONSE_METHODS
! public PgResponsePacket ReceiveResponsePacket()
{
char type;
--- 228,245 ----
}
+ public void Detach()
+ {
+ // Close socket and streams
+ receive.Close();
+ send.Close();
+ socket.Close();
+ }
+
+
#endregion
#region RESPONSE_METHODS
! public PgResponsePacket ReceiveResponsePacket(params bool[] sslRequest)
{
char type;
***************
*** 204,209 ****
lock (this)
{
type = (char)receive.ReadByte();
! length = receive.ReadInt() - 4;
if (length != 0)
--- 249,258 ----
lock (this)
{
+ length = 0;
type = (char)receive.ReadByte();
! if ((sslRequest.Length > 0 && !sslRequest[0]) || type == PgBackendCodes.ERROR_RESPONSE)
! {
! length = receive.ReadInt() - 4;
! }
if (length != 0)
***************
*** 344,348 ****
// Send the packet to the server
! send.WritePacket(PgFrontEndCodes.PASSWORD_MESSAGE, outPacket);
}
--- 393,398 ----
// Send the packet to the server
! send.Write(outPacket.GetPacketBytes(PgFrontEndCodes.PASSWORD_MESSAGE));
! send.Flush();
}
***************
*** 491,495 ****
// Send packet to the server
! send.WritePacket(PgFrontEndCodes.FLUSH, packet);
}
catch (Exception ex)
--- 541,546 ----
// Send packet to the server
! send.Write(packet.GetPacketBytes(PgFrontEndCodes.FLUSH));
! send.Flush();
}
catch (Exception ex)
***************
*** 509,513 ****
// Send packet to the server
! send.WritePacket(PgFrontEndCodes.SYNC, packet);
}
catch (Exception ex)
--- 560,565 ----
// Send packet to the server
! send.Write(packet.GetPacketBytes(PgFrontEndCodes.SYNC));
! send.Flush();
}
catch (Exception ex)
***************
*** 524,529 ****
try
{
! PgOutputPacket packet = new PgOutputPacket(0);
packet.WriteInt(PgCodes.CANCEL_REQUEST);
packet.WriteInt(Handle);
--- 576,582 ----
try
{
! PgOutputPacket packet = new PgOutputPacket();
+ packet.WriteInt(16);
packet.WriteInt(PgCodes.CANCEL_REQUEST);
packet.WriteInt(Handle);
***************
*** 531,535 ****
// Send packet to the server
! send.WriteSimplePacket(packet);
}
catch (Exception ex)
--- 584,624 ----
// Send packet to the server
! send.Write(packet.GetSimplePacketBytes());
! send.Flush();
! }
! catch (Exception ex)
! {
! throw ex;
! }
! }
! }
!
! public void SSLRequest()
! {
! lock (this)
! {
! try
! {
! PgOutputPacket packet = new PgOutputPacket();
!
! packet.WriteInt(PgCodes.SSL_REQUEST);
!
! // Send packet to the server
! send.Write(packet.GetSimplePacketBytes());
! send.Flush();
!
! // Receive server response
! PgResponsePacket response = ReceiveResponsePacket(true);
!
! switch (response.Message)
! {
! case 'S':
! settings.SSL = true;
! break;
!
! default:
! settings.SSL = false;
! break;
! }
}
catch (Exception ex)
Index: PgInetWriter.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgInetWriter.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** PgInetWriter.cs 2 Aug 2003 19:43:02 -0000 1.1.1.1
--- PgInetWriter.cs 15 Aug 2003 17:50:09 -0000 1.2
***************
*** 36,39 ****
--- 36,40 ----
#region METHODS
+ /*
public void WriteSimplePacket(PgOutputPacket packet)
{
***************
*** 59,63 ****
Flush();
}
!
#endregion
}
--- 60,64 ----
Flush();
}
! */
#endregion
}
Index: PgOutputPacket.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgOutputPacket.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** PgOutputPacket.cs 2 Aug 2003 19:43:02 -0000 1.1.1.1
--- PgOutputPacket.cs 15 Aug 2003 17:50:09 -0000 1.2
***************
*** 49,53 ****
{
this.encoding = Encoding.Default;
! Write(new byte[5]);
}
--- 49,53 ----
{
this.encoding = Encoding.Default;
! Write(new byte[0]);
}
***************
*** 55,71 ****
{
this.encoding = encoding;
! Write(new byte[5]);
! }
!
! public PgOutputPacket(int length) : base(new MemoryStream())
! {
! this.encoding = Encoding.Default;
! Write(new byte[length]);
! }
!
! public PgOutputPacket(int length, Encoding encoding) : base(new MemoryStream(), encoding)
! {
! this.encoding = encoding;
! Write(new byte[length]);
}
--- 55,59 ----
{
this.encoding = encoding;
! Write(new byte[0]);
}
***************
*** 248,252 ****
public int GetByteCount()
{
! return (int)((MemoryStream)BaseStream).Length - 1;
}
--- 236,240 ----
public int GetByteCount()
{
! return (int)((MemoryStream)BaseStream).Length;
}
***************
*** 260,263 ****
--- 248,277 ----
((MemoryStream)BaseStream).SetLength(0);
((MemoryStream)BaseStream).Position = 0;
+ }
+
+ #endregion
+
+ #region PACKET_BYTES
+
+ public byte[] GetSimplePacketBytes()
+ {
+ PgOutputPacket packet = new PgOutputPacket();
+
+ // Write packet contents
+ packet.WriteInt(GetByteCount() + 4);
+ packet.Write(GetBytes());
+
+ return packet.GetBytes();
+ }
+
+ public byte[] GetPacketBytes(char format)
+ {
+ PgOutputPacket packet = new PgOutputPacket();
+
+ packet.Write((byte)format);
+ packet.WriteInt(GetByteCount() + 4);
+ packet.Write(GetBytes());
+
+ return packet.GetBytes();
}
Index: PgStatement.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgStatement.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** PgStatement.cs 2 Aug 2003 19:43:02 -0000 1.1.1.1
--- PgStatement.cs 15 Aug 2003 17:50:09 -0000 1.2
***************
*** 190,194 ****
// Send packet to the server
! db.Send.WritePacket(PgFrontEndCodes.PARSE, packet);
// Sync server and client
--- 190,195 ----
// Send packet to the server
! db.Send.Write(packet.GetPacketBytes(PgFrontEndCodes.PARSE));
! db.Send.Flush();
// Sync server and client
***************
*** 239,243 ****
// Send packet to the server
! db.Send.WritePacket(PgFrontEndCodes.DESCRIBE, packet);
// Sync server and client
--- 240,245 ----
// Send packet to the server
! db.Send.Write(packet.GetPacketBytes(PgFrontEndCodes.DESCRIBE));
! db.Send.Flush();
// Sync server and client
***************
*** 307,311 ****
// Send packet to the server
! db.Send.WritePacket(PgFrontEndCodes.BIND, packet);
// Sync server and client
--- 309,314 ----
// Send packet to the server
! db.Send.Write(packet.GetPacketBytes(PgFrontEndCodes.BIND));
! db.Send.Flush();
// Sync server and client
***************
*** 341,345 ****
// Send packet to the server
! db.Send.WritePacket(PgFrontEndCodes.EXECUTE, packet);
// Sync server and client
--- 344,349 ----
// Send packet to the server
! db.Send.Write(packet.GetPacketBytes(PgFrontEndCodes.EXECUTE));
! db.Send.Flush();
// Sync server and client
***************
*** 396,400 ****
// Send packet to the server
! db.Send.WritePacket(PgFrontEndCodes.FUNCTION_CALL, packet);
// Receive response
--- 400,405 ----
// Send packet to the server
! db.Send.Write(packet.GetPacketBytes(PgFrontEndCodes.FUNCTION_CALL));
! db.Send.Flush();
// Receive response
***************
*** 426,430 ****
// Send packet to the server
! db.Send.WritePacket(PgFrontEndCodes.QUERY, packet);
// Receive response
--- 431,436 ----
// Send packet to the server
! db.Send.Write(packet.GetPacketBytes(PgFrontEndCodes.QUERY));
! db.Send.Flush();
// Receive response
***************
*** 497,501 ****
// Send packet to the server
! db.Send.WritePacket(PgFrontEndCodes.CLOSE, packet);
// Sync server and client
--- 503,508 ----
// Send packet to the server
! db.Send.Write(packet.GetPacketBytes(PgFrontEndCodes.CLOSE));
! db.Send.Flush();
// Sync server and client
|