Skip to content

Commit 8b1d38c

Browse files
authored
Revert "Send user agent info as a new feature extension to server (#2793)" (#2833)
This reverts commit f55f130.
1 parent 0e695fb commit 8b1d38c

File tree

2 files changed

+1
-107
lines changed

2 files changed

+1
-107
lines changed

src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,6 @@ final class TDS {
178178
static final byte TDS_FEATURE_EXT_JSONSUPPORT = 0x0D;
179179
static final byte JSONSUPPORT_NOT_SUPPORTED = 0x00;
180180
static final byte MAX_JSONSUPPORT_VERSION = 0x01;
181-
// User agent telemetry support
182-
static final byte TDS_FEATURE_EXT_USERAGENT = 0x10;
183-
static final byte MAX_USERAGENT_VERSION = 0x01;
184181

185182
static final int TDS_TVP = 0xF3;
186183
static final int TVP_ROW = 0x01;
@@ -254,9 +251,7 @@ static final String getTokenName(int tdsTokenType) {
254251
return "TDS_FEATURE_EXT_VECTORSUPPORT (0x0E)";
255252
case TDS_FEATURE_EXT_JSONSUPPORT:
256253
return "TDS_FEATURE_EXT_JSONSUPPORT (0x0D)";
257-
case TDS_FEATURE_EXT_USERAGENT:
258-
return "TDS_FEATURE_EXT_USERAGENT (0x10)";
259-
254+
260255
default:
261256
return "unknown token (0x" + Integer.toHexString(tdsTokenType).toUpperCase() + ")";
262257
}

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -313,72 +313,6 @@ public String toString() {
313313
**/
314314
private static final Lock sLock = new ReentrantLock();
315315

316-
static final String USER_AGENT_TEMPLATE = "{\"driver\":\"%s\",\"version\":\"%s\",\"os\":{\"type\":\"%s\",\"details\":\"%s\"},\"arch\":\"%s\",\"runtime\":\"%s\"}";
317-
static final String userAgentStr;
318-
319-
static {
320-
userAgentStr = getUserAgent();
321-
}
322-
323-
static String getUserAgent() {
324-
try {
325-
return String.format(
326-
USER_AGENT_TEMPLATE,
327-
"MS-JDBC",
328-
getJDBCVersion(),
329-
getOSType(),
330-
getOSDetails(),
331-
getArchitecture(),
332-
getRuntimeDetails()
333-
);
334-
} catch(Exception e) {
335-
return "{\"driver\":\"MS-JDBC\"}";
336-
}
337-
}
338-
339-
static String getJDBCVersion() {
340-
return sanitizeField(SQLJdbcVersion.MAJOR + "." + SQLJdbcVersion.MINOR + "." + SQLJdbcVersion.PATCH + "." + SQLJdbcVersion.BUILD + SQLJdbcVersion.RELEASE_EXT, 16);
341-
}
342-
343-
static String getOSType() {
344-
String osName = System.getProperty("os.name", "Unknown").trim();
345-
String osNameToReturn = "Unknown";
346-
if (osName.startsWith("Windows")) {
347-
osNameToReturn = "Windows";
348-
} else if (osName.startsWith("Linux")) {
349-
osNameToReturn = "Linux";
350-
} else if (osName.startsWith("Mac")) {
351-
osNameToReturn = "macOS";
352-
} else if (osName.startsWith("FreeBSD")) {
353-
osNameToReturn = "FreeBSD";
354-
} else if (osName.startsWith("Android")) {
355-
osNameToReturn = "Android";
356-
}
357-
return sanitizeField(osNameToReturn, 16);
358-
}
359-
360-
static String getArchitecture() {
361-
return sanitizeField(System.getProperty("os.arch", "Unknown").trim(), 16);
362-
}
363-
364-
static String getOSDetails() {
365-
String osName = System.getProperty("os.name", "").trim();
366-
String osVersion = System.getProperty("os.version", "").trim();
367-
if (osName.isEmpty() && osVersion.isEmpty()) return "Unknown";
368-
return sanitizeField(osName + " " + osVersion, 128);
369-
}
370-
371-
static String getRuntimeDetails() {
372-
String javaVmName = System.getProperty("java.vm.name", "").trim();
373-
String javaVmVersion = System.getProperty("java.vm.version", "").trim();
374-
if (javaVmName.isEmpty() && javaVmVersion.isEmpty()) return "Unknown";
375-
return sanitizeField(javaVmName + " " + javaVmVersion, 128);
376-
}
377-
378-
static String sanitizeField(String field, int maxLength) {
379-
return (field == null || field.isEmpty()) ? "Unknown" : field.substring(0, Math.min(field.length(), maxLength));
380-
}
381-
382316
/**
383317
* Generate a 6 byte random array for netAddress
384318
* As per TDS spec this is a unique clientID (MAC address) used to identify the client.
@@ -5855,28 +5789,6 @@ int writeDNSCacheFeatureRequest(boolean write, /* if false just calculates the l
58555789
return len;
58565790
}
58575791

5858-
/**
5859-
* Writes the user agent telemetry feature request
5860-
* @param write
5861-
* If true, writes the feature request to the physical state object.
5862-
* @param tdsWriter
5863-
* @return
5864-
* The length of the feature request in bytes, or 0 if vectorTypeSupport is "off".
5865-
* @throws SQLServerException
5866-
*/
5867-
int writeUserAgentFeatureRequest(boolean write, /* if false just calculates the length */
5868-
TDSWriter tdsWriter) throws SQLServerException {
5869-
byte[] userAgentToSendBytes = toUCS16(userAgentStr);
5870-
int len = userAgentToSendBytes.length + 6; // 1byte = featureID, 1byte = version, 4byte = feature data length in bytes, remaining bytes: feature data
5871-
if (write) {
5872-
tdsWriter.writeByte(TDS.TDS_FEATURE_EXT_USERAGENT);
5873-
tdsWriter.writeInt(userAgentToSendBytes.length + 1);
5874-
tdsWriter.writeByte(TDS.MAX_USERAGENT_VERSION);
5875-
tdsWriter.writeBytes(userAgentToSendBytes);
5876-
}
5877-
return len;
5878-
}
5879-
58805792
/**
58815793
* Writes the Vector Support feature request to the physical state object,
58825794
* unless vectorTypeSupport is "off". The request includes the feature ID,
@@ -7131,14 +7043,6 @@ private void onFeatureExtAck(byte featureId, byte[] data) throws SQLServerExcept
71317043
break;
71327044
}
71337045

7134-
case TDS.TDS_FEATURE_EXT_USERAGENT: {
7135-
if (connectionlogger.isLoggable(Level.FINER)) {
7136-
connectionlogger.fine(
7137-
toString() + " Received feature extension acknowledgement for User agent feature extension. Received byte: " + data[0]);
7138-
}
7139-
break;
7140-
}
7141-
71427046
default: {
71437047
// Unknown feature ack
71447048
throw new SQLServerException(SQLServerException.getErrString("R_UnknownFeatureAck"), null);
@@ -7426,9 +7330,6 @@ final boolean complete(LogonCommand logonCommand, TDSReader tdsReader) throws SQ
74267330
}
74277331

74287332
int aeOffset = len;
7429-
7430-
len += writeUserAgentFeatureRequest(false, tdsWriter);
7431-
74327333
// AE is always ON
74337334
len += writeAEFeatureRequest(false, tdsWriter);
74347335
if (federatedAuthenticationInfoRequested || federatedAuthenticationRequested) {
@@ -7633,8 +7534,6 @@ final boolean complete(LogonCommand logonCommand, TDSReader tdsReader) throws SQ
76337534
tdsWriter.writeBytes(secBlob, 0, secBlob.length);
76347535
}
76357536

7636-
writeUserAgentFeatureRequest(true, tdsWriter);
7637-
76387537
// AE is always ON
76397538
writeAEFeatureRequest(true, tdsWriter);
76407539

0 commit comments

Comments
 (0)