Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 0 additions & 94 deletions spec/user-agent-v1.jsonc

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,9 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\TransactionRequest.cs">
<Link>Microsoft\Data\SqlClient\TransactionRequest.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\UserAgent.cs">
<Link>Microsoft\Data\SqlClient\UserAgent.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\VirtualSecureModeEnclaveProvider.cs">
<Link>Microsoft\Data\SqlClient\VirtualSecureModeEnclaveProvider.cs</Link>
</Compile>
Expand All @@ -846,12 +849,6 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlVector.cs">
<Link>Microsoft\Data\SqlTypes\SqlVector.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\UserAgent\UserAgentInfo.cs">
<Link>Microsoft\Data\SqlClient\UserAgent\UserAgentInfo.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\UserAgent\UserAgentInfoDto.cs">
<Link>Microsoft\Data\SqlClient\UserAgent\UserAgentInfoDto.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Resources\ResCategoryAttribute.cs">
<Link>Resources\ResCategoryAttribute.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,9 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\TransactionRequest.cs">
<Link>Microsoft\Data\SqlClient\TransactionRequest.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\UserAgent.cs">
<Link>Microsoft\Data\SqlClient\UserAgent.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Utilities\BufferWriterExtensions.netfx.cs">
<Link>Microsoft\Data\SqlClient\Utilities\BufferWriterExtensions.netfx.cs</Link>
</Compile>
Expand Down Expand Up @@ -1001,12 +1004,6 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlVector.cs">
<Link>Microsoft\Data\SqlTypes\SqlVector.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\UserAgent\UserAgentInfo.cs">
<Link>Microsoft\Data\SqlClient\UserAgent\UserAgentInfo.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\UserAgent\UserAgentInfoDto.cs">
<Link>Microsoft\Data\SqlClient\UserAgent\UserAgentInfoDto.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Resources\ResDescriptionAttribute.cs">
<Link>Resources\ResDescriptionAttribute.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,11 @@ public static bool IgnoreServerProvidedFailoverPartner
return s_ignoreServerProvidedFailoverPartner == Tristate.True;
}
}

/// <summary>
/// When set to true, the user agent feature is enabled and the driver will send the user agent string to the server.
/// When set to true, the user agent feature is enabled and the driver
/// will send the user agent string to the server as a LOGIN7 feature
/// extension.
/// </summary>
public static bool EnableUserAgent
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using Microsoft.Data.Common.ConnectionString;

