Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ext_filter.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2014 Mark Cavage, Inc. All rights reserved.
  2. // Copyright 2014 Patrick Mooney. All rights reserved.
  3. var util = require('util');
  4. var assert = require('assert-plus');
  5. var helpers = require('./helpers');
  6. ///--- API
  7. function ExtensibleFilter(options) {
  8. if (typeof (options) === 'object') {
  9. assert.optionalString(options.rule, 'options.rule');
  10. assert.optionalString(options.matchType, 'options.matchType');
  11. assert.optionalString(options.attribute, 'options.attribute');
  12. assert.optionalString(options.value, 'options.value');
  13. } else {
  14. options = {};
  15. }
  16. if (options.matchType !== undefined) {
  17. this.matchType = options.matchType;
  18. } else {
  19. this.matchType = options.attribute;
  20. }
  21. this.dnAttributes = options.dnAttributes || false;
  22. this.rule = options.rule;
  23. this.value = (options.value !== undefined) ? options.value : '';
  24. var self = this;
  25. this.__defineGetter__('type', function () { return 'ext'; });
  26. this.__defineGetter__('json', function () {
  27. return {
  28. type: 'ExtensibleMatch',
  29. matchRule: self.rule,
  30. matchType: self.matchType,
  31. matchValue: self.value,
  32. dnAttributes: self.dnAttributes
  33. };
  34. });
  35. this.__defineGetter__('matchingRule', function () {
  36. return self.rule;
  37. });
  38. this.__defineGetter__('matchValue', function () {
  39. return self.value;
  40. });
  41. this.__defineGetter__('attribute', function () {
  42. return this.matchType;
  43. });
  44. this.__defineSetter__('attribute', function (value) {
  45. this.matchType = value;
  46. });
  47. }
  48. util.inherits(ExtensibleFilter, helpers.Filter);
  49. ExtensibleFilter.prototype.toString = function () {
  50. var str = '(';
  51. if (this.matchType)
  52. str += this.matchType;
  53. str += ':';
  54. if (this.dnAttributes)
  55. str += 'dn:';
  56. if (this.rule)
  57. str += this.rule + ':';
  58. return (str + '=' + this.value + ')');
  59. };
  60. ExtensibleFilter.prototype.matches = function () {
  61. // Consumers must implement this themselves
  62. throw new Error('ext match implementation missing');
  63. };
  64. ///--- Exports
  65. module.exports = ExtensibleFilter;