node-ldapjs/lib/controls/index.js

87 lines
2.6 KiB
JavaScript
Raw Normal View History

// Copyright 2011 Mark Cavage, Inc. All rights reserved.
2020-10-31 21:07:32 +00:00
const assert = require('assert')
const Ber = require('asn1').Ber
2020-10-31 21:07:32 +00:00
const Control = require('./control')
const EntryChangeNotificationControl =
require('./entry_change_notification_control')
2020-10-31 21:07:32 +00:00
const PersistentSearchControl = require('./persistent_search_control')
const PagedResultsControl = require('./paged_results_control')
const ServerSideSortingRequestControl =
require('./server_side_sorting_request_control.js')
2020-10-31 21:07:32 +00:00
const ServerSideSortingResponseControl =
require('./server_side_sorting_response_control.js')
2020-10-31 21:07:32 +00:00
const VirtualListViewRequestControl =
2019-09-03 20:25:14 +00:00
require('./virtual_list_view_request_control.js')
2020-10-31 21:07:32 +00:00
const VirtualListViewResponseControl =
2019-09-03 20:25:14 +00:00
require('./virtual_list_view_response_control.js')
/// --- API
module.exports = {
getControl: function getControl (ber) {
assert.ok(ber)
if (ber.readSequence() === null) { return null }
2020-10-31 21:07:32 +00:00
let type
const opts = {
criticality: false,
value: null
}
if (ber.length) {
2020-10-31 21:07:32 +00:00
const end = ber.offset + ber.length
type = ber.readString()
if (ber.offset < end) {
if (ber.peek() === Ber.Boolean) { opts.criticality = ber.readBoolean() }
}
if (ber.offset < end) { opts.value = ber.readString(Ber.OctetString, true) }
}
2020-10-31 21:07:32 +00:00
let control
switch (type) {
case PersistentSearchControl.OID:
control = new PersistentSearchControl(opts)
break
case EntryChangeNotificationControl.OID:
control = new EntryChangeNotificationControl(opts)
break
case PagedResultsControl.OID:
control = new PagedResultsControl(opts)
break
case ServerSideSortingRequestControl.OID:
control = new ServerSideSortingRequestControl(opts)
break
case ServerSideSortingResponseControl.OID:
control = new ServerSideSortingResponseControl(opts)
break
2019-09-03 20:25:14 +00:00
case VirtualListViewRequestControl.OID:
control = new VirtualListViewRequestControl(opts)
break
case VirtualListViewResponseControl.OID:
control = new VirtualListViewResponseControl(opts)
break
default:
opts.type = type
control = new Control(opts)
break
}
return control
},
Control: Control,
EntryChangeNotificationControl: EntryChangeNotificationControl,
PagedResultsControl: PagedResultsControl,
2014-05-16 15:10:24 +00:00
PersistentSearchControl: PersistentSearchControl,
2014-06-09 22:58:01 +00:00
ServerSideSortingRequestControl: ServerSideSortingRequestControl,
2019-09-03 20:25:14 +00:00
ServerSideSortingResponseControl: ServerSideSortingResponseControl,
VirtualListViewRequestControl: VirtualListViewRequestControl,
VirtualListViewResponseControl: VirtualListViewResponseControl
}