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_request.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
  2. var assert = require('assert-plus');
  3. var util = require('util');
  4. var LDAPMessage = require('./message');
  5. var Protocol = require('../protocol');
  6. ///--- API
  7. function ExtendedRequest(options) {
  8. options = options || {};
  9. assert.object(options);
  10. assert.optionalString(options.requestName);
  11. if (options.requestValue &&
  12. !(Buffer.isBuffer(options.requestValue) ||
  13. typeof (options.requestValue) === 'string')) {
  14. throw new TypeError('options.requestValue must be a buffer or a string');
  15. }
  16. options.protocolOp = Protocol.LDAP_REQ_EXTENSION;
  17. LDAPMessage.call(this, options);
  18. this.requestName = options.requestName || '';
  19. this.requestValue = options.requestValue;
  20. }
  21. util.inherits(ExtendedRequest, LDAPMessage);
  22. Object.defineProperties(ExtendedRequest.prototype, {
  23. type: {
  24. get: function getType() { return 'ExtendedRequest'; },
  25. configurable: false
  26. },
  27. _dn: {
  28. get: function getDN() { return this.requestName; },
  29. configurable: false
  30. },
  31. name: {
  32. get: function getName() { return this.requestName; },
  33. set: function setName(val) {
  34. assert.string(val);
  35. this.requestName = val;
  36. },
  37. configurable: false
  38. },
  39. value: {
  40. get: function getValue() { return this.requestValue; },
  41. set: function setValue(val) {
  42. if (!(Buffer.isBuffer(val) || typeof (val) === 'string'))
  43. throw new TypeError('value must be a buffer or a string');
  44. this.requestValue = val;
  45. },
  46. configurable: false
  47. }
  48. });
  49. ExtendedRequest.prototype._parse = function (ber) {
  50. assert.ok(ber);
  51. this.requestName = ber.readString(0x80);
  52. if (ber.peek() === 0x81)
  53. try {
  54. this.requestValue = ber.readString(0x81);
  55. } catch (e) {
  56. this.requestValue = ber.readBuffer(0x81);
  57. }
  58. return true;
  59. };
  60. ExtendedRequest.prototype._toBer = function (ber) {
  61. assert.ok(ber);
  62. ber.writeString(this.requestName, 0x80);
  63. if (Buffer.isBuffer(this.requestValue)) {
  64. ber.writeBuffer(this.requestValue, 0x81);
  65. } else if (typeof (this.requestValue) === 'string') {
  66. ber.writeString(this.requestValue, 0x81);
  67. }
  68. return ber;
  69. };
  70. ExtendedRequest.prototype._json = function (j) {
  71. assert.ok(j);
  72. j.requestName = this.requestName;
  73. j.requestValue = (Buffer.isBuffer(this.requestValue)) ?
  74. this.requestValue.toString('hex') : this.requestValue;
  75. return j;
  76. };
  77. ///--- Exports
  78. module.exports = ExtendedRequest;