2 * Copyright (c) 1998,1999,2000
3 * Traakan, Inc., Los Altos, CA
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
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.
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
34 * Miscellaneous C functions to support protocol versions.
35 * See ndmprotocol.h for explanation.
40 #include "ndmprotocol.h"
47 ****************************************************************
50 struct ndmp_xdr_message_table *
51 ndmp_xmt_lookup (int protocol_version, int msg)
53 struct ndmp_xdr_message_table * table;
54 struct ndmp_xdr_message_table * ent;
56 switch (protocol_version) {
58 table = ndmp0_xdr_message_table;
61 #ifndef NDMOS_OPTION_NO_NDMP2
63 table = ndmp2_xdr_message_table;
65 #endif /* !NDMOS_OPTION_NO_NDMP2 */
67 #ifndef NDMOS_OPTION_NO_NDMP3
69 table = ndmp3_xdr_message_table;
71 #endif /* !NDMOS_OPTION_NO_NDMP3 */
73 #ifndef NDMOS_OPTION_NO_NDMP4
75 table = ndmp4_xdr_message_table;
77 #endif /* !NDMOS_OPTION_NO_NDMP4 */
83 for (ent = table; ent->msg; ent++) {
84 if (ent->msg == msg) {
97 ****************************************************************
101 ndmp_enum_to_str (int val, struct ndmp_enum_str_table *table)
103 static char vbuf[8][32];
107 for (; table->name; table++)
108 if (table->value == val)
114 sprintf (vbp, "?0x%x?", val);
119 ndmp_enum_from_str (int *valp, char *str, struct ndmp_enum_str_table *table)
121 for (; table->name; table++) {
122 if (strcmp(table->name, str) == 0) {
123 *valp = table->value;
135 * MULTI-VERSION ENUM TO STRING CONVERTERS
136 ****************************************************************
140 ndmp_message_to_str (int protocol_version, int msg)
142 static char yikes_buf[40]; /* non-reentrant */
144 switch (protocol_version) {
145 case 0: return ndmp0_message_to_str (msg);
146 #ifndef NDMOS_OPTION_NO_NDMP2
147 case NDMP2VER: return ndmp2_message_to_str (msg);
148 #endif /* !NDMOS_OPTION_NO_NDMP2 */
150 #ifndef NDMOS_OPTION_NO_NDMP3
151 case NDMP3VER: return ndmp3_message_to_str (msg);
152 #endif /* !NDMOS_OPTION_NO_NDMP3 */
154 #ifndef NDMOS_OPTION_NO_NDMP4
155 case NDMP4VER: return ndmp4_message_to_str (msg);
156 #endif /* !NDMOS_OPTION_NO_NDMP4 */
158 default: /* should never happen, if so should be rare */
159 sprintf (yikes_buf, "v%dmsg0x%04x", protocol_version, msg);
165 ndmp_error_to_str (int protocol_version, int err)
167 static char yikes_buf[40]; /* non-reentrant */
169 switch (protocol_version) {
170 case 0: return ndmp0_error_to_str (err);
171 case 9: return ndmp9_error_to_str (err);
172 #ifndef NDMOS_OPTION_NO_NDMP2
173 case NDMP2VER: return ndmp2_error_to_str (err);
174 #endif /* !NDMOS_OPTION_NO_NDMP2 */
176 #ifndef NDMOS_OPTION_NO_NDMP3
177 case NDMP3VER: return ndmp3_error_to_str (err);
178 #endif /* !NDMOS_OPTION_NO_NDMP3 */
180 #ifndef NDMOS_OPTION_NO_NDMP4
181 case NDMP4VER: return ndmp4_error_to_str (err);
182 #endif /* !NDMOS_OPTION_NO_NDMP4 */
184 default: /* should never happen, if so should be rare */
185 sprintf (yikes_buf, "v%derr%d", protocol_version, err);
196 ****************************************************************
200 ndmp_pp_header (int vers, void *data, char *buf)
204 return ndmp0_pp_header (data, buf);
206 #ifndef NDMOS_OPTION_NO_NDMP2
208 return ndmp2_pp_header (data, buf);
209 #endif /* !NDMOS_OPTION_NO_NDMP2 */
211 #ifndef NDMOS_OPTION_NO_NDMP3
213 return ndmp3_pp_header (data, buf);
214 #endif /* !NDMOS_OPTION_NO_NDMP3 */
216 #ifndef NDMOS_OPTION_NO_NDMP4
218 return ndmp4_pp_header (data, buf);
219 #endif /* !NDMOS_OPTION_NO_NDMP4 */
222 sprintf (buf, "V%d? ", vers);
223 return ndmp0_pp_header (data, NDMOS_API_STREND(buf));
228 ndmp_pp_request (int vers, int msg, void *data, int lineno, char *buf)
232 return ndmp0_pp_request (msg, data, lineno, buf);
234 #ifndef NDMOS_OPTION_NO_NDMP2
236 return ndmp2_pp_request (msg, data, lineno, buf);
237 #endif /* !NDMOS_OPTION_NO_NDMP2 */
239 #ifndef NDMOS_OPTION_NO_NDMP3
241 return ndmp3_pp_request (msg, data, lineno, buf);
242 #endif /* !NDMOS_OPTION_NO_NDMP3 */
244 #ifndef NDMOS_OPTION_NO_NDMP4
246 return ndmp4_pp_request (msg, data, lineno, buf);
247 #endif /* !NDMOS_OPTION_NO_NDMP4 */
250 sprintf (buf, "<<INVALID MSG VERS=%d>>", vers);
256 ndmp_pp_reply (int vers, int msg, void *data, int lineno, char *buf)
260 return ndmp0_pp_reply (msg, data, lineno, buf);
262 #ifndef NDMOS_OPTION_NO_NDMP2
264 return ndmp2_pp_reply (msg, data, lineno, buf);
265 #endif /* !NDMOS_OPTION_NO_NDMP2 */
267 #ifndef NDMOS_OPTION_NO_NDMP3
269 return ndmp3_pp_reply (msg, data, lineno, buf);
270 #endif /* !NDMOS_OPTION_NO_NDMP3 */
272 #ifndef NDMOS_OPTION_NO_NDMP4
274 return ndmp4_pp_reply (msg, data, lineno, buf);
275 #endif /* !NDMOS_OPTION_NO_NDMP4 */
278 sprintf (buf, "<<INVALID MSG VERS=%d>>", vers);