1 |
|
2 |
|
3 | const assert = require('assert-plus')
|
4 | const util = require('util')
|
5 |
|
6 | const LDAPResult = require('./result')
|
7 | const Protocol = require('../protocol')
|
8 |
|
9 |
|
10 |
|
11 | function 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 | }
|
23 | util.inherits(ExtendedResponse, LDAPResult)
|
24 | Object.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 |
|
51 | ExtendedResponse.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 |
|
62 | ExtendedResponse.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 |
|
73 | ExtendedResponse.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 |
|
85 |
|
86 | module.exports = ExtendedResponse
|