1 // created on 9/6/2002 at 16:56
4 // Npgsql.NpgsqlStartupPacket.cs
7 // Francisco Jr. (fxjrlists@yahoo.com.br)
9 // Copyright (C) 2002 The Npgsql Development Team
12 // This library is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU Lesser General Public
14 // License as published by the Free Software Foundation; either
15 // version 2.1 of the License, or (at your option) any later version.
17 // This library is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Lesser General Public License for more details.
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 /// This class represents a StartupPacket message of PostgreSQL
39 internal sealed class NpgsqlStartupPacket
42 // Logging related values
43 private static readonly String CLASSNAME = "NpgsqlStartupPacket";
46 private Int32 packet_size;
47 private Int32 protocol_version;
48 private String database_name;
49 private String user_name;
50 private String arguments;
51 private String unused;
52 private String optional_tty;
54 public NpgsqlStartupPacket(Int32 packet_size,
55 Int32 protocol_version_major,
56 Int32 protocol_version_minor,
64 NpgsqlEventLog.LogMsg("Entering " + CLASSNAME + ".NpgsqlStartupPacket()", LogLevel.Debug);
65 // Just copy the values.
67 // [FIXME] Validate params? We are the only clients, so, hopefully, we
70 this.packet_size = packet_size;
71 this.protocol_version = (protocol_version_major<<16) | protocol_version_minor;
72 this.database_name = database_name;
73 this.user_name = user_name;
74 this.arguments = arguments;
76 this.optional_tty = optional_tty;
80 public void WriteToStream(Stream output_stream, Encoding encoding)
83 NpgsqlEventLog.LogMsg("Entering " + CLASSNAME + ".WriteToStream()", LogLevel.Debug);
85 // [FIXME] Need exception handling ?
87 // Packet length = 296
88 output_stream.Write(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(this.packet_size)), 0, 4);
90 // Protocol version = 2.0
91 output_stream.Write(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(this.protocol_version)), 0, 4);
94 PGUtil.WriteLimString(this.database_name, 64, output_stream, encoding);
97 PGUtil.WriteLimString(this.user_name, 32, output_stream, encoding);
100 PGUtil.WriteLimString(this.arguments, 64, output_stream, encoding);
103 PGUtil.WriteLimString(this.unused, 64, output_stream, encoding);
106 PGUtil.WriteLimString(this.optional_tty, 64, output_stream, encoding);