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.

filter.js 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
  2. var assert = require('assert');
  3. var asn1 = require('asn1');
  4. var Protocol = require('../protocol');
  5. ///--- Globals
  6. var BerWriter = asn1.BerWriter;
  7. var TYPES = {
  8. 'and': Protocol.FILTER_AND,
  9. 'or': Protocol.FILTER_OR,
  10. 'not': Protocol.FILTER_NOT,
  11. 'equal': Protocol.FILTER_EQUALITY,
  12. 'substring': Protocol.FILTER_SUBSTRINGS,
  13. 'ge': Protocol.FILTER_GE,
  14. 'le': Protocol.FILTER_LE,
  15. 'present': Protocol.FILTER_PRESENT,
  16. 'approx': Protocol.FILTER_APPROX,
  17. 'ext': Protocol.FILTER_EXT
  18. };
  19. ///--- API
  20. function isFilter(filter) {
  21. if (!filter || typeof (filter) !== 'object') {
  22. return false;
  23. }
  24. // Do our best to duck-type it
  25. if (typeof (filter.toBer) === 'function' &&
  26. typeof (filter.matches) === 'function' &&
  27. TYPES[filter.type] !== undefined) {
  28. return true;
  29. }
  30. return false;
  31. }
  32. function mixin(target) {
  33. target.prototype.toBer = function toBer(ber) {
  34. if (!ber || !(ber instanceof BerWriter))
  35. throw new TypeError('ber (BerWriter) required');
  36. ber.startSequence(TYPES[this.type]);
  37. ber = this._toBer(ber);
  38. ber.endSequence();
  39. return ber;
  40. };
  41. }
  42. module.exports = {
  43. isFilter: isFilter,
  44. mixin: mixin
  45. };