NlmDecoder.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.NlmDecoder = 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 NlmDecoder {
  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.decodeTestRequest();
  39. case 2:
  40. return this.decodeLockRequest();
  41. case 3:
  42. return this.decodeCancelRequest();
  43. case 4:
  44. return this.decodeUnlockRequest();
  45. case 5:
  46. return this.decodeGrantedRequest();
  47. case 20:
  48. return this.decodeShareRequest();
  49. case 21:
  50. return this.decodeUnshareRequest();
  51. case 22:
  52. return this.decodeNmLockRequest();
  53. case 23:
  54. return this.decodeFreeAllRequest();
  55. default:
  56. throw new errors_1.Nfsv3DecodingError(`Unknown NLM procedure: ${proc}`);
  57. }
  58. }
  59. decodeResponse(proc) {
  60. switch (proc) {
  61. case 0:
  62. return undefined;
  63. case 1:
  64. return this.decodeTestResponse();
  65. case 2:
  66. case 3:
  67. case 4:
  68. case 5:
  69. case 22:
  70. return this.decodeResponse4();
  71. case 20:
  72. case 21:
  73. return this.decodeShareResponse();
  74. default:
  75. throw new errors_1.Nfsv3DecodingError(`Unknown NLM procedure: ${proc}`);
  76. }
  77. }
  78. readCookie() {
  79. const data = this.xdr.readVarlenOpaque();
  80. return new Reader_1.Reader(data);
  81. }
  82. readNetobj() {
  83. const data = this.xdr.readVarlenOpaque();
  84. return new Reader_1.Reader(data);
  85. }
  86. readNlm4Holder() {
  87. const xdr = this.xdr;
  88. const exclusive = xdr.readBoolean();
  89. const svid = xdr.readInt();
  90. const oh = this.readNetobj();
  91. const offset = xdr.readUnsignedHyper();
  92. const length = xdr.readUnsignedHyper();
  93. return new structs.Nlm4Holder(exclusive, svid, oh, offset, length);
  94. }
  95. readNlm4Lock() {
  96. const xdr = this.xdr;
  97. const callerName = xdr.readString();
  98. const fh = this.readNetobj();
  99. const oh = this.readNetobj();
  100. const svid = xdr.readInt();
  101. const offset = xdr.readUnsignedHyper();
  102. const length = xdr.readUnsignedHyper();
  103. return new structs.Nlm4Lock(callerName, fh, oh, svid, offset, length);
  104. }
  105. readNlm4Share() {
  106. const xdr = this.xdr;
  107. const callerName = xdr.readString();
  108. const fh = this.readNetobj();
  109. const oh = this.readNetobj();
  110. const mode = xdr.readUnsignedInt();
  111. const access = xdr.readUnsignedInt();
  112. return new structs.Nlm4Share(callerName, fh, oh, mode, access);
  113. }
  114. readTestArgs() {
  115. const cookie = this.readCookie();
  116. const exclusive = this.xdr.readBoolean();
  117. const lock = this.readNlm4Lock();
  118. return new msg.Nlm4TestArgs(cookie, exclusive, lock);
  119. }
  120. readLockArgs() {
  121. const xdr = this.xdr;
  122. const cookie = this.readCookie();
  123. const block = xdr.readBoolean();
  124. const exclusive = xdr.readBoolean();
  125. const lock = this.readNlm4Lock();
  126. const reclaim = xdr.readBoolean();
  127. const state = xdr.readInt();
  128. return new msg.Nlm4LockArgs(cookie, block, exclusive, lock, reclaim, state);
  129. }
  130. readCancelArgs() {
  131. const xdr = this.xdr;
  132. const cookie = this.readCookie();
  133. const block = xdr.readBoolean();
  134. const exclusive = xdr.readBoolean();
  135. const lock = this.readNlm4Lock();
  136. return new msg.Nlm4CancelArgs(cookie, block, exclusive, lock);
  137. }
  138. readUnlockArgs() {
  139. const cookie = this.readCookie();
  140. const lock = this.readNlm4Lock();
  141. return new msg.Nlm4UnlockArgs(cookie, lock);
  142. }
  143. readShareArgs() {
  144. const cookie = this.readCookie();
  145. const share = this.readNlm4Share();
  146. const reclaim = this.xdr.readBoolean();
  147. return new msg.Nlm4ShareArgs(cookie, share, reclaim);
  148. }
  149. decodeTestRequest() {
  150. const args = this.readTestArgs();
  151. return new msg.Nlm4TestRequest(args);
  152. }
  153. decodeTestResponse() {
  154. const xdr = this.xdr;
  155. const cookie = this.readCookie();
  156. const stat = xdr.readUnsignedInt();
  157. const holder = stat === 1 ? this.readNlm4Holder() : undefined;
  158. return new msg.Nlm4TestResponse(cookie, stat, holder);
  159. }
  160. decodeLockRequest() {
  161. const args = this.readLockArgs();
  162. return new msg.Nlm4LockRequest(args);
  163. }
  164. decodeResponse4() {
  165. const cookie = this.readCookie();
  166. const stat = this.xdr.readUnsignedInt();
  167. return new msg.Nlm4Response(cookie, stat);
  168. }
  169. decodeCancelRequest() {
  170. const args = this.readCancelArgs();
  171. return new msg.Nlm4CancelRequest(args);
  172. }
  173. decodeUnlockRequest() {
  174. const args = this.readUnlockArgs();
  175. return new msg.Nlm4UnlockRequest(args);
  176. }
  177. decodeGrantedRequest() {
  178. const args = this.readTestArgs();
  179. return new msg.Nlm4GrantedRequest(args);
  180. }
  181. decodeShareRequest() {
  182. const args = this.readShareArgs();
  183. return new msg.Nlm4ShareRequest(args);
  184. }
  185. decodeShareResponse() {
  186. const xdr = this.xdr;
  187. const cookie = this.readCookie();
  188. const stat = xdr.readUnsignedInt();
  189. const sequence = xdr.readInt();
  190. return new msg.Nlm4ShareResponse(cookie, stat, sequence);
  191. }
  192. decodeUnshareRequest() {
  193. const args = this.readShareArgs();
  194. return new msg.Nlm4UnshareRequest(args);
  195. }
  196. decodeNmLockRequest() {
  197. const args = this.readLockArgs();
  198. return new msg.Nlm4NmLockRequest(args);
  199. }
  200. decodeFreeAllRequest() {
  201. const xdr = this.xdr;
  202. const name = xdr.readString();
  203. const state = xdr.readInt();
  204. const notify = new structs.Nlm4Notify(name, state);
  205. return new msg.Nlm4FreeAllRequest(notify);
  206. }
  207. }
  208. exports.NlmDecoder = NlmDecoder;
  209. //# sourceMappingURL=NlmDecoder.js.map