diff --git a/lib/controls/control.js b/lib/controls/control.js index 0ea2d05..b9cedc5 100644 --- a/lib/controls/control.js +++ b/lib/controls/control.js @@ -38,11 +38,12 @@ function Control(options) { var self = this; this.__defineGetter__('json', function() { - return { + var obj = { controlType: self.type, criticality: self.criticality, controlValue: self.value }; + return (typeof(self._json) === 'function' ? self._json(obj) : obj); }); } module.exports = Control; diff --git a/lib/controls/persistent_search_control.js b/lib/controls/persistent_search_control.js index e0da5cc..47170bf 100644 --- a/lib/controls/persistent_search_control.js +++ b/lib/controls/persistent_search_control.js @@ -39,11 +39,6 @@ function PersistentSearchControl(options) { this.__defineGetter__('value', function() { return self._value || {}; }); - this.__defineGetter__('json', function() { - var json = Control.prototype.json.call(self); - json.controlValue = self.value; - return json; - }); } util.inherits(PersistentSearchControl, Control); module.exports = PersistentSearchControl; @@ -84,4 +79,11 @@ PersistentSearchControl.prototype._toBer = function(ber) { }; +PersistentSearchControl.prototype._json = function(obj) { + obj.controlValue = this.value; + return obj; +}; + + + PersistentSearchControl.OID = '2.16.840.1.113730.3.4.3'; diff --git a/lib/index.js b/lib/index.js index 71585a7..630e179 100644 --- a/lib/index.js +++ b/lib/index.js @@ -7,6 +7,7 @@ var Protocol = require('./protocol'); var Server = require('./server'); var assert = require('assert'); +var controls = require('./controls'); var dn = require('./dn'); var errors = require('./errors'); var filters = require('./filters'); @@ -15,6 +16,8 @@ var messages = require('./messages'); var schema = require('./schema'); var url = require('./url'); + + /// Hack a few things we need (i.e., "monkey patch" the prototype) if (!String.prototype.startsWith) { @@ -73,6 +76,7 @@ module.exports = { }; + ///--- Export all the childrenz var k; @@ -87,6 +91,11 @@ for (k in messages) { module.exports[k] = messages[k]; } +for (k in controls) { + if (controls.hasOwnProperty(k)) + module.exports[k] = controls[k]; +} + for (k in filters) { if (filters.hasOwnProperty(k)) { if (k !== 'parse' && k !== 'parseString') diff --git a/tst/controls/control.test.js b/tst/controls/control.test.js index 3edbf4f..6f1f188 100644 --- a/tst/controls/control.test.js +++ b/tst/controls/control.test.js @@ -16,9 +16,9 @@ var getControl; ///--- Tests test('load library', function(t) { - Control = require('../../lib/controls/index').Control; + Control = require('../../lib/index').Control; t.ok(Control); - getControl = require('../../lib/controls/index').getControl; + getControl = require('../../lib/index').getControl; t.ok(getControl); t.end(); }); diff --git a/tst/controls/persistent_search_control.test.js b/tst/controls/persistent_search_control.test.js index 278e823..b8833a6 100644 --- a/tst/controls/persistent_search_control.test.js +++ b/tst/controls/persistent_search_control.test.js @@ -14,10 +14,9 @@ var PersistentSearchControl; ///--- Tests test('load library', function(t) { - PersistentSearchControl = - require('../../lib/controls').PersistentSearchControl; + PersistentSearchControl = require('../../lib').PersistentSearchControl; t.ok(PersistentSearchControl); - getControl = require('../../lib/controls').getControl; + getControl = require('../../lib').getControl; t.ok(getControl); t.end(); });