<commit_before>buildBuffer = require('./build-buffer')
require('buffertools')
os= require('os')
sprintf = require('sprintf').sprintf
libraryName = require('./tedious').libraryName

FLAGS_1 =
  ENDIAN_LITTLE: 0x00,
  ENDIAN_BIG: 0x01,
  
  CHARSET_ASCII: 0x00,
  CHARSET_EBCDIC: 0x02,
  
  FLOAT_IEEE_754: 0x00,
  FLOAT_VAX: 0x04,
  FLOAT_ND5000: 0x08,
  
  BCP_DUMPLOAD_ON: 0x00,
  BCP_DUMPLOAD_OFF: 0x10,
  
  USE_DB_ON: 0x00,
  USE_DB_OFF: 0x20,
  
  INIT_DB_WARN: 0x00,
  INIT_DB_FATAL: 0x40,
  
  SET_LANG_WARN_OFF: 0x00,
  SET_LANG_WARN_ON: 0x80,

FLAGS_2 = 
  INIT_LANG_WARN: 0x00,
  INIT_LANG_FATAL: 0x01,

  ODBC_OFF: 0x00,
  ODBC_ON: 0x02,
  
  F_TRAN_BOUNDARY: 0x04,          # Removed in TDS 7.2
  
  F_CACHE_CONNECT: 0x08,          # Removed in TDS 7.2
  
  USER_NORMAL: 0x00,
  USER_SERVER: 0x10, 
  USER_REMUSER: 0x20, 
  USER_SQLREPL: 0x40, 
  
  INTEGRATED_SECURITY_OFF: 0x00,
  INTEGRATED_SECURITY_ON: 0x80

TYPE_FLAGS =
  SQL_DFLT: 0x00,
  SQL_TSQL: 0x01,
  
  OLEDB_OFF: 0x00,
  OLEDB_ON: 0x02,                 # Introduced in TDS 7.2

  READ_ONLY_INTENT: 0x04          # Introduced in TDS 7.4

FLAGS_3 =
  CHANGE_PASSWORD_NO: 0x00,
  CHANGE_PASSWORD_YES: 0x01,      # Introduced in TDS 7.2
  
  BINARY_XML: 0x02,               # Introduced in TDS 7.2
  
  SPAWN_USER_INSTANCE: 0x04,      # Introduced in TDS 7.2

  UNKNOWN_COLLATION_HANDLING: 0x08  # Introduced in TDS 7.3

TDS_VERSION_7_2 = 0x72090002
TDS_VERSION_7_3_A = 0x730A0003
TDS_VERSION_7_3_B = 0x730B0003
DEFAULT_TDS_VERSION = TDS_VERSION_7_2

DEFAULT_PACKET_SIZE = 4 * 1024

###
  s2.2.6.3
###
class Login7Payload
  constructor: (@loginData) ->
    lengthLength = 4

    fixed = @createFixedData()
    variable = @createVariableData(lengthLength + fixed.length)
    length = buildBuffer('U32', lengthLength + fixed.length + variable.length)

    @data = new Buffer(length.concat(fixed, variable))
    console.log(@data.length, @data)

  createFixedData: ->
    @tdsVersion = DEFAULT_TDS_VERSION
    @packetSize = DEFAULT_PACKET_SIZE
    @clientProgVer = 0
    @clientPid = process.pid
    @connectionId = 0
    @clientTimeZone = new Date().getTimezoneOffset()
    @clientLcid = 5                #Can't figure what form this should take.

    @flags1 =
      FLAGS_1.ENDIAN_LITTLE |
      FLAGS_1.CHARSET_ASCII |
      FLAGS_1.FLOAT_IEEE_754 |
      FLAGS_1.BCD_DUMPLOAD_OFF |
      FLAGS_1.USE_DB_OFF |
      FLAGS_1.INIT_DB_WARN |
      FLAGS_1.SET_LANG_WARN_ON

    @flags2 =
      FLAGS_2.INIT_LANG_WARN |
      FLAGS_2.ODBC_OFF |
      FLAGS_2.USER_NORMAL |
      FLAGS_2.INTEGRATED_SECURITY_OFF

    @flags3 =
      FLAGS_3.CHANGE_PASSWORD_NO |
      FLAGS_3.UNKNOWN_COLLATION_HANDLING<commit_msg>Remove console.log .<commit_after>buildBuffer = require('./build-buffer')
