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