diff src/main/java/org/monetdb/mcl/net/MapiSocket.java @ 422:8368cbc670bf

Send reply size and time zone during initial handshake
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Tue, 02 Feb 2021 13:50:13 +0100 (2021-02-02)
parents bf9f6b6ecf40
children 788984342ae3
line wrap: on
line diff
--- a/src/main/java/org/monetdb/mcl/net/MapiSocket.java
+++ b/src/main/java/org/monetdb/mcl/net/MapiSocket.java
@@ -122,6 +122,9 @@ public class MapiSocket {	/* cannot (yet
 	/** A short in two bytes for holding the block size in bytes */
 	private final byte[] blklen = new byte[2];
 
+	/** Options that can be sent during the auth handshake if the server supports it */
+	private HandshakeOptions handshakeOptions;
+
 	/**
 	 * Constructs a new MapiSocket.
 	 */
@@ -533,11 +536,33 @@ public class MapiSocket {	/* cannot (yet
 				}
 
 				// compose and return response
-				return "BIG:"	// JVM byte-order is big-endian
-					+ username + ":"
-					+ pwhash + ":"
-					+ language + ":"
-					+ (database == null ? "" : database) + ":";
+				String response = "BIG:"    // JVM byte-order is big-endian
+						+ username + ":"
+						+ pwhash + ":"
+						+ language + ":"
+						+ (database == null ? "" : database) + ":";
+				if (chaltok.length > 6) {
+					// this ':' delimits the FILETRANS field, currently empty because we don't support it.
+					response += ":";
+
+					// if supported, send handshake options
+					for (String part : chaltok[6].split(",")) {
+						if (part.startsWith("sql=") && handshakeOptions != null) {
+							int level;
+							try {
+								level = Integer.parseInt(chaltok[6].substring(4));
+							} catch (NumberFormatException e) {
+								throw new MCLParseException("Invalid handshake level: " + chaltok[6]);
+							}
+							response += handshakeOptions.formatResponse(level);
+							break;
+						}
+					}
+					// this ':' delimits the handshake options field.
+					response += ":";
+
+				}
+				return response;
 			default:
 				throw new MCLException("Unsupported protocol version: " + version);
 		}
@@ -687,6 +712,14 @@ public class MapiSocket {	/* cannot (yet
 			log.flush();
 	}
 
+	public void setHandshakeOptions(HandshakeOptions handshakeOptions) {
+		this.handshakeOptions = handshakeOptions;
+	}
+
+	public HandshakeOptions getHandshakeOptions() {
+		return handshakeOptions;
+	}
+
 	/**
 	 * Inner class that is used to write data on a normal stream as a
 	 * blocked stream.  A call to the flush() method will write a