require('buffertools')
os= require('os')
sprintf = require('sprintf').sprintf
libraryName = require('./tedious').libraryName

FLAGS_1 =
  ENDIAN_LITTLE: 0x00,
  ENDIAN_BIG: 0x01,
  
  CHARSET_ASCII: 0x00,
  CHARSET_EBCDIC: 0x02,
  
  FLOAT_IEEE_754: 0x00,
  FLOAT_VAX: 0x04,
  FLOAT_ND5000: 0x08,
  
  BCP_DUMPLOAD_ON: 0x00,
  BCP_DUMPLOAD_OFF: 0x10,
  
  USE_DB_ON: 0x00,
  USE_DB_OFF: 0x20,
  
  INIT_DB_WARN: 0x00,
  INIT_DB_FATAL: 0x40,
  
  SET_LANG_WARN_OFF: 0x00,
  SET_LANG_WARN_ON: 0x80,

FLAGS_2 = 
  INIT_LANG_WARN: 0x00,
  INIT_LANG_FATAL: 0x01,

  ODBC_OFF: 0x00,
  ODBC_ON: 0x02,
  
  F_TRAN_BOUNDARY: 0x04,          # Removed in TDS 7.2
  
  F_CACHE_CONNECT: 0x08,          # Removed in TDS 7.2
  
  USER_NORMAL: 0x00,
  USER_SERVER: 0x10, 
  USER_REMUSER: 0x20, 
  USER_SQLREPL: 0x40, 
  
  INTEGRATED_SECURITY_OFF: 0x00,
  INTEGRATED_SECURITY_ON: 0x80

TYPE_FLAGS =
  SQL_DFLT: 0x00,
  SQL_TSQL: 0x01,
  
  OLEDB_OFF: 0x00,
  OLEDB_ON: 0x02,                 # Introduced in TDS 7.2

  READ_ONLY_INTENT: 0x04          # Introduced in TDS 7.4

FLAGS_3 =
  CHANGE_PASSWORD_NO: 0x00,
  CHANGE_PASSWORD_YES: 0x01,      # Introduced in TDS 7.2
  
  BINARY_XML: 0x02,               # Introduced in TDS 7.2
  
  SPAWN_USER_INSTANCE: 0x04,      # Introduced in TDS 7.2

  UNKNOWN_COLLATION_HANDLING: 0x08  # Introduced in TDS 7.3

TDS_VERSION_7_2 = 0x72090002
TDS_VERSION_7_3_A = 0x730A0003
TDS_VERSION_7_3_B = 0x730B0003
DEFAULT_TDS_VERSION = TDS_VERSION_7_2

DEFAULT_PACKET_SIZE = 4 * 1024

###
  s2.2.6.3
###
class Login7Payload
  constructor: (@loginData) ->
    lengthLength = 4

    fixed = @createFixedData()
    variable = @createVariableData(lengthLength + fixed.length)
    length = buildBuffer('U32', lengthLength + fixed.length + variable.length)

    @data = new Buffer(length.concat(fixed, variable))

  createFixedData: ->
    @tdsVersion = DEFAULT_TDS_VERSION
    @packetSize = DEFAULT_PACKET_SIZE
    @clientProgVer = 0
    @clientPid = process.pid
    @connectionId = 0
    @clientTimeZone = new Date().getTimezoneOffset()
    @clientLcid = 5                #Can't figure what form this should take.

    @flags1 =
      FLAGS_1.ENDIAN_LITTLE |
      FLAGS_1.CHARSET_ASCII |
      FLAGS_1.FLOAT_IEEE_754 |
      FLAGS_1.BCD_DUMPLOAD_OFF |
      FLAGS_1.USE_DB_OFF |
      FLAGS_1.INIT_DB_WARN |
      FLAGS_1.SET_LANG_WARN_ON

    @flags2 =
      FLAGS_2.INIT_LANG_WARN |
      FLAGS_2.ODBC_OFF |
      FLAGS_2.USER_NORMAL |
      FLAGS_2.INTEGRATED_SECURITY_OFF

    @flags3 =
      FLAGS_3.CHANGE_PASSWORD_NO |
      FLAGS_3.UNKNOWN_COLLATION_HANDLING
{'fraction_non_alphanumeric': 0.08789355322338831, 'fraction_numerical': 0.07683658170914542, 'mean_word_length': 3.1148804934464147, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '87535', 'n_tokens_mistral': 2608, 'n_tokens_neox': 2251, 'n_words': 383}