2011-08-04 20:32:01 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
|
|
|
var assert = require('assert');
|
|
|
|
var util = require('util');
|
|
|
|
|
|
|
|
var LDAPMessage = require('./message');
|
|
|
|
var dn = require('../dn');
|
|
|
|
var Protocol = require('../protocol');
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-30 23:39:19 +00:00
|
|
|
///--- Globals
|
|
|
|
|
|
|
|
var isDN = dn.DN.isDN;
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
///--- API
|
|
|
|
|
|
|
|
function DeleteRequest(options) {
|
|
|
|
if (options) {
|
2012-02-18 08:15:52 +00:00
|
|
|
if (typeof (options) !== 'object')
|
2011-08-04 20:32:01 +00:00
|
|
|
throw new TypeError('options must be an object');
|
2014-09-30 23:39:19 +00:00
|
|
|
if (options.entry &&
|
|
|
|
!(isDN(options.entry) || typeof (options.entry) === 'string')) {
|
|
|
|
throw new TypeError('options.entry must be a DN or string');
|
|
|
|
}
|
2011-08-04 20:32:01 +00:00
|
|
|
} else {
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
options.protocolOp = Protocol.LDAP_REQ_DELETE;
|
|
|
|
LDAPMessage.call(this, options);
|
|
|
|
|
|
|
|
this.entry = options.entry || null;
|
|
|
|
|
|
|
|
var self = this;
|
2012-02-18 08:15:52 +00:00
|
|
|
this.__defineGetter__('type', function () { return 'DeleteRequest'; });
|
|
|
|
this.__defineGetter__('_dn', function () { return self.entry; });
|
2011-08-04 20:32:01 +00:00
|
|
|
}
|
|
|
|
util.inherits(DeleteRequest, LDAPMessage);
|
|
|
|
module.exports = DeleteRequest;
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
DeleteRequest.prototype._parse = function (ber, length) {
|
2011-08-04 20:32:01 +00:00
|
|
|
assert.ok(ber);
|
|
|
|
|
2014-09-30 23:39:19 +00:00
|
|
|
this.entry = ber.buffer.slice(0, length).toString('utf8');
|
2011-08-12 23:37:47 +00:00
|
|
|
ber._offset += ber.length;
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
DeleteRequest.prototype._toBer = function (ber) {
|
2011-08-04 20:32:01 +00:00
|
|
|
assert.ok(ber);
|
|
|
|
|
|
|
|
var buf = new Buffer(this.entry.toString());
|
|
|
|
for (var i = 0; i < buf.length; i++)
|
|
|
|
ber.writeByte(buf[i]);
|
|
|
|
|
|
|
|
return ber;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
DeleteRequest.prototype._json = function (j) {
|
2011-08-04 20:32:01 +00:00
|
|
|
assert.ok(j);
|
|
|
|
|
|
|
|
j.entry = this.entry;
|
|
|
|
|
|
|
|
return j;
|
|
|
|
};
|