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
43 ndmnmb_find_xdrproc (struct ndmp_msg_buf *nmb)
45 struct ndmp_xdr_message_table * xmte;
47 xmte = ndmp_xmt_lookup (nmb->protocol_version, nmb->header.message);
53 if (nmb->header.message_type == NDMP0_MESSAGE_REQUEST) {
54 return (xdrproc_t) xmte->xdr_request;
57 if (nmb->header.message_type == NDMP0_MESSAGE_REPLY) {
58 return (xdrproc_t) xmte->xdr_reply;
65 ndmnmb_free (struct ndmp_msg_buf *nmb)
67 xdrproc_t xdr_body = ndmnmb_find_xdrproc (nmb);
69 if (nmb->flags & NDMNMB_FLAG_NO_FREE)
73 xdr_free (xdr_body, (void*) &nmb->body);
82 struct ndmp_msg_buf *nmb,
91 if (level < 6 && nmb->protocol_version == 4) {
92 ndmp4_header *header = (ndmp4_header *)&nmb->header;
93 if ((header->message_code == NDMP4_NOTIFY_DATA_HALTED &&
94 header->error_code == NDMP4_DATA_HALT_SUCCESSFUL) ||
95 (header->message_code == NDMP4_NOTIFY_MOVER_HALTED &&
96 header->error_code == NDMP4_MOVER_HALT_CONNECT_CLOSED)) {
103 if (!log || level < 5) {
107 rc = ndmp_pp_header (nmb->protocol_version, &nmb->header, buf);
109 ndmlogf (log, tag, level5, "%s %s", buf, whence);
114 if (*whence == 'R') {
123 ndmlogf (log, tag, level5, "%s %s", combo, buf+2);
130 if (rc <= 0) { /* no body */
134 if (nmb->header.message_type == NDMP0_MESSAGE_REQUEST) {
135 ndmpp = ndmp_pp_request;
136 } else if (nmb->header.message_type == NDMP0_MESSAGE_REPLY) {
137 ndmpp = ndmp_pp_reply;
139 return; /* should not happen */
143 for (i = 0; i < nl; i++) {
144 nl = (*ndmpp)(nmb->protocol_version,
145 nmb->header.message, &nmb->body, i, buf);
147 break; /* no printable body (void) */
149 ndmlogf (log, tag, level6, " %s", buf);
154 ndmnmb_get_reply_error_raw (struct ndmp_msg_buf *nmb)
156 unsigned protocol_version = nmb->protocol_version;
157 unsigned msg = nmb->header.message;
160 if (NDMNMB_IS_UNFORTUNATE_REPLY_TYPE(protocol_version, msg)) {
161 raw_error = nmb->body.unf3_error.error;
163 raw_error = nmb->body.error;
170 ndmnmb_get_reply_error (struct ndmp_msg_buf *nmb)
172 unsigned protocol_version = nmb->protocol_version;
173 unsigned raw_error = ndmnmb_get_reply_error_raw (nmb);
176 switch (protocol_version) {
179 error = (ndmp9_error) raw_error;
182 #ifndef NDMOS_OPTION_NO_NDMP2
185 ndmp2_error error2 = raw_error;
187 ndmp_2to9_error (&error2, &error);
190 #endif /* !NDMOS_OPTION_NO_NDMP2 */
192 #ifndef NDMOS_OPTION_NO_NDMP3
195 ndmp3_error error3 = raw_error;
197 ndmp_3to9_error (&error3, &error);
200 #endif /* !NDMOS_OPTION_NO_NDMP3 */
202 #ifndef NDMOS_OPTION_NO_NDMP4
205 ndmp4_error error4 = raw_error;
207 ndmp_4to9_error (&error4, &error);
210 #endif /* !NDMOS_OPTION_NO_NDMP4 */
217 ndmnmb_set_reply_error_raw (struct ndmp_msg_buf *nmb, unsigned raw_error)
219 unsigned protocol_version = nmb->protocol_version;
220 unsigned msg = nmb->header.message;
222 if (NDMNMB_IS_UNFORTUNATE_REPLY_TYPE(protocol_version, msg)) {
223 nmb->body.unf3_error.error = raw_error;
225 nmb->body.error = raw_error;
232 ndmnmb_set_reply_error (struct ndmp_msg_buf *nmb, ndmp9_error error)
234 unsigned protocol_version = nmb->protocol_version;
237 switch (protocol_version) {
240 raw_error = (unsigned) error;
243 #ifndef NDMOS_OPTION_NO_NDMP2
248 ndmp_9to2_error (&error, &error2);
249 raw_error = (unsigned) error2;
252 #endif /* !NDMOS_OPTION_NO_NDMP2 */
254 #ifndef NDMOS_OPTION_NO_NDMP3
259 ndmp_9to3_error (&error, &error3);
260 raw_error = (unsigned) error3;
263 #endif /* !NDMOS_OPTION_NO_NDMP3 */
265 #ifndef NDMOS_OPTION_NO_NDMP4
270 ndmp_9to4_error (&error, &error4);
271 raw_error = (unsigned) error4;
274 #endif /* !NDMOS_OPTION_NO_NDMP4 */
277 return ndmnmb_set_reply_error_raw (nmb, raw_error);