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