namespace Microsoft.Data.SqlClient
{
Expand All @@ -11,7 +12,7 @@ namespace Microsoft.Data.SqlClient
public sealed class SqlError
{
// bug fix - MDAC 48965 - missing source of exception
private readonly string _source = TdsEnums.SQL_PROVIDER_NAME;
private readonly string _source = DbConnectionStringDefaults.ApplicationName;
private readonly int _number;
private readonly byte _state;
private readonly byte _errorClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Globalization;
using System.Runtime.Serialization;
using System.Text;
using Microsoft.Data.Common.ConnectionString;

namespace Microsoft.Data.SqlClient
{
Expand Down Expand Up @@ -112,7 +113,7 @@ public override void GetObjectData(SerializationInfo si, StreamingContext contex
public byte State => Errors.Count > 0 ? Errors[0].State : default;

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


#if NET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ namespace Microsoft.Data.SqlClient
internal static class TdsEnums
{
// internal tdsparser constants


public const string SQL_PROVIDER_NAME = DbConnectionStringDefaults.ApplicationName;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary level of indirection here, so removing this in favour of ApplicationName.


public static readonly decimal SQL_SMALL_MONEY_MIN = new(-214748.3648);
public static readonly decimal SQL_SMALL_MONEY_MAX = new(214748.3647);

Expand Down Expand Up @@ -987,9 +983,6 @@ internal enum FedAuthInfoId : byte
internal const byte MAX_SUPPORTED_VECTOR_VERSION = 0x01;
internal const int VECTOR_HEADER_SIZE = 8;

// User Agent constants
internal const byte SUPPORTED_USER_AGENT_VERSION = 0x01;

// TCE Related constants
internal const byte MAX_SUPPORTED_TCE_VERSION = 0x03; // max version
internal const byte MIN_TCE_VERSION_WITH_ENCLAVE_SUPPORT = 0x02; // min version with enclave support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
using System.Xml;
using Interop.Common.Sni;
using Microsoft.Data.Common;
using Microsoft.Data.Common.ConnectionString;
using Microsoft.Data.ProviderBase;
using Microsoft.Data.Sql;
using Microsoft.Data.SqlClient.Connection;
using Microsoft.Data.SqlClient.DataClassification;
using Microsoft.Data.SqlClient.LocalDb;
using Microsoft.Data.SqlClient.Server;
using Microsoft.Data.SqlClient.UserAgent;
using Microsoft.Data.SqlClient.Utilities;
using Microsoft.SqlServer.Server;

Expand Down Expand Up @@ -1305,11 +1305,11 @@ internal void TdsLogin(
// length in bytes
int length = TdsEnums.SQL2005_LOG_REC_FIXED_LEN;

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

// add up variable-len portions (multiply by 2 for byte len of char strings)
//
checked
{
length += (rec.hostName.Length + rec.applicationName.Length +
Expand Down Expand Up @@ -1364,7 +1364,7 @@ internal void TdsLogin(
requestedFeatures,
recoverySessionData,
fedAuthFeatureExtensionData,
UserAgentInfo.UserAgentCachedJsonPayload.ToArray(),
UserAgent.Ucs2Bytes,
useFeatureExt,
length
);
Expand Down Expand Up @@ -9172,43 +9172,41 @@ internal int WriteVectorSupportFeatureRequest(bool write)
}

/// <summary>
/// Writes the User Agent feature request to the physical state object.
/// The request includes the feature ID, feature data length, version number and encoded JSON payload.
/// Writes the User Agent feature request to the physical state
/// object. The request includes the feature ID, feature data length,
/// and UCS-2 little-endian encoded payload.
/// </summary>
/// <param name="userAgentJsonPayload"> Byte array of UTF-8 encoded JSON payload for User Agent</param>
/// <remarks>
/// The feature request consists of:
/// - 1 byte for the feature ID.
/// - 4 bytes for the feature data length.
/// - N bytes for the UCS-2 payload
/// </remarks>
/// <param name="userAgent">
/// UCS-2 little-endian encoded UserAgent payload.
/// </param>
/// <param name="write">
/// If true, writes the feature request to the physical state object.
/// If false, just calculates the length.
/// If true, writes the feature request to the physical state object.
/// If false, just calculates the length.
/// </param>
/// <returns>The length of the feature request in bytes.</returns>
/// <remarks>
/// The feature request consists of:
/// - 1 byte for the feature ID.
/// - 4 bytes for the feature data length.
/// - 1 byte for the version number.
/// - N bytes for the JSON payload
/// </remarks>
internal int WriteUserAgentFeatureRequest(byte[] userAgentJsonPayload,
internal int WriteUserAgentFeatureRequest(ReadOnlyMemory<byte> userAgent,
bool write)
{
// 1byte (Feature Version) + size of UTF-8 encoded JSON payload
int dataLen = 1 + userAgentJsonPayload.Length;
// 1byte (Feature ID) + 4bytes (Feature Data Length) + 1byte (Version) + N(JSON payload size)
int totalLen = 1 + 4 + dataLen;
// 1 byte (Feature ID) + 4 bytes (Feature Data Length) + N bytes
// (UCS-2 payload size)
int totalLen = 1 + 4 + userAgent.Length;

if (write)
{
// Write Feature ID
_physicalStateObj.WriteByte(TdsEnums.FEATUREEXT_USERAGENT);

// Feature Data Length
WriteInt(dataLen, _physicalStateObj);

// Write Feature Version
_physicalStateObj.WriteByte(TdsEnums.SUPPORTED_USER_AGENT_VERSION);
WriteInt(userAgent.Length, _physicalStateObj);

// Write encoded JSON payload
_physicalStateObj.WriteByteArray(userAgentJsonPayload, userAgentJsonPayload.Length, 0);
// Write encoded UCS-2 payload
_physicalStateObj.WriteByteSpan(userAgent.Span);
}

return totalLen;
Expand Down Expand Up @@ -9488,7 +9486,7 @@ private void WriteLoginData(SqlLogin rec,
requestedFeatures,
recoverySessionData,
fedAuthFeatureExtensionData,
UserAgentInfo.UserAgentCachedJsonPayload.ToArray(),
UserAgent.Ucs2Bytes,
useFeatureExt,
length,
true
Expand All @@ -9511,7 +9509,7 @@ private void WriteLoginData(SqlLogin rec,
private int ApplyFeatureExData(TdsEnums.FeatureExtension requestedFeatures,
SessionData recoverySessionData,
FederatedAuthenticationFeatureExtensionData fedAuthFeatureExtensionData,
byte[] userAgentJsonPayload,
ReadOnlyMemory<byte> userAgent,
bool useFeatureExt,
int length,
bool write = false)
Expand All @@ -9523,7 +9521,7 @@ private int ApplyFeatureExData(TdsEnums.FeatureExtension requestedFeatures,
// NOTE: As part of TDS spec UserAgent feature extension should be the first feature extension in the list.
if (LocalAppContextSwitches.EnableUserAgent && ((requestedFeatures & TdsEnums.FeatureExtension.UserAgent) != 0))
{
length += WriteUserAgentFeatureRequest(userAgentJsonPayload, write);
length += WriteUserAgentFeatureRequest(userAgent, write);
}
if ((requestedFeatures & TdsEnums.FeatureExtension.SessionRecovery) != 0)
{
Expand Down
Loading
Loading