xref: /haiku/src/add-ons/kernel/file_systems/nfs4/RPCReply.cpp (revision b82f4c07eba5dd04d1e2878ea79f47183d83c707)
1 /*
2  * Copyright 2012 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Paweł Dziepak, pdziepak@quarnos.org
7  */
8 
9 
10 #include "RPCReply.h"
11 
12 #include <util/kernel_cpp.h>
13 
14 
15 using namespace RPC;
16 
17 enum {
18 	REPLY	= 1
19 };
20 
21 enum {
22 	MSG_ACCEPTED	= 0,
23 	MSG_DENIED		= 1
24 };
25 
26 enum accept_stat {
27 	SUCCESS       = 0, /* RPC executed successfully       */
28 	PROG_UNAVAIL  = 1, /* remote hasn't exported program  */
29 	PROG_MISMATCH = 2, /* remote can't support version #  */
30 	PROC_UNAVAIL  = 3, /* program can't support procedure */
31 	GARBAGE_ARGS  = 4, /* procedure can't decode params   */
32 	SYSTEM_ERR    = 5  /* e.g. memory allocation failure  */
33 };
34 
35 enum reject_stat {
36 	RPC_MISMATCH = 0, /* RPC version number != 2          */
37 	AUTH_ERROR = 1    /* remote can't authenticate caller */
38 };
39 
40 
41 Reply::Reply(void *buffer, int size)
42 	:
43 	fError(B_OK),
44 	fStream(buffer, size),
45 	fBuffer(buffer)
46 {
47 	fXID = fStream.GetUInt();
48 	if (fStream.GetInt() != REPLY) {
49 		fError = B_BAD_VALUE;
50 		return;
51 	}
52 
53 	if (fStream.GetInt() == MSG_ACCEPTED) {
54 		fStream.GetInt();
55 		fStream.GetOpaque(NULL);
56 
57 		switch (fStream.GetInt()) {
58 			case SUCCESS:
59 				return;
60 			case PROG_UNAVAIL:
61 			case PROG_MISMATCH:
62 			case PROC_UNAVAIL:
63 				fError = B_DEVICE_NOT_FOUND;
64 				return;
65 			case GARBAGE_ARGS:
66 				fError = B_MISMATCHED_VALUES;
67 				return;
68 			case SYSTEM_ERR:
69 				fError = B_ERROR;
70 				return;
71 			default:
72 				fError = B_BAD_VALUE;
73 				return;
74 		}
75 	} else {		// MSG_DENIED
76 		if (fStream.GetInt() == RPC_MISMATCH) {
77 			fError = B_DEVICE_NOT_FOUND;
78 			return;
79 		} else {	// AUTH_ERROR
80 			fError = B_PERMISSION_DENIED;
81 			return;
82 		}
83 	}
84 }
85 
86 
87 Reply::~Reply()
88 {
89 	free(fBuffer);
90 }
91 
92