1 /*
2 * Copyright (c) 2000
3 * Traakan, Inc., Los Altos, CA
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
11 * disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 /*
30 * Project: NDMJOB
31 * Ident: $Id: $
32 *
33 * Description:
34 *
35 */
36
37
38 #include "ndmos.h" /* rpc/rpc.h */
39 #include "ndmprotocol.h"
40 #include "ndmp_msg_buf.h"
41 #include "ndmp_translate.h"
42
43
44 /*
45 * enum_conversion tables
46 ****************************************************************
47 * Used to make enum conversion convenient and dense.
48 * The first row is the default case in both directions,
49 * and is skipped while attempting precise conversion.
50 * The search stops with the first match.
51 */
52
53 int /* ndmp9_.... */
convert_enum_to_9(struct enum_conversion * ectab,int enum_x)54 convert_enum_to_9(struct enum_conversion* ectab, int enum_x)
55 {
56 struct enum_conversion* ec = &ectab[1];
57
58 for (; !IS_END_ENUM_CONVERSION_TABLE(ec); ec++) {
59 if (ec->enum_x == enum_x) return ec->enum_9;
60 }
61
62 return ectab[0].enum_9;
63 }
64
65 int /* ndmpx_.... */
convert_enum_from_9(struct enum_conversion * ectab,int enum_9)66 convert_enum_from_9(struct enum_conversion* ectab, int enum_9)
67 {
68 struct enum_conversion* ec = &ectab[1];
69
70 for (; !IS_END_ENUM_CONVERSION_TABLE(ec); ec++) {
71 if (ec->enum_9 == enum_9) return ec->enum_x;
72 }
73
74 return ectab[0].enum_x;
75 }
76
convert_valid_u_long_to_9(uint32_t * valx,ndmp9_valid_u_long * val9)77 int convert_valid_u_long_to_9(uint32_t* valx, ndmp9_valid_u_long* val9)
78 {
79 val9->value = *valx;
80
81 if (*valx == NDMP_INVALID_U_LONG)
82 val9->valid = NDMP9_VALIDITY_INVALID;
83 else
84 val9->valid = NDMP9_VALIDITY_VALID;
85
86 return 0;
87 }
88
convert_valid_u_long_from_9(uint32_t * valx,ndmp9_valid_u_long * val9)89 int convert_valid_u_long_from_9(uint32_t* valx, ndmp9_valid_u_long* val9)
90 {
91 if (!val9->valid)
92 *valx = NDMP_INVALID_U_LONG;
93 else
94 *valx = val9->value;
95
96 return 0;
97 }
98
convert_invalid_u_long_9(struct ndmp9_valid_u_long * val9)99 int convert_invalid_u_long_9(struct ndmp9_valid_u_long* val9)
100 {
101 val9->value = NDMP_INVALID_U_LONG;
102 val9->valid = NDMP9_VALIDITY_INVALID;
103
104 return 0;
105 }
106
convert_valid_u_quad_to_9(ndmp9_u_quad * valx,ndmp9_valid_u_quad * val9)107 int convert_valid_u_quad_to_9(ndmp9_u_quad* valx, ndmp9_valid_u_quad* val9)
108 {
109 val9->value = *valx;
110
111 if (*valx == NDMP_INVALID_U_QUAD)
112 val9->valid = NDMP9_VALIDITY_INVALID;
113 else
114 val9->valid = NDMP9_VALIDITY_VALID;
115
116 return 0;
117 }
118
convert_valid_u_quad_from_9(ndmp9_u_quad * valx,ndmp9_valid_u_quad * val9)119 int convert_valid_u_quad_from_9(ndmp9_u_quad* valx, ndmp9_valid_u_quad* val9)
120 {
121 if (!val9->valid)
122 *valx = NDMP_INVALID_U_QUAD;
123 else
124 *valx = val9->value;
125
126 return 0;
127 }
128
convert_invalid_u_quad_9(struct ndmp9_valid_u_quad * val9)129 int convert_invalid_u_quad_9(struct ndmp9_valid_u_quad* val9)
130 {
131 val9->value = NDMP_INVALID_U_QUAD;
132 val9->valid = NDMP9_VALIDITY_INVALID;
133
134 return 0;
135 }
136
convert_strdup(char * src,char ** dstp)137 int convert_strdup(char* src, char** dstp)
138 {
139 if (src == 0) {
140 *dstp = 0;
141 return 0;
142 }
143 *dstp = NDMOS_API_STRDUP(src);
144 if (!*dstp) return -1;
145
146 return 0;
147 }
148
149
150 /*
151 * request/reply translation tables
152 ****************************************************************
153 */
154
155 struct reqrep_xlate_version_table reqrep_xlate_version_table[] = {
156 #ifndef NDMOS_OPTION_NO_NDMP2
157 {NDMP2VER, ndmp2_reqrep_xlate_table},
158 #endif /* !NDMOS_OPTION_NO_NDMP2 */
159 #ifndef NDMOS_OPTION_NO_NDMP3
160 {NDMP3VER, ndmp3_reqrep_xlate_table},
161 #endif /* !NDMOS_OPTION_NO_NDMP3 */
162 #ifndef NDMOS_OPTION_NO_NDMP4
163 {NDMP4VER, ndmp4_reqrep_xlate_table},
164 #endif /* !NDMOS_OPTION_NO_NDMP4 */
165 {0}};
166
reqrep_xlate_lookup_version(struct reqrep_xlate_version_table * rrvt,unsigned protocol_version)167 struct reqrep_xlate* reqrep_xlate_lookup_version(
168 struct reqrep_xlate_version_table* rrvt,
169 unsigned protocol_version)
170 {
171 for (; rrvt->protocol_version > 0; rrvt++) {
172 if (rrvt->protocol_version == (int)protocol_version) {
173 return rrvt->reqrep_xlate_table;
174 }
175 }
176
177 return 0;
178 }
179
180
ndmp_reqrep_by_v9(struct reqrep_xlate * table,ndmp9_message v9_message)181 struct reqrep_xlate* ndmp_reqrep_by_v9(struct reqrep_xlate* table,
182 ndmp9_message v9_message)
183 {
184 struct reqrep_xlate* rrx = table;
185
186 for (; rrx->v9_message; rrx++)
187 if (rrx->v9_message == v9_message) return rrx;
188
189 return 0;
190 }
191
ndmp_reqrep_by_vx(struct reqrep_xlate * table,int vx_message)192 struct reqrep_xlate* ndmp_reqrep_by_vx(struct reqrep_xlate* table,
193 int vx_message)
194 {
195 struct reqrep_xlate* rrx = table;
196
197 for (; rrx->v9_message; rrx++)
198 if (rrx->vx_message == vx_message) return rrx;
199
200 return 0;
201 }
202
ndmp_xtox_no_arguments(void * vxbody,void * vybody)203 int ndmp_xtox_no_arguments(void* vxbody, void* vybody) { return 0; }
204
205
ndmp_xtox_no_memused(void * vxbody)206 int ndmp_xtox_no_memused(void* vxbody) { return 0; }
207