2011-11-07 22:13:53 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
2015-10-31 17:28:25 +00:00
|
|
|
var assert = require('assert-plus');
|
2011-11-07 22:13:53 +00:00
|
|
|
var util = require('util');
|
|
|
|
|
|
|
|
var LDAPMessage = require('./message');
|
|
|
|
var Protocol = require('../protocol');
|
|
|
|
|
|
|
|
|
|
|
|
///--- API
|
|
|
|
|
|
|
|
function AbandonRequest(options) {
|
2015-10-31 17:28:25 +00:00
|
|
|
options = options || {};
|
|
|
|
assert.object(options);
|
|
|
|
assert.optionalNumber(options.abandonID);
|
2011-11-07 22:13:53 +00:00
|
|
|
|
|
|
|
options.protocolOp = Protocol.LDAP_REQ_ABANDON;
|
|
|
|
LDAPMessage.call(this, options);
|
|
|
|
|
|
|
|
this.abandonID = options.abandonID || 0;
|
|
|
|
}
|
|
|
|
util.inherits(AbandonRequest, LDAPMessage);
|
2015-10-31 17:28:25 +00:00
|
|
|
Object.defineProperties(AbandonRequest.prototype, {
|
|
|
|
type: {
|
|
|
|
get: function getType() { return 'AbandonRequest'; },
|
|
|
|
configurable: false
|
|
|
|
}
|
|
|
|
});
|
2011-11-07 22:13:53 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
AbandonRequest.prototype._parse = function (ber, length) {
|
2011-11-07 22:13:53 +00:00
|
|
|
assert.ok(ber);
|
|
|
|
assert.ok(length);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
var buf = ber.buffer;
|
|
|
|
var offset = 0;
|
|
|
|
var value = 0;
|
|
|
|
|
|
|
|
var fb = buf[offset++];
|
|
|
|
value = fb & 0x7F;
|
|
|
|
for (var i = 1; i < length; i++) {
|
|
|
|
value <<= 8;
|
|
|
|
value |= (buf[offset++] & 0xff);
|
|
|
|
}
|
|
|
|
if ((fb & 0x80) == 0x80)
|
|
|
|
value = -value;
|
|
|
|
|
|
|
|
ber._offset += length;
|
|
|
|
|
|
|
|
this.abandonID = value;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
AbandonRequest.prototype._toBer = function (ber) {
|
2011-11-07 22:13:53 +00:00
|
|
|
assert.ok(ber);
|
|
|
|
|
|
|
|
var i = this.abandonID;
|
|
|
|
var sz = 4;
|
|
|
|
|
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)) {
|
|
|
|
sz--;
|
|
|
|
i <<= 8;
|
|
|
|
}
|
|
|
|
assert.ok(sz <= 4);
|
|
|
|
|
|
|
|
while (sz-- > 0) {
|
|
|
|
ber.writeByte((i & 0xff000000) >> 24);
|
|
|
|
i <<= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ber;
|
|
|
|
};
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
AbandonRequest.prototype._json = function (j) {
|
2011-11-07 22:13:53 +00:00
|
|
|
assert.ok(j);
|
|
|
|
|
|
|
|
j.abandonID = this.abandonID;
|
|
|
|
|
|
|
|
return j;
|
|
|
|
};
|
2015-10-31 17:28:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
///--- Exports
|
|
|
|
|
|
|
|
module.exports = AbandonRequest;
|