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.

abandon_request.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 AbandonRequest(options) {
  8. options = options || {};
  9. assert.object(options);
  10. assert.optionalNumber(options.abandonID);
  11. options.protocolOp = Protocol.LDAP_REQ_ABANDON;
  12. LDAPMessage.call(this, options);
  13. this.abandonID = options.abandonID || 0;
  14. }
  15. util.inherits(AbandonRequest, LDAPMessage);
  16. Object.defineProperties(AbandonRequest.prototype, {
  17. type: {
  18. get: function getType() { return 'AbandonRequest'; },
  19. configurable: false
  20. }
  21. });
  22. AbandonRequest.prototype._parse = function (ber, length) {
  23. assert.ok(ber);
  24. assert.ok(length);
  25. // What a PITA - have to replicate ASN.1 integer logic to work around the
  26. // way abandon is encoded and the way ldapjs framework handles "normal"
  27. // messages
  28. var buf = ber.buffer;
  29. var offset = 0;
  30. var value = 0;
  31. var fb = buf[offset++];
  32. value = fb & 0x7F;
  33. for (var i = 1; i < length; i++) {
  34. value <<= 8;
  35. value |= (buf[offset++] & 0xff);
  36. }
  37. if ((fb & 0x80) == 0x80)
  38. value = -value;
  39. ber._offset += length;
  40. this.abandonID = value;
  41. return true;
  42. };
  43. AbandonRequest.prototype._toBer = function (ber) {
  44. assert.ok(ber);
  45. var i = this.abandonID;
  46. var sz = 4;
  47. while ((((i & 0xff800000) === 0) || ((i & 0xff800000) === 0xff800000)) &&
  48. (sz > 1)) {
  49. sz--;
  50. i <<= 8;
  51. }
  52. assert.ok(sz <= 4);
  53. while (sz-- > 0) {
  54. ber.writeByte((i & 0xff000000) >> 24);
  55. i <<= 8;
  56. }
  57. return ber;
  58. };
  59. AbandonRequest.prototype._json = function (j) {
  60. assert.ok(j);
  61. j.abandonID = this.abandonID;
  62. return j;
  63. };
  64. ///--- Exports
  65. module.exports = AbandonRequest;