Sorted attributes/changes in add/modify requests
This commit is contained in:
parent
7706cd5e4e
commit
05be0dd966
|
@ -40,6 +40,23 @@ function Attribute(options) {
|
|||
module.exports = Attribute;
|
||||
|
||||
|
||||
Attribute.compare = function(a, b) {
|
||||
if (!(a instanceof Attribute) || !(b instanceof Attribute))
|
||||
throw new TypeError('can only compare Attributes');
|
||||
|
||||
if (a.type < b.type) return -1;
|
||||
if (a.type > b.type) return 1;
|
||||
if (a.vals.length < b.vals.length) return -1;
|
||||
if (a.vals.length > b.vals.length) return 1;
|
||||
|
||||
for (var i = 0; i < a.vals.length; i++) {
|
||||
if (a.vals[i] < b.vals[i]) return -1;
|
||||
if (a.vals[i] > b.vals[i]) return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
Attribute.prototype.addValue = function(val) {
|
||||
if (typeof(val) !== 'string')
|
||||
throw new TypeError('val (string) required');
|
||||
|
@ -57,10 +74,9 @@ Attribute.prototype.parse = function(ber) {
|
|||
|
||||
if (ber.readSequence(Protocol.LBER_SET)) {
|
||||
var end = ber.offset + ber.length;
|
||||
while (ber.offset < end) {
|
||||
var val = ber.readString();
|
||||
this.vals.push(val);
|
||||
}
|
||||
while (ber.offset < end)
|
||||
this.vals.push(ber.readString().toLowerCase());
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -79,6 +79,17 @@ function Change(options) {
|
|||
module.exports = Change;
|
||||
|
||||
|
||||
Change.compare = function(a, b) {
|
||||
if (!(a instanceof Change) || !(b instanceof Change))
|
||||
throw new TypeError('can only compare Changes');
|
||||
|
||||
if (a.operation < b.operation) return -1;
|
||||
if (a.operation > b.operation) return 1;
|
||||
|
||||
return Attribute.compare(a.modification, b.modification);
|
||||
};
|
||||
|
||||
|
||||
Change.prototype.parse = function(ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ AddRequest.prototype._parse = function(ber) {
|
|||
this.attributes.push(a);
|
||||
}
|
||||
|
||||
this.attributes.sort(Attribute.compare);
|
||||
return true;
|
||||
};
|
||||
|
||||
|
@ -96,3 +97,25 @@ AddRequest.prototype._json = function(j) {
|
|||
|
||||
return j;
|
||||
};
|
||||
|
||||
|
||||
AddRequest.prototype.indexOf = function(attr) {
|
||||
if (!attr || typeof(attr) !== 'string')
|
||||
throw new TypeError('attr (string) required');
|
||||
|
||||
for (var i = 0; i < this.attributes.length; i++)
|
||||
if (req.attributes[i].type === attr)
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
|
||||
AddRequest.prototype.attributeNames = function() {
|
||||
var attrs = [];
|
||||
|
||||
for (var i = 0; i < this.attributes.length; i++)
|
||||
attrs.push[this.attributes[i].type];
|
||||
|
||||
return attrs;
|
||||
};
|
||||
|
|
|
@ -61,6 +61,7 @@ ModifyRequest.prototype._parse = function(ber) {
|
|||
this.changes.push(c);
|
||||
}
|
||||
|
||||
this.changes.sort(Change.compare);
|
||||
return true;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue