MountDecoder.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.MountDecoder = void 0;
  4. const tslib_1 = require("tslib");
  5. const Reader_1 = require("@jsonjoy.com/buffers/lib/Reader");
  6. const XdrDecoder_1 = require("../../../xdr/XdrDecoder");
  7. const errors_1 = require("../errors");
  8. const msg = tslib_1.__importStar(require("./messages"));
  9. const structs = tslib_1.__importStar(require("./structs"));
  10. class MountDecoder {
  11. constructor(reader = new Reader_1.Reader()) {
  12. this.xdr = new XdrDecoder_1.XdrDecoder(reader);
  13. }
  14. decodeMessage(reader, proc, isRequest) {
  15. this.xdr.reader = reader;
  16. const startPos = reader.x;
  17. try {
  18. if (isRequest) {
  19. return this.decodeRequest(proc);
  20. }
  21. else {
  22. return this.decodeResponse(proc);
  23. }
  24. }
  25. catch (err) {
  26. if (err instanceof RangeError) {
  27. reader.x = startPos;
  28. return undefined;
  29. }
  30. throw err;
  31. }
  32. }
  33. decodeRequest(proc) {
  34. switch (proc) {
  35. case 0:
  36. return undefined;
  37. case 1:
  38. return this.decodeMntRequest();
  39. case 2:
  40. return new msg.MountDumpRequest();
  41. case 3:
  42. return this.decodeUmntRequest();
  43. case 4:
  44. return new msg.MountUmntallRequest();
  45. case 5:
  46. return new msg.MountExportRequest();
  47. default:
  48. throw new errors_1.Nfsv3DecodingError(`Unknown MOUNT procedure: ${proc}`);
  49. }
  50. }
  51. decodeResponse(proc) {
  52. switch (proc) {
  53. case 0:
  54. return undefined;
  55. case 1:
  56. return this.decodeMntResponse();
  57. case 2:
  58. return this.decodeDumpResponse();
  59. case 3:
  60. return undefined;
  61. case 4:
  62. return undefined;
  63. case 5:
  64. return this.decodeExportResponse();
  65. default:
  66. throw new errors_1.Nfsv3DecodingError(`Unknown MOUNT procedure: ${proc}`);
  67. }
  68. }
  69. readFhandle3() {
  70. const data = this.xdr.readVarlenOpaque();
  71. return new structs.MountFhandle3(new Reader_1.Reader(data));
  72. }
  73. readDirpath() {
  74. return this.xdr.readString();
  75. }
  76. readMountBody() {
  77. const valueFollows = this.xdr.readBoolean();
  78. if (!valueFollows)
  79. return undefined;
  80. const hostname = this.xdr.readString();
  81. const directory = this.readDirpath();
  82. const next = this.readMountBody();
  83. return new structs.MountBody(hostname, directory, next);
  84. }
  85. readGroupNode() {
  86. const valueFollows = this.xdr.readBoolean();
  87. if (!valueFollows)
  88. return undefined;
  89. const name = this.xdr.readString();
  90. const next = this.readGroupNode();
  91. return new structs.MountGroupNode(name, next);
  92. }
  93. readExportNode() {
  94. const valueFollows = this.xdr.readBoolean();
  95. if (!valueFollows)
  96. return undefined;
  97. const dir = this.readDirpath();
  98. const groups = this.readGroupNode();
  99. const next = this.readExportNode();
  100. return new structs.MountExportNode(dir, groups, next);
  101. }
  102. decodeMntRequest() {
  103. const dirpath = this.readDirpath();
  104. return new msg.MountMntRequest(dirpath);
  105. }
  106. decodeMntResponse() {
  107. const xdr = this.xdr;
  108. const status = xdr.readUnsignedInt();
  109. if (status !== 0) {
  110. return new msg.MountMntResponse(status);
  111. }
  112. const fhandle = this.readFhandle3();
  113. const authFlavorsCount = xdr.readUnsignedInt();
  114. const authFlavors = [];
  115. for (let i = 0; i < authFlavorsCount; i++) {
  116. authFlavors.push(xdr.readUnsignedInt());
  117. }
  118. const mountinfo = new msg.MountMntResOk(fhandle, authFlavors);
  119. return new msg.MountMntResponse(status, mountinfo);
  120. }
  121. decodeDumpResponse() {
  122. const mountlist = this.readMountBody();
  123. return new msg.MountDumpResponse(mountlist);
  124. }
  125. decodeUmntRequest() {
  126. const dirpath = this.readDirpath();
  127. return new msg.MountUmntRequest(dirpath);
  128. }
  129. decodeExportResponse() {
  130. const exports = this.readExportNode();
  131. return new msg.MountExportResponse(exports);
  132. }
  133. }
  134. exports.MountDecoder = MountDecoder;
  135. //# sourceMappingURL=MountDecoder.js.map