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.

modify_request.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 Change = require('../change');
  6. var Protocol = require('../protocol');
  7. var lassert = require('../assert');
  8. ///--- API
  9. function ModifyRequest(options) {
  10. options = options || {};
  11. assert.object(options);
  12. lassert.optionalStringDN(options.object);
  13. lassert.optionalArrayOfAttribute(options.attributes);
  14. options.protocolOp = Protocol.LDAP_REQ_MODIFY;
  15. LDAPMessage.call(this, options);
  16. this.object = options.object || null;
  17. this.changes = options.changes ? options.changes.slice(0) : [];
  18. }
  19. util.inherits(ModifyRequest, LDAPMessage);
  20. Object.defineProperties(ModifyRequest.prototype, {
  21. type: {
  22. get: function getType() { return 'ModifyRequest'; },
  23. configurable: false
  24. },
  25. _dn: {
  26. get: function getDN() { return this.object; },
  27. configurable: false
  28. }
  29. });
  30. ModifyRequest.prototype._parse = function (ber) {
  31. assert.ok(ber);
  32. this.object = ber.readString();
  33. ber.readSequence();
  34. var end = ber.offset + ber.length;
  35. while (ber.offset < end) {
  36. var c = new Change();
  37. c.parse(ber);
  38. c.modification.type = c.modification.type.toLowerCase();
  39. this.changes.push(c);
  40. }
  41. this.changes.sort(Change.compare);
  42. return true;
  43. };
  44. ModifyRequest.prototype._toBer = function (ber) {
  45. assert.ok(ber);
  46. ber.writeString(this.object.toString());
  47. ber.startSequence();
  48. this.changes.forEach(function (c) {
  49. c.toBer(ber);
  50. });
  51. ber.endSequence();
  52. return ber;
  53. };
  54. ModifyRequest.prototype._json = function (j) {
  55. assert.ok(j);
  56. j.object = this.object;
  57. j.changes = [];
  58. this.changes.forEach(function (c) {
  59. j.changes.push(c.json);
  60. });
  61. return j;
  62. };
  63. ///--- Exports
  64. module.exports = ModifyRequest;