node-ldapjs/lib/messages/modify_request.js

84 lines
1.7 KiB
JavaScript
Raw Normal View History

2011-08-04 20:32:01 +00:00
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus')
var util = require('util')
2011-08-04 20:32:01 +00:00
var LDAPMessage = require('./message')
var Change = require('../change')
var Protocol = require('../protocol')
var lassert = require('../assert')
/// --- API
function ModifyRequest (options) {
options = options || {}
assert.object(options)
lassert.optionalStringDN(options.object)
lassert.optionalArrayOfAttribute(options.attributes)
2011-08-04 20:32:01 +00:00
options.protocolOp = Protocol.LDAP_REQ_MODIFY
LDAPMessage.call(this, options)
2011-08-04 20:32:01 +00:00
this.object = options.object || null
this.changes = options.changes ? options.changes.slice(0) : []
2011-08-04 20:32:01 +00:00
}
util.inherits(ModifyRequest, LDAPMessage)
Object.defineProperties(ModifyRequest.prototype, {
type: {
get: function getType () { return 'ModifyRequest' },
configurable: false
},
_dn: {
get: function getDN () { return this.object },
configurable: false
}
})
2011-08-04 20:32:01 +00:00
ModifyRequest.prototype._parse = function (ber) {
assert.ok(ber)
2011-08-04 20:32:01 +00:00
this.object = ber.readString()
2011-08-04 20:32:01 +00:00
ber.readSequence()
var end = ber.offset + ber.length
2011-08-04 20:32:01 +00:00
while (ber.offset < end) {
var c = new Change()
c.parse(ber)
c.modification.type = c.modification.type.toLowerCase()
this.changes.push(c)
2011-08-04 20:32:01 +00:00
}
this.changes.sort(Change.compare)
return true
}
2011-08-04 20:32:01 +00:00
ModifyRequest.prototype._toBer = function (ber) {
assert.ok(ber)
2011-08-04 20:32:01 +00:00
ber.writeString(this.object.toString())
ber.startSequence()
this.changes.forEach(function (c) {
c.toBer(ber)
})
ber.endSequence()
2011-08-04 20:32:01 +00:00
return ber
}
2011-08-04 20:32:01 +00:00
ModifyRequest.prototype._json = function (j) {
assert.ok(j)
2011-08-04 20:32:01 +00:00
j.object = this.object
j.changes = []
2011-08-04 20:32:01 +00:00
this.changes.forEach(function (c) {
j.changes.push(c.json)
})
return j
}
/// --- Exports
module.exports = ModifyRequest