2011-11-07 22:13:53 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
var assert = require('assert-plus')
|
|
|
|
var util = require('util')
|
2011-11-07 22:13:53 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
var LDAPMessage = require('./message')
|
|
|
|
var Protocol = require('../protocol')
|
2011-11-07 22:13:53 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
/// --- API
|
2011-11-07 22:13:53 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
function AbandonRequest (options) {
|
|
|
|
options = options || {}
|
|
|
|
assert.object(options)
|
|
|
|
assert.optionalNumber(options.abandonID)
|
2011-11-07 22:13:53 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
options.protocolOp = Protocol.LDAP_REQ_ABANDON
|
|
|
|
LDAPMessage.call(this, options)
|
2011-11-07 22:13:53 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
this.abandonID = options.abandonID || 0
|
2011-11-07 22:13:53 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
util.inherits(AbandonRequest, LDAPMessage)
|
2015-10-31 17:28:25 +00:00
|
|
|
Object.defineProperties(AbandonRequest.prototype, {
|
|
|
|
type: {
|
2019-08-27 21:11:49 +00:00
|
|
|
get: function getType () { return 'AbandonRequest' },
|
2015-10-31 17:28:25 +00:00
|
|
|
configurable: false
|
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
2011-11-07 22:13:53 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
AbandonRequest.prototype._parse = function (ber, length) {
|
2019-08-27 21:11:49 +00:00
|
|
|
assert.ok(ber)
|
|
|
|
assert.ok(length)
|
2011-11-07 22:13:53 +00:00
|
|
|
|
|
|
|
// What a PITA - have to replicate ASN.1 integer logic to work around the
|
|
|
|
// way abandon is encoded and the way ldapjs framework handles "normal"
|
|
|
|
// messages
|
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
var buf = ber.buffer
|
|
|
|
var offset = 0
|
|
|
|
var value = 0
|
2011-11-07 22:13:53 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
var fb = buf[offset++]
|
|
|
|
value = fb & 0x7F
|
2011-11-07 22:13:53 +00:00
|
|
|
for (var i = 1; i < length; i++) {
|
2019-08-27 21:11:49 +00:00
|
|
|
value <<= 8
|
|
|
|
value |= (buf[offset++] & 0xff)
|
2011-11-07 22:13:53 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
if ((fb & 0x80) === 0x80) { value = -value }
|
2011-11-07 22:13:53 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
ber._offset += length
|
2011-11-07 22:13:53 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
this.abandonID = value
|
2011-11-07 22:13:53 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
return true
|
|
|
|
}
|
2011-11-07 22:13:53 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
AbandonRequest.prototype._toBer = function (ber) {
|
2019-08-27 21:11:49 +00:00
|
|
|
assert.ok(ber)
|
2011-11-07 22:13:53 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
var i = this.abandonID
|
|
|
|
var sz = 4
|
2011-11-07 22:13:53 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
while ((((i & 0xff800000) === 0) || ((i & 0xff800000) === 0xff800000)) &&
|
2011-11-07 22:13:53 +00:00
|
|
|
(sz > 1)) {
|
2019-08-27 21:11:49 +00:00
|
|
|
sz--
|
|
|
|
i <<= 8
|
2011-11-07 22:13:53 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
assert.ok(sz <= 4)
|
2011-11-07 22:13:53 +00:00
|
|
|
|
|
|
|
while (sz-- > 0) {
|
2019-08-27 21:11:49 +00:00
|
|
|
ber.writeByte((i & 0xff000000) >> 24)
|
|
|
|
i <<= 8
|
2011-11-07 22:13:53 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
return ber
|
|
|
|
}
|
2011-11-07 22:13:53 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
AbandonRequest.prototype._json = function (j) {
|
2019-08-27 21:11:49 +00:00
|
|
|
assert.ok(j)
|
2011-11-07 22:13:53 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
j.abandonID = this.abandonID
|
2015-10-31 17:28:25 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
return j
|
|
|
|
}
|
2015-10-31 17:28:25 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
/// --- Exports
|
2015-10-31 17:28:25 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
module.exports = AbandonRequest
|