Skip to content

Commit db6cc4d

Browse files
committed
- Resurrected the original pipe-delimited work and renamed it to UserAgent.
- Reverted commit e0fa87b. - Removed the JSON-based user agent classes. - Updated UserAgent to produce the proper pipe-delimited format. - Updated TDS emission to remove UserAgent version byte. - Swapped the Architecture and OS Type fields.
1 parent bc3d519 commit db6cc4d

17 files changed

Lines changed: 1076 additions & 965 deletions

File tree

spec/user-agent-v1.jsonc

Lines changed: 0 additions & 94 deletions
This file was deleted.

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -989,14 +989,8 @@
989989
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\TransactionRequest.cs">
990990
<Link>Microsoft\Data\SqlClient\TransactionRequest.cs</Link>
991991
</Compile>
992-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\UserAgent\UserAgentInfo.cs">
993-
<Link>Microsoft\Data\SqlClient\UserAgent\UserAgentInfo.cs</Link>
994-
</Compile>
995-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\UserAgent\UserAgentInfoDto.cs">
996-
<Link>Microsoft\Data\SqlClient\UserAgent\UserAgentInfoDto.cs</Link>
997-
</Compile>
998-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\UserAgent\UserAgentInfoDtoSerializerContext.cs">
999-
<Link>Microsoft\Data\SqlClient\UserAgent\UserAgentInfoDtoSerializerContext.cs</Link>
992+
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\UserAgent.cs">
993+
<Link>Microsoft\Data\SqlClient\UserAgent.cs</Link>
1000994
</Compile>
1001995
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\VirtualSecureModeEnclaveProvider.cs">
1002996
<Link>Microsoft\Data\SqlClient\VirtualSecureModeEnclaveProvider.cs</Link>

src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,9 @@
963963
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\TransactionRequest.cs">
964964
<Link>Microsoft\Data\SqlClient\TransactionRequest.cs</Link>
965965
</Compile>
966+
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\UserAgent.cs">
967+
<Link>Microsoft\Data\SqlClient\UserAgent.cs</Link>
968+
</Compile>
966969
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Utilities\BufferWriterExtensions.netfx.cs">
967970
<Link>Microsoft\Data\SqlClient\Utilities\BufferWriterExtensions.netfx.cs</Link>
968971
</Compile>
@@ -996,15 +999,6 @@
996999
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlTypeWorkarounds.cs">
9971000
<Link>Microsoft\Data\SqlTypes\SqlTypeWorkarounds.cs</Link>
9981001
</Compile>
999-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\UserAgent\UserAgentInfo.cs">
1000-
<Link>Microsoft\Data\SqlClient\UserAgent\UserAgentInfo.cs</Link>
1001-
</Compile>
1002-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\UserAgent\UserAgentInfoDto.cs">
1003-
<Link>Microsoft\Data\SqlClient\UserAgent\UserAgentInfoDto.cs</Link>
1004-
</Compile>
1005-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\UserAgent\UserAgentInfoDtoSerializerContext.cs">
1006-
<Link>Microsoft\Data\SqlClient\UserAgent\UserAgentInfoDtoSerializerContext.cs</Link>
1007-
</Compile>
10081002
<Compile Include="$(CommonSourceRoot)Resources\ResCategoryAttribute.cs">
10091003
<Link>Resources\ResCategoryAttribute.cs</Link>
10101004
</Compile>

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlError.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using Microsoft.Data.Common.ConnectionString;
67

