node-ldapjs/lib/controls/index.js

95 lines
2.4 KiB
JavaScript
Raw Normal View History

// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert');
var Control = require('./control');
var EntryChangeNotificationControl =
require('./entry_change_notification_control');
var PersistentSearchControl = require('./persistent_search_control');
var PagedResultsControl = require('./paged_results_control');
var ServerSideSortingRequestControl =
require('./server_side_sorting_request_control.js');
2014-06-09 22:58:01 +00:00
var ServerSideSortingResponseControl =
require('./server_side_sorting_response_control.js');
///--- API
module.exports = {
getControl: function getControl(ber) {
assert.ok(ber);
if (ber.readSequence() === null)
return null;
var type;
var critical = false;
var value;
if (ber.length) {
var end = ber.offset + ber.length;
type = ber.readString();
if (ber.offset < end) {
if (ber.peek() === 0x01)
critical = ber.readBoolean();
}
if (ber.offset < end)
value = ber.readString(0x04, true);
}
var control;
switch (type) {
case PersistentSearchControl.OID:
control = new PersistentSearchControl({
critical: critical,
value: value
});
break;
case EntryChangeNotificationControl.OID:
control = new EntryChangeNotificationControl({
critical: critical,
value: value
});
break;
case PagedResultsControl.OID:
control = new PagedResultsControl({
critical: critical,
value: value
});
break;
case ServerSideSortingRequestControl.OID:
control = new ServerSideSortingRequestControl({
2014-05-16 15:10:24 +00:00
critical: critical,
value: value
});
break;
2014-06-09 22:58:01 +00:00
case ServerSideSortingResponseControl.OID:
control = new ServerSideSortingResponseControl({
critical: critical,
value: value
});
break;
default:
control = new Control({
type: type,
critical: critical,
value: value ? value.toString('utf8') : null
});
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,
ServerSideSortingResponseControl: ServerSideSortingResponseControl
};