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.

substr_filter.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
  2. var assert = require('assert');
  3. var util = require('util');
  4. var parents = require('ldap-filter');
  5. var Filter = require('./filter');
  6. ///--- API
  7. function SubstringFilter(options) {
  8. parents.SubstringFilter.call(this, options);
  9. }
  10. util.inherits(SubstringFilter, parents.SubstringFilter);
  11. Filter.mixin(SubstringFilter);
  12. module.exports = SubstringFilter;
  13. SubstringFilter.prototype.parse = function (ber) {
  14. assert.ok(ber);
  15. this.attribute = ber.readString().toLowerCase();
  16. ber.readSequence();
  17. var end = ber.offset + ber.length;
  18. while (ber.offset < end) {
  19. var tag = ber.peek();
  20. switch (tag) {
  21. case 0x80: // Initial
  22. this.initial = ber.readString(tag);
  23. if (this.attribute === 'objectclass')
  24. this.initial = this.initial.toLowerCase();
  25. break;
  26. case 0x81: // Any
  27. var anyVal = ber.readString(tag);
  28. if (this.attribute === 'objectclass')
  29. anyVal = anyVal.toLowerCase();
  30. this.any.push(anyVal);
  31. break;
  32. case 0x82: // Final
  33. this.final = ber.readString(tag);
  34. if (this.attribute === 'objectclass')
  35. this.final = this.final.toLowerCase();
  36. break;
  37. default:
  38. throw new Error('Invalid substrings filter type: 0x' + tag.toString(16));
  39. }
  40. }
  41. return true;
  42. };
  43. SubstringFilter.prototype._toBer = function (ber) {
  44. assert.ok(ber);
  45. ber.writeString(this.attribute);
  46. ber.startSequence();
  47. if (this.initial)
  48. ber.writeString(this.initial, 0x80);
  49. if (this.any && this.any.length)
  50. this.any.forEach(function (s) {
  51. ber.writeString(s, 0x81);
  52. });
  53. if (this.final)
  54. ber.writeString(this.final, 0x82);
  55. ber.endSequence();
  56. return ber;
  57. };