78
namespace Microsoft.Data.SqlClient
89
{
@@ -11,7 +12,7 @@ namespace Microsoft.Data.SqlClient
1112
public sealed class SqlError
1213
{
1314
// bug fix - MDAC 48965 - missing source of exception
14-
private readonly string _source = TdsEnums.SQL_PROVIDER_NAME;
15+
private readonly string _source = DbConnectionStringDefaults.ApplicationName;
1516
private readonly int _number;
1617
private readonly byte _state;
1718
private readonly byte _errorClass;

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlException.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Runtime.Serialization;
1212
using System.Text;
1313
using Microsoft.Data.SqlClient.Connection;
14+
using Microsoft.Data.Common.ConnectionString;
1415

1516
namespace Microsoft.Data.SqlClient
1617
{
@@ -113,7 +114,7 @@ public override void GetObjectData(SerializationInfo si, StreamingContext contex
113114
public byte State => Errors.Count > 0 ? Errors[0].State : default;
114115

115116
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlException.xml' path='docs/members[@name="SqlException"]/Source/*' />
116-
override public string Source => TdsEnums.SQL_PROVIDER_NAME;
117+
override public string Source => DbConnectionStringDefaults.ApplicationName;
117118

118119

119120
#if NET

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsEnums.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ namespace Microsoft.Data.SqlClient
1313
internal static class TdsEnums
1414
{
1515
// internal tdsparser constants
16-
17-
18-
public const string SQL_PROVIDER_NAME = DbConnectionStringDefaults.ApplicationName;
19-
2016
public static readonly decimal SQL_SMALL_MONEY_MIN = new(-214748.3648);
2117
public static readonly decimal SQL_SMALL_MONEY_MAX = new(214748.3647);
2218

@@ -987,9 +983,6 @@ internal enum FedAuthInfoId : byte
987983
internal const byte MAX_SUPPORTED_VECTOR_VERSION = 0x01;
988984
internal const int VECTOR_HEADER_SIZE = 8;
989985

990-
// User Agent constants
991-
internal const byte SUPPORTED_USER_AGENT_VERSION = 0x01;
992-
993986
// TCE Related constants
994987
internal const byte MAX_SUPPORTED_TCE_VERSION = 0x03; // max version
995988
internal const byte MIN_TCE_VERSION_WITH_ENCLAVE_SUPPORT = 0x02; // min version with enclave support

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
using System.Xml;
1919
using Interop.Common.Sni;
2020
using Microsoft.Data.Common;
21+
using Microsoft.Data.Common.ConnectionString;
2122
using Microsoft.Data.ProviderBase;
2223
using Microsoft.Data.Sql;
2324
using Microsoft.Data.SqlClient.Connection;
2425
using Microsoft.Data.SqlClient.DataClassification;
2526
using Microsoft.Data.SqlClient.LocalDb;
2627
using Microsoft.Data.SqlClient.Server;
27-
using Microsoft.Data.SqlClient.UserAgent;
2828
using Microsoft.Data.SqlClient.Utilities;
2929
using Microsoft.SqlServer.Server;
3030

@@ -1307,11 +1307,11 @@ internal void TdsLogin(
13071307
// length in bytes
13081308
int length = TdsEnums.SQL2005_LOG_REC_FIXED_LEN;
13091309

1310-
string clientInterfaceName = TdsEnums.SQL_PROVIDER_NAME;
1311-
Debug.Assert(TdsEnums.MAXLEN_CLIENTINTERFACE >= clientInterfaceName.Length, "cchCltIntName can specify at most 128 unicode characters. See Tds spec");
1310+
// Obtain the client interface name.
1311+
string clientInterfaceName = DbConnectionStringDefaults.ApplicationName;
1312+
Debug.Assert(clientInterfaceName.Length <= TdsEnums.MAXLEN_CLIENTINTERFACE);
13121313

13131314
// add up variable-len portions (multiply by 2 for byte len of char strings)
1314-
//
13151315
checked
13161316
{
13171317
length += (rec.hostName.Length + rec.applicationName.Length +
@@ -1366,7 +1366,7 @@ internal void TdsLogin(
13661366
requestedFeatures,
13671367
recoverySessionData,
13681368
fedAuthFeatureExtensionData,
1369-
UserAgentInfo.UserAgentCachedJsonPayload.ToArray(),
1369+
UserAgent.Ucs2Bytes,
13701370
useFeatureExt,
13711371
length
13721372
);
@@ -9176,43 +9176,41 @@ internal int WriteVectorSupportFeatureRequest(bool write)
91769176
}
91779177

91789178
/// <summary>
9179-
/// Writes the User Agent feature request to the physical state object.
9180-
/// The request includes the feature ID, feature data length, version number and encoded JSON payload.
9179+
/// Writes the User Agent feature request to the physical state
9180+
/// object. The request includes the feature ID, feature data length,
9181+
/// and UCS-2 little-endian encoded payload.
91819182
/// </summary>
9182-
/// <param name="userAgentJsonPayload"> Byte array of UTF-8 encoded JSON payload for User Agent</param>
9183+
/// <remarks>
9184+
/// The feature request consists of:
9185+
/// - 1 byte for the feature ID.
9186+
/// - 4 bytes for the feature data length.
9187+
/// - N bytes for the UCS-2 payload
9188+
/// </remarks>
9189+
/// <param name="userAgent">
9190+
/// UCS-2 little-endian encoded UserAgent payload.
9191+
/// </param>
91839192
/// <param name="write">
9184-
/// If true, writes the feature request to the physical state object.
9185-
/// If false, just calculates the length.
9193+
/// If true, writes the feature request to the physical state object.
9194+
/// If false, just calculates the length.
91869195
/// </param>
91879196
/// <returns>The length of the feature request in bytes.</returns>
9188-
/// <remarks>
9189-
/// The feature request consists of:
9190-
/// - 1 byte for the feature ID.
9191-
/// - 4 bytes for the feature data length.
9192-
/// - 1 byte for the version number.
9193-
/// - N bytes for the JSON payload
9194-
/// </remarks>
9195-
internal int WriteUserAgentFeatureRequest(byte[] userAgentJsonPayload,
9197+
internal int WriteUserAgentFeatureRequest(ReadOnlyMemory<byte> userAgent,
91969198
bool write)
91979199
{
9198-
// 1byte (Feature Version) + size of UTF-8 encoded JSON payload
9199-
int dataLen = 1 + userAgentJsonPayload.Length;
9200-
// 1byte (Feature ID) + 4bytes (Feature Data Length) + 1byte (Version) + N(JSON payload size)
9201-
int totalLen = 1 + 4 + dataLen;
9200+
// 1 byte (Feature ID) + 4 bytes (Feature Data Length) + N bytes
9201+
// (UCS-2 payload size)
9202+
int totalLen = 1 + 4 + userAgent.Length;
92029203

92039204
if (write)
92049205
{
92059206
// Write Feature ID
92069207
_physicalStateObj.WriteByte(TdsEnums.FEATUREEXT_USERAGENT);
92079208

92089209
// Feature Data Length
9209-
WriteInt(dataLen, _physicalStateObj);
9210-
9211-
// Write Feature Version
9212-
_physicalStateObj.WriteByte(TdsEnums.SUPPORTED_USER_AGENT_VERSION);
9210+
WriteInt(userAgent.Length, _physicalStateObj);
92139211

9214-
// Write encoded JSON payload
9215-
_physicalStateObj.WriteByteArray(userAgentJsonPayload, userAgentJsonPayload.Length, 0);
9212+
// Write encoded UCS-2 payload
9213+
_physicalStateObj.WriteByteSpan(userAgent.Span);
92169214
}
92179215

92189216
return totalLen;
@@ -9492,7 +9490,7 @@ private void WriteLoginData(SqlLogin rec,
94929490
requestedFeatures,
94939491
recoverySessionData,
94949492
fedAuthFeatureExtensionData,
9495-
UserAgentInfo.UserAgentCachedJsonPayload.ToArray(),
9493+
UserAgent.Ucs2Bytes,
94969494
useFeatureExt,
94979495
length,
94989496
true
@@ -9515,7 +9513,7 @@ private void WriteLoginData(SqlLogin rec,
95159513
private int ApplyFeatureExData(TdsEnums.FeatureExtension requestedFeatures,
95169514
SessionData recoverySessionData,
95179515
FederatedAuthenticationFeatureExtensionData fedAuthFeatureExtensionData,
9518-
byte[] userAgentJsonPayload,
9516+
ReadOnlyMemory<byte> userAgent,
95199517
bool useFeatureExt,
95209518
int length,
95219519
bool write = false)
@@ -9527,7 +9525,7 @@ private int ApplyFeatureExData(TdsEnums.FeatureExtension requestedFeatures,
95279525
// NOTE: As part of TDS spec UserAgent feature extension should be the first feature extension in the list.
95289526
if (LocalAppContextSwitches.EnableUserAgent && ((requestedFeatures & TdsEnums.FeatureExtension.UserAgent) != 0))
95299527
{
9530-
length += WriteUserAgentFeatureRequest(userAgentJsonPayload, write);
9528+
length += WriteUserAgentFeatureRequest(userAgent, write);
95319529
}
95329530
if ((requestedFeatures & TdsEnums.FeatureExtension.SessionRecovery) != 0)
95339531
{

0 commit comments

Comments
 (0)