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');
|
2014-07-14 19:47:36 +00:00
|
|
|
var Ber = require('asn1').Ber;
|
2011-12-08 19:22:35 +00:00
|
|
|
|
|
|
|
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;
|
2015-11-12 04:36:21 +00:00
|
|
|
var opts = {
|
|
|
|
criticality: false,
|
|
|
|
value: null
|
|
|
|
};
|
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) {
|
2014-07-14 19:47:36 +00:00
|
|
|
if (ber.peek() === Ber.Boolean)
|
2015-11-12 04:36:21 +00:00
|
|
|
opts.criticality = ber.readBoolean();
|
2011-12-08 19:22:35 +00:00
|
|
|
}
|
2011-12-08 22:54:40 +00:00
|
|
|
|
|
|
|
if (ber.offset < end)
|
2015-11-12 04:36:21 +00:00
|
|
|
opts.value = ber.readString(Ber.OctetString, true);
|
2011-12-08 19:22:35 +00:00
|
|
|
}
|
2011-12-08 22:54:40 +00:00
|
|
|
|
|
|
|
var control;
|
|
|
|
switch (type) {
|
|
|
|
case PersistentSearchControl.OID:
|
2015-11-12 04:36:21 +00:00
|
|
|
control = new PersistentSearchControl(opts);
|
2011-12-08 22:54:40 +00:00
|
|
|
break;
|
2011-12-20 00:52:48 +00:00
|
|
|
case EntryChangeNotificationControl.OID:
|
2015-11-12 04:36:21 +00:00
|
|
|
control = new EntryChangeNotificationControl(opts);
|
2011-12-20 00:52:48 +00:00
|
|
|
break;
|
2012-03-26 18:53:30 +00:00
|
|
|
case PagedResultsControl.OID:
|
2015-11-12 04:36:21 +00:00
|
|
|
control = new PagedResultsControl(opts);
|
2012-03-26 18:53:30 +00:00
|
|
|
break;
|
2014-06-09 22:37:19 +00:00
|
|
|
case ServerSideSortingRequestControl.OID:
|
2015-11-12 04:36:21 +00:00
|
|
|
control = new ServerSideSortingRequestControl(opts);
|
2014-05-16 15:10:24 +00:00
|
|
|
break;
|
2014-06-09 22:58:01 +00:00
|
|
|
case ServerSideSortingResponseControl.OID:
|
2015-11-12 04:36:21 +00:00
|
|
|
control = new ServerSideSortingResponseControl(opts);
|
2014-06-09 22:58:01 +00:00
|
|
|
break;
|
2011-12-08 22:54:40 +00:00
|
|
|
default:
|
2015-11-12 04:36:21 +00:00
|
|
|
opts.type = type;
|
|
|
|
control = new Control(opts);
|
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
|
|
|
};
|