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.

search_reference.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
  2. var assert = require('assert-plus');
  3. var util = require('util');
  4. var asn1 = require('asn1');
  5. var LDAPMessage = require('./message');
  6. var Protocol = require('../protocol');
  7. var dn = require('../dn');
  8. var url = require('../url');
  9. ///--- Globals
  10. var BerWriter = asn1.BerWriter;
  11. var parseURL = url.parse;
  12. ///--- API
  13. function SearchReference(options) {
  14. options = options || {};
  15. assert.object(options);
  16. options.protocolOp = Protocol.LDAP_REP_SEARCH_REF;
  17. LDAPMessage.call(this, options);
  18. this.uris = options.uris || [];
  19. }
  20. util.inherits(SearchReference, LDAPMessage);
  21. Object.defineProperties(SearchReference.prototype, {
  22. type: {
  23. get: function getType() { return 'SearchReference'; },
  24. configurable: false
  25. },
  26. _dn: {
  27. get: function getDN() { return new dn.DN(''); },
  28. configurable: false
  29. },
  30. object: {
  31. get: function getObject() {
  32. return {
  33. dn: this.dn.toString(),
  34. uris: this.uris.slice()
  35. };
  36. },
  37. configurable: false
  38. },
  39. urls: {
  40. get: function getUrls() { return this.uris; },
  41. set: function setUrls(val) {
  42. assert.ok(val);
  43. assert.ok(Array.isArray(val));
  44. this.uris = val.slice();
  45. },
  46. configurable: false
  47. }
  48. });
  49. SearchReference.prototype.toObject = function () {
  50. return this.object;
  51. };
  52. SearchReference.prototype.fromObject = function (obj) {
  53. if (typeof (obj) !== 'object')
  54. throw new TypeError('object required');
  55. this.uris = obj.uris ? obj.uris.slice() : [];
  56. return true;
  57. };
  58. SearchReference.prototype._json = function (j) {
  59. assert.ok(j);
  60. j.uris = this.uris.slice();
  61. return j;
  62. };
  63. SearchReference.prototype._parse = function (ber, length) {
  64. assert.ok(ber);
  65. while (ber.offset < length) {
  66. var _url = ber.readString();
  67. parseURL(_url);
  68. this.uris.push(_url);
  69. }
  70. return true;
  71. };
  72. SearchReference.prototype._toBer = function (ber) {
  73. assert.ok(ber);
  74. this.uris.forEach(function (u) {
  75. ber.writeString(u.href || u);
  76. });
  77. return ber;
  78. };
  79. ///--- Exports
  80. module.exports = SearchReference;