Skip to content

Commit 2343c81

Browse files
authored
- Resurrected the original pipe-delimited work and renamed it to UserAgent. (dotnet#3826)
1 parent 6f2bb8a commit 2343c81

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

@@ -1317,11 +1317,11 @@ internal void TdsLogin(
13171317
// length in bytes
13181318
int length = TdsEnums.SQL2005_LOG_REC_FIXED_LEN;
13191319

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

13231324
// add up variable-len portions (multiply by 2 for byte len of char strings)
1324-
//
13251325
checked
13261326
{
13271327
length += (rec.hostName.Length + rec.applicationName.Length +
@@ -1376,7 +1376,7 @@ internal void TdsLogin(
13761376
requestedFeatures,
13771377
recoverySessionData,
13781378
fedAuthFeatureExtensionData,
1379-
UserAgentInfo.UserAgentCachedJsonPayload.ToArray(),
1379+
UserAgent.Ucs2Bytes,
13801380
useFeatureExt,
13811381
length
13821382
);
@@ -9186,43 +9186,41 @@ internal int WriteVectorSupportFeatureRequest(bool write)
91869186
}
91879187

91889188
/// <summary>
9189-
/// Writes the User Agent feature request to the physical state object.
9190-
/// The request includes the feature ID, feature data length, version number and encoded JSON payload.
9189+
/// Writes the User Agent feature request to the physical state
9190+
/// object. The request includes the feature ID, feature data length,
9191+
/// and UCS-2 little-endian encoded payload.
91919192
/// </summary>
9192-
/// <param name="userAgentJsonPayload"> Byte array of UTF-8 encoded JSON payload for User Agent</param>
9193+
/// <remarks>
9194+
/// The feature request consists of:
9195+
/// - 1 byte for the feature ID.
9196+
/// - 4 bytes for the feature data length.
9197+
/// - N bytes for the UCS-2 payload
9198+
/// </remarks>
9199+
/// <param name="userAgent">
9200+
/// UCS-2 little-endian encoded UserAgent payload.
9201+
/// </param>
91939202
/// <param name="write">
9194-
/// If true, writes the feature request to the physical state object.
9195-
/// If false, just calculates the length.
9203+
/// If true, writes the feature request to the physical state object.
9204+
/// If false, just calculates the length.
91969205
/// </param>
91979206
/// <returns>The length of the feature request in bytes.</returns>
9198-
/// <remarks>
9199-
/// The feature request consists of:
9200-
/// - 1 byte for the feature ID.
9201-
/// - 4 bytes for the feature data length.
9202-
/// - 1 byte for the version number.
9203-
/// - N bytes for the JSON payload
9204-
/// </remarks>
9205-
internal int WriteUserAgentFeatureRequest(byte[] userAgentJsonPayload,
9207+
internal int WriteUserAgentFeatureRequest(ReadOnlyMemory<byte> userAgent,
92069208
bool write)
92079209
{
9208-
// 1byte (Feature Version) + size of UTF-8 encoded JSON payload
9209-
int dataLen = 1 + userAgentJsonPayload.Length;
9210-
// 1byte (Feature ID) + 4bytes (Feature Data Length) + 1byte (Version) + N(JSON payload size)
9211-
int totalLen = 1 + 4 + dataLen;
9210+
// 1 byte (Feature ID) + 4 bytes (Feature Data Length) + N bytes
9211+
// (UCS-2 payload size)
9212+
int totalLen = 1 + 4 + userAgent.Length;
92129213

92139214
if (write)
92149215
{
92159216
// Write Feature ID
92169217
_physicalStateObj.WriteByte(TdsEnums.FEATUREEXT_USERAGENT);
92179218

92189219
// Feature Data Length
9219-
WriteInt(dataLen, _physicalStateObj);
9220-
9221-
// Write Feature Version
9222-
_physicalStateObj.WriteByte(TdsEnums.SUPPORTED_USER_AGENT_VERSION);
9220+
WriteInt(userAgent.Length, _physicalStateObj);
92239221

9224-
// Write encoded JSON payload
9225-
_physicalStateObj.WriteByteArray(userAgentJsonPayload, userAgentJsonPayload.Length, 0);
9222+
// Write encoded UCS-2 payload
9223+
_physicalStateObj.WriteByteSpan(userAgent.Span);
92269224
}
92279225

92289226
return totalLen;
@@ -9502,7 +9500,7 @@ private void WriteLoginData(SqlLogin rec,
95029500
requestedFeatures,
95039501
recoverySessionData,
95049502
fedAuthFeatureExtensionData,
9505-
UserAgentInfo.UserAgentCachedJsonPayload.ToArray(),
9503+
UserAgent.Ucs2Bytes,
95069504
useFeatureExt,
95079505
length,
95089506
true
@@ -9525,7 +9523,7 @@ private void WriteLoginData(SqlLogin rec,
95259523
private int ApplyFeatureExData(TdsEnums.FeatureExtension requestedFeatures,
95269524
SessionData recoverySessionData,
95279525
FederatedAuthenticationFeatureExtensionData fedAuthFeatureExtensionData,
9528-
byte[] userAgentJsonPayload,
9526+
ReadOnlyMemory<byte> userAgent,
95299527
bool useFeatureExt,
95309528
int length,
95319529
bool write = false)
@@ -9537,7 +9535,7 @@ private int ApplyFeatureExData(TdsEnums.FeatureExtension requestedFeatures,
95379535
// NOTE: As part of TDS spec UserAgent feature extension should be the first feature extension in the list.
95389536
if (LocalAppContextSwitches.EnableUserAgent && ((requestedFeatures & TdsEnums.FeatureExtension.UserAgent) != 0))
95399537
{
9540-
length += WriteUserAgentFeatureRequest(userAgentJsonPayload, write);
9538+
length += WriteUserAgentFeatureRequest(userAgent, write);
95419539
}
95429540
if ((requestedFeatures & TdsEnums.FeatureExtension.SessionRecovery) != 0)
95439541
{

0 commit comments

Comments
 (0)