UNPKG

2.14 kBJavaScriptView Raw
1// Copyright 2011 Mark Cavage, Inc. All rights reserved.
2
3const assert = require('assert-plus')
4const util = require('util')
5
6const LDAPResult = require('./result')
7const Protocol = require('../protocol')
8
9/// --- API
10
11function ExtendedResponse (options) {
12 options = options || {}
13 assert.object(options)
14 assert.optionalString(options.responseName)
15 assert.optionalString(options.responsevalue)
16
17 this.responseName = options.responseName || undefined
18 this.responseValue = options.responseValue || undefined
19
20 options.protocolOp = Protocol.LDAP_REP_EXTENSION
21 LDAPResult.call(this, options)
22}
23util.inherits(ExtendedResponse, LDAPResult)
24Object.defineProperties(ExtendedResponse.prototype, {
25 type: {
26 get: function getType () { return 'ExtendedResponse' },
27 configurable: false
28 },
29 _dn: {
30 get: function getDN () { return this.responseName },
31 configurable: false
32 },
33 name: {
34 get: function getName () { return this.responseName },
35 set: function setName (val) {
36 assert.string(val)
37 this.responseName = val
38 },
39 configurable: false
40 },
41 value: {
42 get: function getValue () { return this.responseValue },
43 set: function (val) {
44 assert.string(val)
45 this.responseValue = val
46 },
47 configurable: false
48 }
49})
50
51ExtendedResponse.prototype._parse = function (ber) {
52 assert.ok(ber)
53
54 if (!LDAPResult.prototype._parse.call(this, ber)) { return false }
55
56 if (ber.peek() === 0x8a) { this.responseName = ber.readString(0x8a) }
57 if (ber.peek() === 0x8b) { this.responseValue = ber.readString(0x8b) }
58
59 return true
60}
61
62ExtendedResponse.prototype._toBer = function (ber) {
63 assert.ok(ber)
64
65 if (!LDAPResult.prototype._toBer.call(this, ber)) { return false }
66
67 if (this.responseName) { ber.writeString(this.responseName, 0x8a) }
68 if (this.responseValue) { ber.writeString(this.responseValue, 0x8b) }
69
70 return ber
71}
72
73ExtendedResponse.prototype._json = function (j) {
74 assert.ok(j)
75
76 j = LDAPResult.prototype._json.call(this, j)
77
78 j.responseName = this.responseName
79 j.responseValue = this.responseValue
80
81 return j
82}
83
84/// --- Exports
85
86module.exports = ExtendedResponse