1 /*
2  * Copyright (c) 1998,1999,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 
41 
42 #ifndef NDMOS_OPTION_NO_NDMP4
43 
44 
45 int
ndmp4_pp_header(void * data,char * buf)46 ndmp4_pp_header (void *data, char *buf)
47 {
48 	ndmp4_header *		mh = (ndmp4_header *) data;
49 
50 	if (mh->message_type == NDMP4_MESSAGE_REQUEST) {
51 		sprintf (buf, "C %s %lu",
52 			ndmp4_message_to_str (mh->message_code),
53 			mh->sequence);
54 	} else if (mh->message_type == NDMP4_MESSAGE_REPLY) {
55 		sprintf (buf, "R %s %lu (%lu)",
56 			ndmp4_message_to_str (mh->message_code),
57 			mh->reply_sequence,
58 			mh->sequence);
59 		if (mh->error_code != NDMP4_NO_ERR) {
60 			sprintf (NDMOS_API_STREND(buf), " %s",
61 				ndmp4_error_to_str (mh->error_code));
62 			return 0;	/* no body */
63 		}
64 	} else {
65 		strcpy (buf, "??? INVALID MESSAGE TYPE");
66 		return -1;	/* no body */
67 	}
68 	return 1;	/* body */
69 }
70 
71 int
ndmp4_pp_addr(char * buf,ndmp4_addr * ma)72 ndmp4_pp_addr (char *buf, ndmp4_addr *ma)
73 {
74    unsigned int		i, j;
75    ndmp4_tcp_addr *	tcp;
76    uint32_t ip_in_host_order;
77 
78    sprintf (buf, "%s", ndmp4_addr_type_to_str (ma->addr_type));
79    if (ma->addr_type == NDMP4_ADDR_TCP) {
80       for (i = 0; i < ma->ndmp4_addr_u.tcp_addr.tcp_addr_len; i++) {
81          tcp = &ma->ndmp4_addr_u.tcp_addr.tcp_addr_val[i];
82 
83          char ip_addr[100];
84          ip_in_host_order = ntohl(tcp->ip_addr);
85          sprintf (NDMOS_API_STREND(buf), "%d(%s:%u",
86                i,
87                inet_ntop (AF_INET, &ip_in_host_order, ip_addr, sizeof(ip_addr)),
88                tcp->port);
89 
90          for (j = 0; j < tcp->addr_env.addr_env_len; j++) {
91             sprintf (NDMOS_API_STREND(buf), ",%s=%s",
92                   tcp->addr_env.addr_env_val[j].name,
93                   tcp->addr_env.addr_env_val[j].value);
94          }
95          sprintf (NDMOS_API_STREND(buf), ")");
96       }
97    }
98    return 0;
99 }
100 
101 
102 int
ndmp4_pp_request(ndmp4_message msg,void * data,int lineno,char * buf)103 ndmp4_pp_request (ndmp4_message msg, void *data, int lineno, char *buf)
104 {
105     int		    i;
106     unsigned int    j;
107 
108     switch (msg) {
109     default:
110 	strcpy (buf, "<<INVALID MSG>>");
111 	return -1;
112 
113     case NDMP4_CONNECT_OPEN:
114       NDMP_PP_WITH(ndmp4_connect_open_request)
115 	sprintf (buf, "version=%d", p->protocol_version);
116       NDMP_PP_ENDWITH
117       break;
118 
119     case NDMP4_CONNECT_CLIENT_AUTH:
120       NDMP_PP_WITH(ndmp4_connect_client_auth_request)
121 	sprintf (buf, "auth_type=%s",
122 		ndmp4_auth_type_to_str (p->auth_data.auth_type));
123 	sprintf (buf, "auth_type=%s",
124 		ndmp4_auth_type_to_str (p->auth_data.auth_type));
125 	switch (p->auth_data.auth_type) {
126 	case NDMP4_AUTH_NONE:
127 		break;
128 
129 	case NDMP4_AUTH_TEXT:
130 		sprintf (NDMOS_API_STREND(buf), " auth_id=%s",
131 			p->auth_data.ndmp4_auth_data_u.auth_text.auth_id);
132 		break;
133 
134 	case NDMP4_AUTH_MD5:
135 		sprintf (NDMOS_API_STREND(buf), " auth_id=%s",
136 			p->auth_data.ndmp4_auth_data_u.auth_md5.auth_id);
137 		break;
138 
139 	default:
140 		sprintf (NDMOS_API_STREND(buf), " ????");
141 		break;
142 	}
143       NDMP_PP_ENDWITH
144       break;
145 
146     case NDMP4_CONNECT_CLOSE:
147     case NDMP4_CONFIG_GET_HOST_INFO:
148     case NDMP4_CONFIG_GET_CONNECTION_TYPE:
149     case NDMP4_CONFIG_GET_SERVER_INFO:
150     case NDMP4_CONFIG_GET_TAPE_INFO:
151     case NDMP4_CONFIG_GET_SCSI_INFO:
152     case NDMP4_SCSI_CLOSE:
153     case NDMP4_SCSI_GET_STATE:
154     case NDMP4_SCSI_RESET_DEVICE:
155 /*  case NDMP4_SCSI_RESET_BUS: */
156     case NDMP4_TAPE_GET_STATE:
157     case NDMP4_TAPE_CLOSE:
158     case NDMP4_MOVER_GET_STATE:
159     case NDMP4_MOVER_CONTINUE:
160     case NDMP4_MOVER_ABORT:
161     case NDMP4_MOVER_STOP:
162     case NDMP4_MOVER_CLOSE:
163     case NDMP4_DATA_GET_STATE:
164     case NDMP4_DATA_ABORT:
165     case NDMP4_DATA_STOP:
166     case NDMP4_DATA_GET_ENV:
167 	*buf = 0;	/* no body */
168 	return 0;
169 
170     case NDMP4_CONNECT_SERVER_AUTH:
171 	strcpy (buf, "<<unimplemented pp>>");
172       break;
173 
174     case NDMP4_CONFIG_GET_AUTH_ATTR:
175       NDMP_PP_WITH(ndmp4_config_get_auth_attr_request)
176 	sprintf (buf, "auth_type=%s", ndmp4_auth_type_to_str (p->auth_type));
177       NDMP_PP_ENDWITH
178       break;
179 
180     case NDMP4_SCSI_OPEN:
181       NDMP_PP_WITH(ndmp4_scsi_open_request)
182 	sprintf (buf, "device='%s'", p->device);
183       NDMP_PP_ENDWITH
184       break;
185 
186 /*** deprecated
187     case NDMP4_SCSI_SET_TARGET:
188       NDMP_PP_WITH(ndmp4_scsi_set_target_request)
189 	sprintf (buf, "device='%s' cont=%d sid=%d lun=%d",
190 		p->device, p->target_controller,
191 		p->target_id, p->target_lun);
192       NDMP_PP_ENDWITH
193       break;
194 ***/
195 
196     case NDMP4_SCSI_EXECUTE_CDB:
197     case NDMP4_TAPE_EXECUTE_CDB:
198       NDMP_PP_WITH(ndmp4_execute_cdb_request)
199 	switch (lineno) {
200 	case 0:	sprintf (buf, "flags=0x%lx timeout=%ld datain_len=%ld",
201 			p->flags, p->timeout, p->datain_len);
202 		break;
203 	case 1: sprintf (buf, "cmd[%d]={", p->cdb.cdb_len);
204 		for (j = 0; j < p->cdb.cdb_len; j++) {
205 			sprintf (NDMOS_API_STREND(buf), " %02x",
206 						p->cdb.cdb_val[j]&0xFF);
207 		}
208 		strcat (buf, " }");
209 		break;
210 	}
211 	return 2;
212       NDMP_PP_ENDWITH
213       break;
214 
215     case NDMP4_TAPE_OPEN:
216       NDMP_PP_WITH(ndmp4_tape_open_request)
217 	sprintf (buf, "device='%s' mode=%s",
218 		p->device,
219 		ndmp4_tape_open_mode_to_str (p->mode));
220       NDMP_PP_ENDWITH
221       break;
222 
223     case NDMP4_TAPE_MTIO:
224       NDMP_PP_WITH(ndmp4_tape_mtio_request)
225 	sprintf (buf, "op=%s count=%ld",
226 		ndmp4_tape_mtio_op_to_str(p->tape_op),
227 		p->count);
228       NDMP_PP_ENDWITH
229       break;
230 
231     case NDMP4_TAPE_WRITE:
232       NDMP_PP_WITH(ndmp4_tape_write_request)
233 	sprintf (buf, "data_out_len=%d", p->data_out.data_out_len);
234       NDMP_PP_ENDWITH
235       break;
236 
237     case NDMP4_TAPE_READ:
238       NDMP_PP_WITH(ndmp4_tape_read_request)
239 	sprintf (buf, "count=%ld", p->count);
240       NDMP_PP_ENDWITH
241       break;
242 
243     case NDMP4_DATA_START_BACKUP:
244       NDMP_PP_WITH(ndmp4_data_start_backup_request)
245 	if (lineno == 0) {
246 		sprintf (buf, "butype_name='%s' n_env=%d",
247 			p->butype_name, p->env.env_len);
248 	} else {
249 		i = lineno - 1;
250 		if (0 <= i && (unsigned)i < p->env.env_len) {
251 			sprintf (buf, "env[%d] name='%s' value='%s'",
252 				i, p->env.env_val[i].name,
253 				p->env.env_val[i].value);
254 		} else {
255 			strcpy (buf, "--INVALID--");
256 		}
257 	}
258 	return 1 + p->env.env_len;
259       NDMP_PP_ENDWITH
260       break;
261 
262     case NDMP4_DATA_START_RECOVER:
263     case NDMP4_DATA_START_RECOVER_FILEHIST:
264       NDMP_PP_WITH(ndmp4_data_start_recover_request)
265 	if (lineno == 0) {
266 		sprintf (buf, "butype_name='%s' n_env=%d n_nlist=%d",
267 			p->butype_name, p->env.env_len,
268 			p->nlist.nlist_len);
269 	} else {
270 		i = lineno - 1;
271 		if (0 <= i && (unsigned)i < p->env.env_len) {
272 			sprintf (buf, "env[%d] name='%s' value='%s'",
273 				i, p->env.env_val[i].name,
274 				p->env.env_val[i].value);
275 		} else {
276 			i -= p->env.env_len;
277 			if (0 <= i && (unsigned)i < p->nlist.nlist_len*4) {
278 			    ndmp4_name *nm = &p->nlist.nlist_val[i/4];
279 
280 			    switch (i%4) {
281 			    case 0:
282 				sprintf (buf, "nl[%d] original_path='%s'",
283 					i/4, nm->original_path);
284 				break;
285 			    case 1:
286 				sprintf (buf, "..... destination_path='%s'",
287 					nm->destination_path);
288 				break;
289 			    case 2:
290 				sprintf (buf, "..... name='%s' other='%s'",
291 					nm->name, nm->other_name);
292 				break;
293 			    case 3:
294 				sprintf (buf, "..... node=%lld fh_info=%lld",
295 					nm->node, nm->fh_info);
296 				break;
297 			    }
298 			} else {
299 				strcpy (buf, "--INVALID--");
300 			}
301 		}
302 	}
303 	return 1 + p->env.env_len + p->nlist.nlist_len*4;
304       NDMP_PP_ENDWITH
305       break;
306 
307     case NDMP4_DATA_LISTEN:
308       NDMP_PP_WITH(ndmp4_data_listen_request)
309 	sprintf (buf, "addr_type=%s", ndmp4_addr_type_to_str (p->addr_type));
310       NDMP_PP_ENDWITH
311       break;
312 
313     case NDMP4_DATA_CONNECT:
314       NDMP_PP_WITH(ndmp4_data_connect_request)
315 	sprintf (buf, "addr=");
316 	ndmp4_pp_addr (NDMOS_API_STREND(buf), &p->addr);
317       NDMP_PP_ENDWITH
318       break;
319 
320     case NDMP4_NOTIFY_DATA_HALTED:
321       NDMP_PP_WITH(ndmp4_notify_data_halted_post)
322 	sprintf (buf, "reason=%s", ndmp4_data_halt_reason_to_str(p->reason));
323       NDMP_PP_ENDWITH
324       break;
325 
326     case NDMP4_NOTIFY_CONNECTION_STATUS:
327       NDMP_PP_WITH(ndmp4_notify_connection_status_post)
328 	sprintf (buf, "reason=%s protocol_version=%d text_reason='%s'",
329 		ndmp4_connection_status_reason_to_str(p->reason),
330 		p->protocol_version,
331 		p->text_reason);
332       NDMP_PP_ENDWITH
333       break;
334 
335     case NDMP4_NOTIFY_MOVER_HALTED:
336       NDMP_PP_WITH(ndmp4_notify_mover_halted_post)
337 	sprintf (buf, "reason=%s", ndmp4_mover_halt_reason_to_str(p->reason));
338       NDMP_PP_ENDWITH
339       break;
340 
341     case NDMP4_NOTIFY_MOVER_PAUSED:
342       NDMP_PP_WITH(ndmp4_notify_mover_paused_post)
343 	sprintf (buf, "reason=%s seek_position=%lld",
344 		ndmp4_mover_pause_reason_to_str(p->reason),
345 		p->seek_position);
346       NDMP_PP_ENDWITH
347       break;
348 
349     case NDMP4_NOTIFY_DATA_READ:
350       NDMP_PP_WITH(ndmp4_notify_data_read_post)
351 	sprintf (buf, "offset=%lld length=%lld",
352 		p->offset, p->length);
353       NDMP_PP_ENDWITH
354       break;
355 
356     case NDMP4_LOG_FILE:
357       NDMP_PP_WITH(ndmp4_log_file_post)
358 	sprintf (buf, "file=%s recovery_status=%s",
359 		p->name,
360 		ndmp4_recovery_status_to_str(p->recovery_status));
361       NDMP_PP_ENDWITH
362       break;
363 
364     case NDMP4_LOG_MESSAGE:
365       NDMP_PP_WITH(ndmp4_log_message_post)
366 	sprintf (buf, "log_type=%s id=%lu message='%s'",
367 		ndmp4_log_type_to_str(p->log_type), p->message_id, p->entry);
368       NDMP_PP_ENDWITH
369       break;
370 
371     case NDMP4_FH_ADD_FILE:
372       NDMP_PP_WITH(ndmp4_fh_add_file_post)
373 	int	n_line = 0, n_names = 0, n_stats = 0;
374         unsigned int n_normal = 0;
375 
376 	n_line++;
377 	for (j = 0; j < p->files.files_len; j++) {
378 		int	nn, ns;
379 
380 		nn = p->files.files_val[j].names.names_len;
381 		ns = p->files.files_val[j].stats.stats_len;
382 
383 		n_line += 1 + nn + ns;
384 		if (nn == 1 && ns == 1)
385 			n_normal++;
386 		n_names += nn;
387 		n_stats += ns;
388 	}
389 
390 	if (n_normal == p->files.files_len) {
391 		/* could do something more efficient here */
392 	}
393 
394 	if (lineno == 0) {
395 		sprintf (buf, "n_files=%d  total n_names=%d n_stats=%d",
396 			p->files.files_len, n_names, n_stats);
397 		return n_line;
398 	}
399 	lineno--;
400 	for (j = 0; j < p->files.files_len; j++) {
401 	    ndmp4_file *	file = &p->files.files_val[j];
402 	    unsigned int		k;
403 
404 	    if (lineno == 0) {
405 		sprintf (buf, "[%ud] n_names=%d n_stats=%d node=%lld fhinfo=%lld",
406 			j,
407 			file->names.names_len,
408 			file->stats.stats_len,
409 			file->node,
410 			file->fh_info);
411 		return n_line;
412 	    }
413 
414 	    lineno--;
415 
416 	    for (k = 0; k < file->names.names_len; k++, lineno--) {
417 		ndmp4_file_name *filename;
418 
419 		if (lineno != 0)
420 			continue;
421 
422 		filename = &file->names.names_val[k];
423 
424 		sprintf (buf, "  name[%ud] fs_type=%s",
425 			k, ndmp4_fs_type_to_str (filename->fs_type));
426 
427 		switch (filename->fs_type) {
428 		default:
429 			sprintf (NDMOS_API_STREND(buf), " other=%s",
430 				filename->ndmp4_file_name_u.other_name);
431 			break;
432 
433 		case NDMP4_FS_UNIX:
434 			sprintf (NDMOS_API_STREND(buf), " unix=%s",
435 				filename->ndmp4_file_name_u.unix_name);
436 			break;
437 
438 		case NDMP4_FS_NT:
439 			sprintf (NDMOS_API_STREND(buf)," nt=%s dos=%s",
440 				filename->ndmp4_file_name_u.nt_name.nt_path,
441 				filename->ndmp4_file_name_u.nt_name.dos_path);
442 			break;
443 		}
444 		return n_line;
445 	    }
446 
447 	    for (k = 0; k < file->stats.stats_len; k++, lineno--) {
448 		ndmp4_file_stat *filestat;
449 
450 		if (lineno != 0)
451 			continue;
452 
453 		filestat = &file->stats.stats_val[k];
454 
455 		sprintf (buf, "  stat[%d] fs_type=%s ftype=%s size=%lld",
456 			k,
457 			ndmp4_fs_type_to_str (filestat->fs_type),
458 			ndmp4_file_type_to_str (filestat->ftype),
459 			filestat->size);
460 
461 		return n_line;
462 	    }
463 	}
464 	sprintf (buf, "  YIKES n_line=%d lineno=%d", n_line, lineno);
465 	return -1;
466       NDMP_PP_ENDWITH
467       break;
468 
469     case NDMP4_FH_ADD_DIR:
470       NDMP_PP_WITH(ndmp4_fh_add_dir_post)
471 	int	n_line = 0, n_names = 0;
472         unsigned int n_normal = 0;
473 
474 	n_line++;
475 	for (j = 0; j < p->dirs.dirs_len; j++) {
476 		int	nn;
477 
478 		nn = p->dirs.dirs_val[j].names.names_len;
479 
480 		n_line += 1 + nn;
481 		if (nn == 1)
482 			n_normal++;
483 		n_names += nn;
484 	}
485 
486 	if (n_normal == p->dirs.dirs_len) {
487 		/* could do something more efficient here */
488 	}
489 
490 	if (lineno == 0) {
491 		sprintf (buf, "n_dirs=%d  total n_names=%d",
492 			p->dirs.dirs_len, n_names);
493 		return n_line;
494 	}
495 	lineno--;
496 	for (j = 0; j < p->dirs.dirs_len; j++) {
497 	    ndmp4_dir *		dir = &p->dirs.dirs_val[j];
498 	    unsigned int	k;
499 
500 	    if (lineno == 0) {
501 		sprintf (buf, "[%ud] n_names=%d node=%lld parent=%lld",
502 			j,
503 			dir->names.names_len,
504 			dir->node,
505 			dir->parent);
506 		return n_line;
507 	    }
508 
509 	    lineno--;
510 
511 	    for (k = 0; k < dir->names.names_len; k++, lineno--) {
512 		ndmp4_file_name *filename;
513 
514 		if (lineno != 0)
515 			continue;
516 
517 		filename = &dir->names.names_val[k];
518 
519 		sprintf (buf, "  name[%d] fs_type=%s",
520 			k, ndmp4_fs_type_to_str (filename->fs_type));
521 
522 		switch (filename->fs_type) {
523 		default:
524 			sprintf (NDMOS_API_STREND(buf), " other=%s",
525 				filename->ndmp4_file_name_u.other_name);
526 			break;
527 
528 		case NDMP4_FS_UNIX:
529 			sprintf (NDMOS_API_STREND(buf), " unix=%s",
530 				filename->ndmp4_file_name_u.unix_name);
531 			break;
532 
533 		case NDMP4_FS_NT:
534 			sprintf (NDMOS_API_STREND(buf)," nt=%s dos=%s",
535 				filename->ndmp4_file_name_u.nt_name.nt_path,
536 				filename->ndmp4_file_name_u.nt_name.dos_path);
537 			break;
538 		}
539 		return n_line;
540 	    }
541 	}
542 	sprintf (buf, "  YIKES n_line=%d lineno=%d", n_line, lineno);
543 	return -1;
544       NDMP_PP_ENDWITH
545       break;
546 
547     case NDMP4_FH_ADD_NODE:
548       NDMP_PP_WITH(ndmp4_fh_add_node_post)
549 	int	n_line = 0, n_stats = 0;
550         unsigned int n_normal = 0;
551 
552 	n_line++;
553 	for (j = 0; j < p->nodes.nodes_len; j++) {
554 		int	ns;
555 
556 		ns = p->nodes.nodes_val[j].stats.stats_len;
557 
558 		n_line += 1 + ns;
559 		if (ns == 1)
560 			n_normal++;
561 		n_stats += ns;
562 	}
563 
564 	if (n_normal == p->nodes.nodes_len) {
565 		/* could do something more efficient here */
566 	}
567 
568 	if (lineno == 0) {
569 		sprintf (buf, "n_nodes=%d  total n_stats=%d",
570 			p->nodes.nodes_len, n_stats);
571 		return n_line;
572 	}
573 	lineno--;
574 	for (j = 0; j < p->nodes.nodes_len; j++) {
575 	    ndmp4_node *	node = &p->nodes.nodes_val[j];
576 	    unsigned int	k;
577 
578 	    if (lineno == 0) {
579 		sprintf (buf, "[%ud] n_stats=%d node=%lld fhinfo=%lld",
580 			j,
581 			node->stats.stats_len,
582 			node->node,
583 			node->fh_info);
584 		return n_line;
585 	    }
586 
587 	    lineno--;
588 
589 	    for (k = 0; k < node->stats.stats_len; k++, lineno--) {
590 		ndmp4_file_stat *filestat;
591 
592 		if (lineno != 0)
593 			continue;
594 
595 		filestat = &node->stats.stats_val[k];
596 
597 		sprintf (buf, "  stat[%ud] fs_type=%s ftype=%s size=%lld",
598 			k,
599 			ndmp4_fs_type_to_str (filestat->fs_type),
600 			ndmp4_file_type_to_str (filestat->ftype),
601 			filestat->size);
602 
603 		return n_line;
604 	    }
605 	}
606 	sprintf (buf, "  YIKES n_line=%d lineno=%d", n_line, lineno);
607 	return -1;
608       NDMP_PP_ENDWITH
609       break;
610 
611     case NDMP4_MOVER_LISTEN:
612       NDMP_PP_WITH(ndmp4_mover_listen_request)
613 	sprintf (buf, "mode=%s addr_type=%s",
614 		ndmp4_mover_mode_to_str (p->mode),
615 		ndmp4_addr_type_to_str (p->addr_type));
616       NDMP_PP_ENDWITH
617       break;
618 
619     case NDMP4_MOVER_SET_WINDOW:
620       NDMP_PP_WITH(ndmp4_mover_set_window_request)
621 	sprintf (buf, "offset=%lld length=%lld", p->offset, p->length);
622       NDMP_PP_ENDWITH
623       break;
624 
625     case NDMP4_MOVER_READ:
626       NDMP_PP_WITH(ndmp4_mover_read_request)
627 	sprintf (buf, "offset=%lld length=%lld", p->offset, p->length);
628       NDMP_PP_ENDWITH
629       break;
630 
631     case NDMP4_MOVER_SET_RECORD_SIZE:
632       NDMP_PP_WITH(ndmp4_mover_set_record_size_request)
633 	sprintf (buf, "len=%lu", p->len);
634       NDMP_PP_ENDWITH
635       break;
636 
637     case NDMP4_MOVER_CONNECT:
638       NDMP_PP_WITH(ndmp4_mover_connect_request)
639 	sprintf (buf, "mode=%s addr=", ndmp4_mover_mode_to_str (p->mode));
640 	ndmp4_pp_addr (NDMOS_API_STREND(buf), &p->addr);
641       NDMP_PP_ENDWITH
642       break;
643 
644     }
645     return 1;	/* one line in buf */
646 }
647 
648 
649 
650 int
ndmp4_pp_reply(ndmp4_message msg,void * data,int lineno,char * buf)651 ndmp4_pp_reply (ndmp4_message msg, void *data, int lineno, char *buf)
652 {
653     int		    i;
654     unsigned int    j;
655 
656     switch (msg) {
657     default:
658 	strcpy (buf, "<<INVALID MSG>>");
659 	return -1;
660 
661     case NDMP4_CONNECT_OPEN:
662     case NDMP4_CONNECT_CLIENT_AUTH:
663     case NDMP4_SCSI_OPEN:
664     case NDMP4_SCSI_CLOSE:
665 /*  case NDMP4_SCSI_SET_TARGET: */
666     case NDMP4_SCSI_RESET_DEVICE:
667 /*  case NDMP4_SCSI_RESET_BUS: */
668     case NDMP4_TAPE_OPEN:
669     case NDMP4_TAPE_CLOSE:
670     case NDMP4_MOVER_CONTINUE:
671     case NDMP4_MOVER_ABORT:
672     case NDMP4_MOVER_STOP:
673     case NDMP4_MOVER_READ:
674     case NDMP4_MOVER_SET_WINDOW:
675     case NDMP4_MOVER_CLOSE:
676     case NDMP4_MOVER_SET_RECORD_SIZE:
677     case NDMP4_MOVER_CONNECT:
678     case NDMP4_DATA_START_BACKUP:
679     case NDMP4_DATA_START_RECOVER:
680     case NDMP4_DATA_START_RECOVER_FILEHIST:
681     case NDMP4_DATA_ABORT:
682     case NDMP4_DATA_STOP:
683     case NDMP4_DATA_CONNECT:
684       NDMP_PP_WITH(ndmp4_error)
685 	sprintf (buf, "error=%s", ndmp4_error_to_str(*p));
686       NDMP_PP_ENDWITH
687       break;
688 
689     case NDMP4_CONNECT_CLOSE:
690 	*buf = 0;
691 	return 0;
692 
693     case NDMP4_CONNECT_SERVER_AUTH:
694 	strcpy (buf, "<<unimplemented pp>>");
695       break;
696 
697     case NDMP4_CONFIG_GET_HOST_INFO:
698       NDMP_PP_WITH(ndmp4_config_get_host_info_reply)
699 	switch (lineno) {
700 	case 0: sprintf (buf, "error=%s hostname=%s",
701 			ndmp4_error_to_str(p->error),
702 			p->hostname);
703 		break;
704 	case 1: sprintf (buf, "os_type=%s os_vers=%s hostid=%s",
705 			p->os_type, p->os_vers, p->hostid);
706 		break;
707 	default:
708 		strcpy (buf, "--INVALID--");
709 		break;
710 	}
711 	return 2;
712       NDMP_PP_ENDWITH
713       break;
714 
715     case NDMP4_CONFIG_GET_CONNECTION_TYPE:
716       NDMP_PP_WITH(ndmp4_config_get_connection_type_reply)
717 	sprintf (buf, "error=%s addr_types[%d]={",
718 			ndmp4_error_to_str(p->error),
719 			p->addr_types.addr_types_len);
720 	for (j = 0; j < p->addr_types.addr_types_len; j++) {
721 		sprintf (NDMOS_API_STREND(buf), " %s",
722 			 ndmp4_addr_type_to_str(p->addr_types.addr_types_val[j]));
723 	}
724 	strcat (buf, " }");
725       NDMP_PP_ENDWITH
726       break;
727 
728 
729     case NDMP4_CONFIG_GET_SERVER_INFO:
730     case NDMP4_CONFIG_GET_TAPE_INFO:
731     case NDMP4_CONFIG_GET_SCSI_INFO:
732 	strcpy (buf, "<<unimplemented pp>>");
733       break;
734 
735     case NDMP4_CONFIG_GET_AUTH_ATTR:
736 	strcpy (buf, "<<unimplemented pp>>");
737       break;
738 
739     case NDMP4_SCSI_GET_STATE:
740       NDMP_PP_WITH(ndmp4_scsi_get_state_reply)
741 	sprintf (buf, "error=%s cont=%d sid=%d lun=%d",
742 		ndmp4_error_to_str(p->error),
743 		p->target_controller,
744 		p->target_id, p->target_lun);
745       NDMP_PP_ENDWITH
746       break;
747 
748     case NDMP4_SCSI_EXECUTE_CDB:
749     case NDMP4_TAPE_EXECUTE_CDB:
750       NDMP_PP_WITH(ndmp4_execute_cdb_reply)
751 	switch (lineno) {
752 	case 0:	sprintf (buf,
753 			"error=%s status=%02x dataout_len=%ld datain_len=%d",
754 			ndmp4_error_to_str(p->error),
755 			p->status, p->dataout_len, p->datain.datain_len);
756 		break;
757 	case 1: sprintf (buf, "sense[%d]={", p->ext_sense.ext_sense_len);
758 		for (j = 0; j < p->ext_sense.ext_sense_len; j++) {
759 			sprintf (NDMOS_API_STREND(buf), " %02x",
760 					p->ext_sense.ext_sense_val[j]&0xFF);
761 		}
762 		strcat (buf, " }");
763 		break;
764 	}
765 	return 2;
766       NDMP_PP_ENDWITH
767       break;
768 
769     case NDMP4_TAPE_GET_STATE:
770       NDMP_PP_WITH(ndmp4_tape_get_state_reply)
771 	switch (lineno) {
772 	case 0:	sprintf (buf, "unsupp=%lx error=%s flags=0x%lx file_num=%ld",
773 			p->unsupported,
774 			ndmp4_error_to_str(p->error),
775 			p->flags, p->file_num);
776 		break;
777 	case 1:	sprintf (buf, "soft_errors=%lu block_size=%lu blockno=%lu",
778 			p->soft_errors, p->block_size, p->blockno);
779 		break;
780 	case 2:	sprintf (buf, "total_space=%lld space_remain=%lld",
781 			p->total_space, p->space_remain);
782 		break;
783 	default:
784 		strcpy (buf, "--INVALID--");
785 		break;
786 	}
787 	return 3;
788       NDMP_PP_ENDWITH
789       break;
790 
791     case NDMP4_TAPE_MTIO:
792       NDMP_PP_WITH(ndmp4_tape_mtio_reply)
793 	sprintf (buf, "error=%s resid_count=%ld",
794 		ndmp4_error_to_str(p->error), p->resid_count);
795       NDMP_PP_ENDWITH
796       break;
797 
798     case NDMP4_TAPE_WRITE:
799       NDMP_PP_WITH(ndmp4_tape_write_reply)
800 	sprintf (buf, "error=%s count=%ld",
801 		ndmp4_error_to_str(p->error), p->count);
802       NDMP_PP_ENDWITH
803       break;
804 
805     case NDMP4_TAPE_READ:
806       NDMP_PP_WITH(ndmp4_tape_read_reply)
807 	sprintf (buf, "error=%s data_in_len=%d",
808 		ndmp4_error_to_str(p->error), p->data_in.data_in_len);
809       NDMP_PP_ENDWITH
810       break;
811 
812     case NDMP4_DATA_GET_STATE:
813       NDMP_PP_WITH(ndmp4_data_get_state_reply)
814 	switch (lineno) {
815 	case 0:	sprintf (buf, "unsupp=%lx error=%s op=%s",
816 			p->unsupported,
817 			ndmp4_error_to_str(p->error),
818 			ndmp4_data_operation_to_str(p->operation));
819 		break;
820 	case 1:	sprintf (buf, "state=%s",
821 			ndmp4_data_state_to_str(p->state));
822 		break;
823 	case 2:	sprintf (buf, "halt_reason=%s",
824 			ndmp4_data_halt_reason_to_str(p->halt_reason));
825 		break;
826 	case 3:	sprintf (buf, "bytes_processed=%lld est_bytes_remain=%lld",
827 			p->bytes_processed, p->est_bytes_remain);
828 		break;
829 	case 4:	sprintf (buf, "est_time_remain=%ld data_conn_addr=",
830 			p->est_time_remain);
831 		ndmp4_pp_addr (NDMOS_API_STREND(buf),
832 					&p->data_connection_addr);
833 		break;
834 	case 5: sprintf (buf, "read_offset=%lld read_length=%lld",
835 			p->read_offset, p->read_length);
836 		break;
837 	default:
838 		strcpy (buf, "--INVALID--");
839 		break;
840 	}
841 	return 6;
842       NDMP_PP_ENDWITH
843       break;
844 
845     case NDMP4_DATA_GET_ENV:
846       NDMP_PP_WITH(ndmp4_data_get_env_reply)
847 	if (lineno == 0) {
848 		sprintf (buf, "error=%s n_env=%d",
849 			ndmp4_error_to_str(p->error),
850 			p->env.env_len);
851 	} else {
852 		i = lineno - 1;
853 		if (0 <= i && (unsigned)i < p->env.env_len) {
854 			sprintf (buf, "[%d] name='%s' value='%s'",
855 				i, p->env.env_val[i].name,
856 				p->env.env_val[i].value);
857 		} else {
858 			strcpy (buf, "--INVALID--");
859 		}
860 	}
861 	return p->env.env_len + 1;
862       NDMP_PP_ENDWITH
863       break;
864 
865     case NDMP4_NOTIFY_DATA_HALTED:
866     case NDMP4_NOTIFY_CONNECTION_STATUS:
867     case NDMP4_NOTIFY_MOVER_HALTED:
868     case NDMP4_NOTIFY_MOVER_PAUSED:
869     case NDMP4_NOTIFY_DATA_READ:
870     case NDMP4_LOG_FILE:
871     case NDMP4_LOG_MESSAGE:
872     case NDMP4_FH_ADD_FILE:
873     case NDMP4_FH_ADD_DIR:
874     case NDMP4_FH_ADD_NODE:
875 	strcpy (buf, "<<ILLEGAL REPLY>>");
876       break;
877 
878     case NDMP4_MOVER_GET_STATE:
879       NDMP_PP_WITH(ndmp4_mover_get_state_reply)
880 	switch (lineno) {
881 	case 0:	sprintf (buf, "error=%s state=%s",
882 			ndmp4_error_to_str(p->error),
883 			ndmp4_mover_state_to_str(p->state));
884 		break;
885 	case 1:	sprintf (buf, "pause_reason=%s",
886 			ndmp4_mover_pause_reason_to_str(p->pause_reason));
887 		break;
888 	case 2:	sprintf (buf, "halt_reason=%s",
889 			ndmp4_mover_halt_reason_to_str(p->halt_reason));
890 		break;
891 	case 3:	sprintf (buf,"record_size=%lu record_num=%lu bytes_moved=%lld",
892 			p->record_size, p->record_num, p->bytes_moved);
893 		break;
894 	case 4:	sprintf (buf, "seek=%lld to_read=%lld win_off=%lld win_len=%lld",
895 			p->seek_position, p->bytes_left_to_read,
896 			p->window_offset, p->window_length);
897 		break;
898 	case 5: sprintf (buf, "data_conn_addr=");
899 		ndmp4_pp_addr (NDMOS_API_STREND(buf),
900 					&p->data_connection_addr);
901 		break;
902 	default:
903 		strcpy (buf, "--INVALID--");
904 		break;
905 	}
906 	return 6;
907       NDMP_PP_ENDWITH
908       break;
909 
910     case NDMP4_MOVER_LISTEN:
911       NDMP_PP_WITH(ndmp4_mover_listen_reply)
912 	sprintf (buf, "error=%s data_conn_addr=",
913 				ndmp4_error_to_str(p->error));
914 	ndmp4_pp_addr (NDMOS_API_STREND(buf), &p->connect_addr);
915       NDMP_PP_ENDWITH
916       break;
917     }
918 
919     return 1;	/* one line in buf */
920 }
921 
922 #endif /* !NDMOS_OPTION_NO_NDMP4 */
923