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 LDAPResult = require('./result');
|
|
|
|
|
|
|
|
var dn = require('../dn');
|
|
|
|
var Protocol = require('../protocol');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///--- API
|
|
|
|
|
|
|
|
function CompareRequest(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');
|
|
|
|
if (options.entry && !(options.entry instanceof dn.DN))
|
|
|
|
throw new TypeError('options.entry must be a DN');
|
2012-02-18 08:15:52 +00:00
|
|
|
if (options.attribute && typeof (options.attribute) !== 'string')
|
2011-08-04 20:32:01 +00:00
|
|
|
throw new TypeError('options.attribute must be a string');
|
2012-02-18 08:15:52 +00:00
|
|
|
if (options.value && typeof (options.value) !== 'string')
|
2011-08-04 20:32:01 +00:00
|
|
|
throw new TypeError('options.value must be a string');
|
|
|
|
} else {
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
options.protocolOp = Protocol.LDAP_REQ_COMPARE;
|
|
|
|
LDAPMessage.call(this, options);
|
|
|
|
|
|
|
|
this.entry = options.entry || null;
|
|
|
|
this.attribute = options.attribute || '';
|
|
|
|
this.value = options.value || '';
|
|
|
|
|
|
|
|
var self = this;
|
2012-02-18 08:15:52 +00:00
|
|
|
this.__defineGetter__('type', function () { return 'CompareRequest'; });
|
|
|
|
this.__defineGetter__('_dn', function () {
|
2011-08-04 20:32:01 +00:00
|
|
|
return self.entry ? self.entry.toString() : '';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
util.inherits(CompareRequest, LDAPMessage);
|
|
|
|
module.exports = CompareRequest;
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
CompareRequest.prototype._parse = function (ber) {
|
2011-08-04 20:32:01 +00:00
|
|
|
assert.ok(ber);
|
|
|
|
|
|
|
|
this.entry = dn.parse(ber.readString());
|
|
|
|
|
|
|
|
ber.readSequence();
|
2011-08-12 23:37:47 +00:00
|
|
|
this.attribute = ber.readString().toLowerCase();
|
2011-08-04 20:32:01 +00:00
|
|
|
this.value = ber.readString();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
CompareRequest.prototype._toBer = function (ber) {
|
2011-08-04 20:32:01 +00:00
|
|
|
assert.ok(ber);
|
|
|
|
|
|
|
|
ber.writeString(this.entry.toString());
|
|
|
|
ber.startSequence();
|
|
|
|
ber.writeString(this.attribute);
|
|
|
|
ber.writeString(this.value);
|
|
|
|
ber.endSequence();
|
|
|
|
|
|
|
|
return ber;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
CompareRequest.prototype._json = function (j) {
|
2011-08-04 20:32:01 +00:00
|
|
|
assert.ok(j);
|
|
|
|
|
|
|
|
j.entry = this.entry.toString();
|
|
|
|
j.attribute = this.attribute;
|
|
|
|
j.value = this.value;
|
|
|
|
|
|
|
|
return j;
|
|
|
|
};
|