2011-08-04 20:32:01 +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-08-04 20:32:01 +00:00
|
|
|
|
2020-10-31 21:07:32 +00:00
|
|
|
const LDAPMessage = require('./message')
|
|
|
|
const Change = require('../change')
|
|
|
|
const Protocol = require('../protocol')
|
|
|
|
const lassert = require('../assert')
|
2014-09-30 23:39:19 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
/// --- API
|
2014-09-30 23:39:19 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
function ModifyRequest (options) {
|
|
|
|
options = options || {}
|
|
|
|
assert.object(options)
|
|
|
|
lassert.optionalStringDN(options.object)
|
|
|
|
lassert.optionalArrayOfAttribute(options.attributes)
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
options.protocolOp = Protocol.LDAP_REQ_MODIFY
|
|
|
|
LDAPMessage.call(this, options)
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
this.object = options.object || null
|
|
|
|
this.changes = options.changes ? options.changes.slice(0) : []
|
2011-08-04 20:32:01 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
util.inherits(ModifyRequest, LDAPMessage)
|
2015-10-31 17:28:25 +00:00
|
|
|
Object.defineProperties(ModifyRequest.prototype, {
|
|
|
|
type: {
|
2019-08-27 21:11:49 +00:00
|
|
|
get: function getType () { return 'ModifyRequest' },
|
2015-10-31 17:28:25 +00:00
|
|
|
configurable: false
|
|
|
|
},
|
|
|
|
_dn: {
|
2019-08-27 21:11:49 +00:00
|
|
|
get: function getDN () { return this.object },
|
2015-10-31 17:28:25 +00:00
|
|
|
configurable: false
|
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
ModifyRequest.prototype._parse = function (ber) {
|
2019-08-27 21:11:49 +00:00
|
|
|
assert.ok(ber)
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
this.object = ber.readString()
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
ber.readSequence()
|
2020-10-31 21:07:32 +00:00
|
|
|
const end = ber.offset + ber.length
|
2011-08-04 20:32:01 +00:00
|
|
|
while (ber.offset < end) {
|
2020-10-31 21:07:32 +00:00
|
|
|
const c = new Change()
|
2019-08-27 21:11:49 +00:00
|
|
|
c.parse(ber)
|
|
|
|
c.modification.type = c.modification.type.toLowerCase()
|
|
|
|
this.changes.push(c)
|
2011-08-04 20:32:01 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
this.changes.sort(Change.compare)
|
|
|
|
return true
|
|
|
|
}
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
ModifyRequest.prototype._toBer = function (ber) {
|
2019-08-27 21:11:49 +00:00
|
|
|
assert.ok(ber)
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
ber.writeString(this.object.toString())
|
|
|
|
ber.startSequence()
|
2012-02-18 08:15:52 +00:00
|
|
|
this.changes.forEach(function (c) {
|
2019-08-27 21:11:49 +00:00
|
|
|
c.toBer(ber)
|
|
|
|
})
|
|
|
|
ber.endSequence()
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
return ber
|
|
|
|
}
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
ModifyRequest.prototype._json = function (j) {
|
2019-08-27 21:11:49 +00:00
|
|
|
assert.ok(j)
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
j.object = this.object
|
|
|
|
j.changes = []
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
this.changes.forEach(function (c) {
|
2019-08-27 21:11:49 +00:00
|
|
|
j.changes.push(c.json)
|
|
|
|
})
|
2015-10-31 17:28:25 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
return j
|
|
|
|
}
|
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 = ModifyRequest
|