disable broken tests on net_4_0
[mcs.git] / class / Npgsql / Npgsql / NpgsqlStartupPacket.cs
blob47ef00f35a2c4a8c14b7b408127dd7026aa30776
1 // created on 9/6/2002 at 16:56
4 // Npgsql.NpgsqlStartupPacket.cs
5 //
6 // Author:
7 // Francisco Jr. (fxjrlists@yahoo.com.br)
8 //
9 // Copyright (C) 2002 The Npgsql Development Team
10 // npgsql-general@gborg.postgresql.org
11 // http://gborg.postgresql.org/project/npgsql/projdisplay.php
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2.1 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 using System;
28 using System.IO;
29 using System.Text;
30 using System.Net;
32 namespace Npgsql
35 /// <summary>
36 /// This class represents a StartupPacket message of PostgreSQL
37 /// protocol.
38 /// </summary>
39 ///
40 internal sealed class NpgsqlStartupPacket
42 // Logging related values
43 private static readonly String CLASSNAME = "NpgsqlStartupPacket";
45 // Private fields.
46 private Int32 packet_size;
47 private ProtocolVersion 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 ProtocolVersion protocol_version,
56 String database_name,
57 String user_name,
58 String arguments,
59 String unused,
60 String optional_tty)
63 NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, CLASSNAME);
64 // Just copy the values.
66 // [FIXME] Validate params? We are the only clients, so, hopefully, we
67 // know what to send.
69 this.packet_size = packet_size;
70 this.protocol_version = protocol_version;
72 this.database_name = database_name;
73 this.user_name = user_name;
74 this.arguments = arguments;
75 this.unused = unused;
76 this.optional_tty = optional_tty;
81 public void WriteToStream(Stream output_stream, Encoding encoding)
83 NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "WriteToStream");
85 switch (protocol_version) {
86 case ProtocolVersion.Version2 :
87 WriteToStream_Ver_2(output_stream, encoding);
88 break;
90 case ProtocolVersion.Version3 :
91 WriteToStream_Ver_3(output_stream, encoding);
92 break;
98 private void WriteToStream_Ver_2(Stream output_stream, Encoding encoding)
100 NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "WriteToStream_Ver_2");
102 // Packet length = 296
103 output_stream.Write(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(this.packet_size)), 0, 4);
105 output_stream.Write(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(PGUtil.ConvertProtocolVersion(this.protocol_version))), 0, 4);
107 // Database name.
108 PGUtil.WriteLimString(this.database_name, 64, output_stream, encoding);
110 // User name.
111 PGUtil.WriteLimString(this.user_name, 32, output_stream, encoding);
113 // Arguments.
114 PGUtil.WriteLimString(this.arguments, 64, output_stream, encoding);
116 // Unused.
117 PGUtil.WriteLimString(this.unused, 64, output_stream, encoding);
119 // Optional tty.
120 PGUtil.WriteLimString(this.optional_tty, 64, output_stream, encoding);
121 output_stream.Flush();
125 private void WriteToStream_Ver_3(Stream output_stream, Encoding encoding)
127 NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "WriteToStream_Ver_3");
129 PGUtil.WriteInt32(output_stream, 4 + 4 + 5 + (encoding.GetByteCount(user_name) + 1) + 9 + (encoding.GetByteCount(database_name) + 1) + 10 + 4 + 1);
131 PGUtil.WriteInt32(output_stream, Npgsql.PGUtil.ConvertProtocolVersion(this.protocol_version));
133 // User name.
134 PGUtil.WriteString("user", output_stream, encoding);
136 // User name.
137 PGUtil.WriteString(user_name, output_stream, encoding);
139 // Database name.
140 PGUtil.WriteString("database", output_stream, encoding);
142 // Database name.
143 PGUtil.WriteString(database_name, output_stream, encoding);
145 // DateStyle.
146 PGUtil.WriteString("DateStyle", output_stream, encoding);
148 // DateStyle.
149 PGUtil.WriteString("ISO", output_stream, encoding);
151 output_stream.WriteByte(0);
152 output_stream.Flush();