2011-09-27 18:49:33 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
2015-10-31 17:28:25 +00:00
|
|
|
var assert = require('assert-plus');
|
2011-09-27 18:49:33 +00:00
|
|
|
var util = require('util');
|
|
|
|
|
|
|
|
var asn1 = require('asn1');
|
|
|
|
|
|
|
|
var LDAPMessage = require('./message');
|
|
|
|
var Protocol = require('../protocol');
|
|
|
|
var dn = require('../dn');
|
|
|
|
var url = require('../url');
|
|
|
|
|
|
|
|
|
|
|
|
///--- Globals
|
|
|
|
|
|
|
|
var BerWriter = asn1.BerWriter;
|
|
|
|
var parseURL = url.parse;
|
|
|
|
|
|
|
|
|
|
|
|
///--- API
|
|
|
|
|
|
|
|
function SearchReference(options) {
|
2015-10-31 17:28:25 +00:00
|
|
|
options = options || {};
|
|
|
|
assert.object(options);
|
2011-09-27 18:49:33 +00:00
|
|
|
|
|
|
|
options.protocolOp = Protocol.LDAP_REP_SEARCH_REF;
|
|
|
|
LDAPMessage.call(this, options);
|
|
|
|
|
|
|
|
this.uris = options.uris || [];
|
|
|
|
}
|
|
|
|
util.inherits(SearchReference, LDAPMessage);
|
2015-10-31 17:28:25 +00:00
|
|
|
Object.defineProperties(SearchReference.prototype, {
|
|
|
|
type: {
|
|
|
|
get: function getType() { return 'SearchReference'; },
|
|
|
|
configurable: false
|
|
|
|
},
|
|
|
|
_dn: {
|
|
|
|
get: function getDN() { return new dn.DN(''); },
|
|
|
|
configurable: false
|
|
|
|
},
|
|
|
|
object: {
|
|
|
|
get: function getObject() {
|
|
|
|
return {
|
|
|
|
dn: this.dn.toString(),
|
|
|
|
uris: this.uris.slice()
|
|
|
|
};
|
|
|
|
},
|
|
|
|
configurable: false
|
|
|
|
},
|
|
|
|
urls: {
|
|
|
|
get: function getUrls() { return this.uris; },
|
|
|
|
set: function setUrls(val) {
|
|
|
|
assert.ok(val);
|
|
|
|
assert.ok(Array.isArray(val));
|
|
|
|
this.uris = val.slice();
|
|
|
|
},
|
|
|
|
configurable: false
|
|
|
|
}
|
|
|
|
});
|
2011-09-27 18:49:33 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
SearchReference.prototype.toObject = function () {
|
2011-09-27 18:49:33 +00:00
|
|
|
return this.object;
|
|
|
|
};
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
SearchReference.prototype.fromObject = function (obj) {
|
|
|
|
if (typeof (obj) !== 'object')
|
2011-09-27 18:49:33 +00:00
|
|
|
throw new TypeError('object required');
|
|
|
|
|
|
|
|
this.uris = obj.uris ? obj.uris.slice() : [];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
SearchReference.prototype._json = function (j) {
|
2011-09-27 18:49:33 +00:00
|
|
|
assert.ok(j);
|
|
|
|
j.uris = this.uris.slice();
|
|
|
|
return j;
|
|
|
|
};
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
SearchReference.prototype._parse = function (ber, length) {
|
2011-09-27 18:49:33 +00:00
|
|
|
assert.ok(ber);
|
|
|
|
|
|
|
|
while (ber.offset < length) {
|
|
|
|
var _url = ber.readString();
|
|
|
|
parseURL(_url);
|
|
|
|
this.uris.push(_url);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
SearchReference.prototype._toBer = function (ber) {
|
2011-09-27 18:49:33 +00:00
|
|
|
assert.ok(ber);
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
this.uris.forEach(function (u) {
|
2011-09-27 18:49:33 +00:00
|
|
|
ber.writeString(u.href || u);
|
|
|
|
});
|
|
|
|
|
|
|
|
return ber;
|
|
|
|
};
|
2015-10-31 17:28:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
///--- Exports
|
|
|
|
|
|
|
|
module.exports = SearchReference;
|