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_NDMP3
43 
44 
45 int
ndmp3_pp_header(void * data,char * buf)46 ndmp3_pp_header (void *data, char *buf)
47 {
48 	ndmp3_header *		mh = (ndmp3_header *) data;
49 
50 	if (mh->message_type == NDMP3_MESSAGE_REQUEST) {
51 		sprintf (buf, "C %s %lu",
52 			ndmp3_message_to_str (mh->message),
53 			mh->sequence);
54 	} else if (mh->message_type == NDMP3_MESSAGE_REPLY) {
55 		sprintf (buf, "R %s %lu (%lu)",
56 			ndmp3_message_to_str (mh->message),
57 			mh->reply_sequence,
58 			mh->sequence);
59 		if (mh->error != NDMP3_NO_ERR) {
60 			sprintf (NDMOS_API_STREND(buf), " %s",
61 				ndmp3_error_to_str (mh->error));
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
ndmp3_pp_addr(char * buf,ndmp3_addr * ma)72 ndmp3_pp_addr (char *buf, ndmp3_addr *ma)
73 {
74 	sprintf (buf, "%s", ndmp3_addr_type_to_str (ma->addr_type));
75 	if (ma->addr_type == NDMP3_ADDR_TCP) {
76 		sprintf (NDMOS_API_STREND(buf), "(%lx,%d)",
77 			ma->ndmp3_addr_u.tcp_addr.ip_addr,
78 			ma->ndmp3_addr_u.tcp_addr.port);
79 	}
80 	return 0;
81 }
82 
83 
84 int
ndmp3_pp_request(ndmp3_message msg,void * data,int lineno,char * buf)85 ndmp3_pp_request (ndmp3_message msg, void *data, int lineno, char *buf)
86 {
87     int			i;
88     unsigned int	j;
89 
90     switch (msg) {
91     default:
92 	strcpy (buf, "<<INVALID MSG>>");
93 	return -1;
94 
95     case NDMP3_CONNECT_OPEN:
96       NDMP_PP_WITH(ndmp3_connect_open_request)
97 	sprintf (buf, "version=%d", p->protocol_version);
98       NDMP_PP_ENDWITH
99       break;
100 
101     case NDMP3_CONNECT_CLIENT_AUTH:
102       NDMP_PP_WITH(ndmp3_connect_client_auth_request)
103 	sprintf (buf, "auth_type=%s",
104 		ndmp3_auth_type_to_str (p->auth_data.auth_type));
105 	sprintf (buf, "auth_type=%s",
106 		ndmp3_auth_type_to_str (p->auth_data.auth_type));
107 	switch (p->auth_data.auth_type) {
108 	case NDMP3_AUTH_NONE:
109 		break;
110 
111 	case NDMP3_AUTH_TEXT:
112 		sprintf (NDMOS_API_STREND(buf), " auth_id=%s",
113 			p->auth_data.ndmp3_auth_data_u.auth_text.auth_id);
114 		break;
115 
116 	case NDMP3_AUTH_MD5:
117 		sprintf (NDMOS_API_STREND(buf), " auth_id=%s",
118 			p->auth_data.ndmp3_auth_data_u.auth_md5.auth_id);
119 		break;
120 
121 	default:
122 		sprintf (NDMOS_API_STREND(buf), " ????");
123 		break;
124 	}
125       NDMP_PP_ENDWITH
126       break;
127 
128     case NDMP3_CONNECT_CLOSE:
129     case NDMP3_CONFIG_GET_HOST_INFO:
130     case NDMP3_CONFIG_GET_CONNECTION_TYPE:
131     case NDMP3_CONFIG_GET_SERVER_INFO:
132     case NDMP3_CONFIG_GET_BUTYPE_INFO:
133     case NDMP3_CONFIG_GET_FS_INFO:
134     case NDMP3_CONFIG_GET_TAPE_INFO:
135     case NDMP3_CONFIG_GET_SCSI_INFO:
136     case NDMP3_SCSI_CLOSE:
137     case NDMP3_SCSI_GET_STATE:
138     case NDMP3_SCSI_RESET_DEVICE:
139     case NDMP3_SCSI_RESET_BUS:
140     case NDMP3_TAPE_GET_STATE:
141     case NDMP3_TAPE_CLOSE:
142     case NDMP3_MOVER_GET_STATE:
143     case NDMP3_MOVER_CONTINUE:
144     case NDMP3_MOVER_ABORT:
145     case NDMP3_MOVER_STOP:
146     case NDMP3_MOVER_CLOSE:
147     case NDMP3_DATA_GET_STATE:
148     case NDMP3_DATA_ABORT:
149     case NDMP3_DATA_STOP:
150     case NDMP3_DATA_GET_ENV:
151 	*buf = 0;	/* no body */
152 	return 0;
153 
154     case NDMP3_CONNECT_SERVER_AUTH:
155 	strcpy (buf, "<<unimplemented pp>>");
156       break;
157 
158     case NDMP3_CONFIG_GET_AUTH_ATTR:
159       NDMP_PP_WITH(ndmp3_config_get_auth_attr_request)
160 	sprintf (buf, "auth_type=%s", ndmp3_auth_type_to_str (p->auth_type));
161       NDMP_PP_ENDWITH
162       break;
163 
164     case NDMP3_SCSI_OPEN:
165       NDMP_PP_WITH(ndmp3_scsi_open_request)
166 	sprintf (buf, "device='%s'", p->device);
167       NDMP_PP_ENDWITH
168       break;
169 
170     case NDMP3_SCSI_SET_TARGET:
171       NDMP_PP_WITH(ndmp3_scsi_set_target_request)
172 	sprintf (buf, "device='%s' cont=%d sid=%d lun=%d",
173 		p->device, p->target_controller,
174 		p->target_id, p->target_lun);
175       NDMP_PP_ENDWITH
176       break;
177 
178     case NDMP3_SCSI_EXECUTE_CDB:
179     case NDMP3_TAPE_EXECUTE_CDB:
180       NDMP_PP_WITH(ndmp3_execute_cdb_request)
181 	switch (lineno) {
182 	case 0:	sprintf (buf, "flags=0x%lx timeout=%ld datain_len=%ld",
183 			p->flags, p->timeout, p->datain_len);
184 		break;
185 	case 1: sprintf (buf, "cmd[%d]={", p->cdb.cdb_len);
186 		for (j = 0; j < p->cdb.cdb_len; j++) {
187 			sprintf (NDMOS_API_STREND(buf), " %02x",
188 						p->cdb.cdb_val[j]&0xFF);
189 		}
190 		strcat (buf, " }");
191 		break;
192 	}
193 	return 2;
194       NDMP_PP_ENDWITH
195       break;
196 
197     case NDMP3_TAPE_OPEN:
198       NDMP_PP_WITH(ndmp3_tape_open_request)
199 	sprintf (buf, "device='%s' mode=%s",
200 		p->device,
201 		ndmp3_tape_open_mode_to_str (p->mode));
202       NDMP_PP_ENDWITH
203       break;
204 
205     case NDMP3_TAPE_MTIO:
206       NDMP_PP_WITH(ndmp3_tape_mtio_request)
207 	sprintf (buf, "op=%s count=%ld",
208 		ndmp3_tape_mtio_op_to_str(p->tape_op),
209 		p->count);
210       NDMP_PP_ENDWITH
211       break;
212 
213     case NDMP3_TAPE_WRITE:
214       NDMP_PP_WITH(ndmp3_tape_write_request)
215 	sprintf (buf, "data_out_len=%d", p->data_out.data_out_len);
216       NDMP_PP_ENDWITH
217       break;
218 
219     case NDMP3_TAPE_READ:
220       NDMP_PP_WITH(ndmp3_tape_read_request)
221 	sprintf (buf, "count=%ld", p->count);
222       NDMP_PP_ENDWITH
223       break;
224 
225     case NDMP3_DATA_START_BACKUP:
226       NDMP_PP_WITH(ndmp3_data_start_backup_request)
227 	if (lineno == 0) {
228 		sprintf (buf, "bu_type='%s' n_env=%d",
229 			p->bu_type, p->env.env_len);
230 	} else {
231 		i = lineno - 1;
232 		if (0 <= i && (unsigned)i < p->env.env_len) {
233 			sprintf (buf, "env[%d] name='%s' value='%s'",
234 				i, p->env.env_val[i].name,
235 				p->env.env_val[i].value);
236 		} else {
237 			strcpy (buf, "--INVALID--");
238 		}
239 	}
240 	return 1 + p->env.env_len;
241       NDMP_PP_ENDWITH
242       break;
243 
244     case NDMP3_DATA_START_RECOVER:
245     case NDMP3_DATA_START_RECOVER_FILEHIST:
246       NDMP_PP_WITH(ndmp3_data_start_recover_request)
247 	if (lineno == 0) {
248 		sprintf (buf, "bu_type='%s' n_env=%d n_nlist=%d",
249 			p->bu_type, p->env.env_len,
250 			p->nlist.nlist_len);
251 	} else {
252 		i = lineno - 1;
253 		if (0 <= i && (unsigned)i < p->env.env_len) {
254 			sprintf (buf, "env[%d] name='%s' value='%s'",
255 				i, p->env.env_val[i].name,
256 				p->env.env_val[i].value);
257 		} else {
258 			i -= p->env.env_len;
259 			if (0 <= i && (unsigned)i < p->nlist.nlist_len*4) {
260 			    ndmp3_name *nm = &p->nlist.nlist_val[i/4];
261 
262 			    switch (i%4) {
263 			    case 0:
264 				sprintf (buf, "nl[%d] original_path='%s'",
265 					i/4, nm->original_path);
266 				break;
267 			    case 1:
268 				sprintf (buf, "..... destination_dir='%s'",
269 					nm->destination_dir);
270 				break;
271 			    case 2:
272 				sprintf (buf, "..... new_name='%s' other='%s'",
273 					nm->new_name, nm->other_name);
274 				break;
275 			    case 3:
276 				sprintf (buf, "..... node=%lld fh_info=%lld",
277 					nm->node, nm->fh_info);
278 				break;
279 			    }
280 			} else {
281 				strcpy (buf, "--INVALID--");
282 			}
283 		}
284 	}
285 	return 1 + p->env.env_len + p->nlist.nlist_len*4;
286       NDMP_PP_ENDWITH
287       break;
288 
289     case NDMP3_DATA_LISTEN:
290       NDMP_PP_WITH(ndmp3_data_listen_request)
291 	sprintf (buf, "addr_type=%s", ndmp3_addr_type_to_str (p->addr_type));
292       NDMP_PP_ENDWITH
293       break;
294 
295     case NDMP3_DATA_CONNECT:
296       NDMP_PP_WITH(ndmp3_data_connect_request)
297 	sprintf (buf, "addr=");
298 	ndmp3_pp_addr (NDMOS_API_STREND(buf), &p->addr);
299       NDMP_PP_ENDWITH
300       break;
301 
302     case NDMP3_NOTIFY_DATA_HALTED:
303       NDMP_PP_WITH(ndmp3_notify_data_halted_request)
304 	sprintf (buf, "reason=%s text_reason='%s'",
305 		ndmp3_data_halt_reason_to_str(p->reason),
306 		p->text_reason);
307       NDMP_PP_ENDWITH
308       break;
309 
310     case NDMP3_NOTIFY_CONNECTED:
311       NDMP_PP_WITH(ndmp3_notify_connected_request)
312 	sprintf (buf, "reason=%s protocol_version=%d text_reason='%s'",
313 		ndmp3_connect_reason_to_str(p->reason),
314 		p->protocol_version,
315 		p->text_reason);
316       NDMP_PP_ENDWITH
317       break;
318 
319     case NDMP3_NOTIFY_MOVER_HALTED:
320       NDMP_PP_WITH(ndmp3_notify_mover_halted_request)
321 	sprintf (buf, "reason=%s text_reason='%s'",
322 		ndmp3_mover_halt_reason_to_str(p->reason),
323 		p->text_reason);
324       NDMP_PP_ENDWITH
325       break;
326 
327     case NDMP3_NOTIFY_MOVER_PAUSED:
328       NDMP_PP_WITH(ndmp3_notify_mover_paused_request)
329 	sprintf (buf, "reason=%s seek_position=%lld",
330 		ndmp3_mover_pause_reason_to_str(p->reason),
331 		p->seek_position);
332       NDMP_PP_ENDWITH
333       break;
334 
335     case NDMP3_NOTIFY_DATA_READ:
336       NDMP_PP_WITH(ndmp3_notify_data_read_request)
337 	sprintf (buf, "offset=%lld length=%lld",
338 		p->offset, p->length);
339       NDMP_PP_ENDWITH
340       break;
341 
342     case NDMP3_LOG_FILE:
343       NDMP_PP_WITH(ndmp3_log_file_request)
344 	sprintf (buf, "file=%s error=%s",
345 		p->name,
346 		ndmp3_error_to_str(p->error));
347       NDMP_PP_ENDWITH
348       break;
349 
350     case NDMP3_LOG_MESSAGE:
351       NDMP_PP_WITH(ndmp3_log_message_request)
352 	sprintf (buf, "log_type=%s id=%lu message='%s'",
353 		ndmp3_log_type_to_str(p->log_type), p->message_id, p->entry);
354       NDMP_PP_ENDWITH
355       break;
356 
357     case NDMP3_FH_ADD_FILE:
358       NDMP_PP_WITH(ndmp3_fh_add_file_request)
359 	int	n_line = 0, n_names = 0, n_stats = 0;
360 	unsigned int n_normal = 0;
361 
362 	n_line++;
363 	for (j = 0; j < p->files.files_len; j++) {
364 		int	nn, ns;
365 
366 		nn = p->files.files_val[j].names.names_len;
367 		ns = p->files.files_val[j].stats.stats_len;
368 
369 		n_line += 1 + nn + ns;
370 		if (nn == 1 && ns == 1)
371 			n_normal++;
372 		n_names += nn;
373 		n_stats += ns;
374 	}
375 
376 	if (n_normal == p->files.files_len) {
377 		/* could do something more efficient here */
378 	}
379 
380 	if (lineno == 0) {
381 		sprintf (buf, "n_files=%d  total n_names=%d n_stats=%d",
382 			p->files.files_len, n_names, n_stats);
383 		return n_line;
384 	}
385 	lineno--;
386 	for (j = 0; j < p->files.files_len; j++) {
387 	    ndmp3_file *	file = &p->files.files_val[j];
388 	    unsigned int	k;
389 
390 	    if (lineno == 0) {
391 		sprintf (buf, "[%d] n_names=%d n_stats=%d node=%lld fhinfo=%lld",
392 			j,
393 			file->names.names_len,
394 			file->stats.stats_len,
395 			file->node,
396 			file->fh_info);
397 		return n_line;
398 	    }
399 
400 	    lineno--;
401 
402 	    for (k = 0; k < file->names.names_len; k++, lineno--) {
403 		ndmp3_file_name *filename;
404 
405 		if (lineno != 0)
406 			continue;
407 
408 		filename = &file->names.names_val[k];
409 
410 		sprintf (buf, "  name[%d] fs_type=%s",
411 			k, ndmp3_fs_type_to_str (filename->fs_type));
412 
413 		switch (filename->fs_type) {
414 		default:
415 			sprintf (NDMOS_API_STREND(buf), " other=%s",
416 				filename->ndmp3_file_name_u.other_name);
417 			break;
418 
419 		case NDMP3_FS_UNIX:
420 			sprintf (NDMOS_API_STREND(buf), " unix=%s",
421 				filename->ndmp3_file_name_u.unix_name);
422 			break;
423 
424 		case NDMP3_FS_NT:
425 			sprintf (NDMOS_API_STREND(buf)," nt=%s dos=%s",
426 				filename->ndmp3_file_name_u.nt_name.nt_path,
427 				filename->ndmp3_file_name_u.nt_name.dos_path);
428 			break;
429 		}
430 		return n_line;
431 	    }
432 
433 	    for (k = 0; k < file->stats.stats_len; k++, lineno--) {
434 		ndmp3_file_stat *filestat;
435 
436 		if (lineno != 0)
437 			continue;
438 
439 		filestat = &file->stats.stats_val[k];
440 
441 		sprintf (buf, "  stat[%ud] fs_type=%s ftype=%s size=%lld",
442 			k,
443 			ndmp3_fs_type_to_str (filestat->fs_type),
444 			ndmp3_file_type_to_str (filestat->ftype),
445 			filestat->size);
446 
447 		return n_line;
448 	    }
449 	}
450 	sprintf (buf, "  YIKES n_line=%d lineno=%d", n_line, lineno);
451 	return -1;
452       NDMP_PP_ENDWITH
453       break;
454 
455     case NDMP3_FH_ADD_DIR:
456       NDMP_PP_WITH(ndmp3_fh_add_dir_request)
457 	int	n_line = 0, n_names = 0;
458         unsigned int n_normal = 0;
459 
460 	n_line++;
461 	for (j = 0; j < p->dirs.dirs_len; j++) {
462 		int	nn;
463 
464 		nn = p->dirs.dirs_val[j].names.names_len;
465 
466 		n_line += 1 + nn;
467 		if (nn == 1)
468 			n_normal++;
469 		n_names += nn;
470 	}
471 
472 	if (n_normal == p->dirs.dirs_len) {
473 		/* could do something more efficient here */
474 	}
475 
476 	if (lineno == 0) {
477 		sprintf (buf, "n_dirs=%d  total n_names=%d",
478 			p->dirs.dirs_len, n_names);
479 		return n_line;
480 	}
481 	lineno--;
482 	for (j = 0; j < p->dirs.dirs_len; j++) {
483 	    ndmp3_dir *		dir = &p->dirs.dirs_val[j];
484 	    unsigned int	k;
485 
486 	    if (lineno == 0) {
487 		sprintf (buf, "[%ud] n_names=%d node=%lld parent=%lld",
488 			j,
489 			dir->names.names_len,
490 			dir->node,
491 			dir->parent);
492 		return n_line;
493 	    }
494 
495 	    lineno--;
496 
497 	    for (k = 0; k < dir->names.names_len; k++, lineno--) {
498 		ndmp3_file_name *filename;
499 
500 		if (lineno != 0)
501 			continue;
502 
503 		filename = &dir->names.names_val[k];
504 
505 		sprintf (buf, "  name[%ud] fs_type=%s",
506 			k, ndmp3_fs_type_to_str (filename->fs_type));
507 
508 		switch (filename->fs_type) {
509 		default:
510 			sprintf (NDMOS_API_STREND(buf), " other=%s",
511 				filename->ndmp3_file_name_u.other_name);
512 			break;
513 
514 		case NDMP3_FS_UNIX:
515 			sprintf (NDMOS_API_STREND(buf), " unix=%s",
516 				filename->ndmp3_file_name_u.unix_name);
517 			break;
518 
519 		case NDMP3_FS_NT:
520 			sprintf (NDMOS_API_STREND(buf)," nt=%s dos=%s",
521 				filename->ndmp3_file_name_u.nt_name.nt_path,
522 				filename->ndmp3_file_name_u.nt_name.dos_path);
523 			break;
524 		}
525 		return n_line;
526 	    }
527 	}
528 	sprintf (buf, "  YIKES n_line=%d lineno=%d", n_line, lineno);
529 	return -1;
530       NDMP_PP_ENDWITH
531       break;
532 
533     case NDMP3_FH_ADD_NODE:
534       NDMP_PP_WITH(ndmp3_fh_add_node_request)
535 	int	n_line = 0, n_stats = 0;
536         unsigned int n_normal = 0;
537 
538 	n_line++;
539 	for (j = 0; j < p->nodes.nodes_len; j++) {
540 		int	ns;
541 
542 		ns = p->nodes.nodes_val[j].stats.stats_len;
543 
544 		n_line += 1 + ns;
545 		if (ns == 1)
546 			n_normal++;
547 		n_stats += ns;
548 	}
549 
550 	if (n_normal == p->nodes.nodes_len) {
551 		/* could do something more efficient here */
552 	}
553 
554 	if (lineno == 0) {
555 		sprintf (buf, "n_nodes=%d  total n_stats=%d",
556 			p->nodes.nodes_len, n_stats);
557 		return n_line;
558 	}
559 	lineno--;
560 	for (j = 0; j < p->nodes.nodes_len; j++) {
561 	    ndmp3_node *	node = &p->nodes.nodes_val[j];
562 	    unsigned int	k;
563 
564 	    if (lineno == 0) {
565 		sprintf (buf, "[%ud] n_stats=%d node=%lld fhinfo=%lld",
566 			j,
567 			node->stats.stats_len,
568 			node->node,
569 			node->fh_info);
570 		return n_line;
571 	    }
572 
573 	    lineno--;
574 
575 	    for (k = 0; k < node->stats.stats_len; k++, lineno--) {
576 		ndmp3_file_stat *filestat;
577 
578 		if (lineno != 0)
579 			continue;
580 
581 		filestat = &node->stats.stats_val[k];
582 
583 		sprintf (buf, "  stat[%ud] fs_type=%s ftype=%s size=%lld",
584 			k,
585 			ndmp3_fs_type_to_str (filestat->fs_type),
586 			ndmp3_file_type_to_str (filestat->ftype),
587 			filestat->size);
588 
589 		return n_line;
590 	    }
591 	}
592 	sprintf (buf, "  YIKES n_line=%d lineno=%d", n_line, lineno);
593 	return -1;
594       NDMP_PP_ENDWITH
595       break;
596 
597     case NDMP3_MOVER_LISTEN:
598       NDMP_PP_WITH(ndmp3_mover_listen_request)
599 	sprintf (buf, "mode=%s addr_type=%s",
600 		ndmp3_mover_mode_to_str (p->mode),
601 		ndmp3_addr_type_to_str (p->addr_type));
602       NDMP_PP_ENDWITH
603       break;
604 
605     case NDMP3_MOVER_SET_WINDOW:
606       NDMP_PP_WITH(ndmp3_mover_set_window_request)
607 	sprintf (buf, "offset=%lld length=%lld", p->offset, p->length);
608       NDMP_PP_ENDWITH
609       break;
610 
611     case NDMP3_MOVER_READ:
612       NDMP_PP_WITH(ndmp3_mover_read_request)
613 	sprintf (buf, "offset=%lld length=%lld", p->offset, p->length);
614       NDMP_PP_ENDWITH
615       break;
616 
617     case NDMP3_MOVER_SET_RECORD_SIZE:
618       NDMP_PP_WITH(ndmp3_mover_set_record_size_request)
619 	sprintf (buf, "len=%lu", p->len);
620       NDMP_PP_ENDWITH
621       break;
622 
623     case NDMP3_MOVER_CONNECT:
624       NDMP_PP_WITH(ndmp3_mover_connect_request)
625 	sprintf (buf, "mode=%s addr=", ndmp3_mover_mode_to_str (p->mode));
626 	ndmp3_pp_addr (NDMOS_API_STREND(buf), &p->addr);
627       NDMP_PP_ENDWITH
628       break;
629 
630     }
631     return 1;	/* one line in buf */
632 }
633 
634 
635 
636 int
ndmp3_pp_reply(ndmp3_message msg,void * data,int lineno,char * buf)637 ndmp3_pp_reply (ndmp3_message msg, void *data, int lineno, char *buf)
638 {
639     int		    i;
640     unsigned int    j;
641 
642     switch (msg) {
643     default:
644 	strcpy (buf, "<<INVALID MSG>>");
645 	return -1;
646 
647     case NDMP3_CONNECT_OPEN:
648     case NDMP3_CONNECT_CLIENT_AUTH:
649     case NDMP3_SCSI_OPEN:
650     case NDMP3_SCSI_CLOSE:
651     case NDMP3_SCSI_SET_TARGET:
652     case NDMP3_SCSI_RESET_DEVICE:
653     case NDMP3_SCSI_RESET_BUS:
654     case NDMP3_TAPE_OPEN:
655     case NDMP3_TAPE_CLOSE:
656     case NDMP3_MOVER_CONTINUE:
657     case NDMP3_MOVER_ABORT:
658     case NDMP3_MOVER_STOP:
659     case NDMP3_MOVER_READ:
660     case NDMP3_MOVER_SET_WINDOW:
661     case NDMP3_MOVER_CLOSE:
662     case NDMP3_MOVER_SET_RECORD_SIZE:
663     case NDMP3_MOVER_CONNECT:
664     case NDMP3_DATA_START_BACKUP:
665     case NDMP3_DATA_START_RECOVER:
666     case NDMP3_DATA_START_RECOVER_FILEHIST:
667     case NDMP3_DATA_ABORT:
668     case NDMP3_DATA_STOP:
669     case NDMP3_DATA_CONNECT:
670       NDMP_PP_WITH(ndmp3_error)
671 	sprintf (buf, "error=%s", ndmp3_error_to_str(*p));
672       NDMP_PP_ENDWITH
673       break;
674 
675     case NDMP3_CONFIG_GET_CONNECTION_TYPE:
676       NDMP_PP_WITH(ndmp3_config_get_connection_type_reply)
677 	sprintf (buf, "error=%s addr_types[%d]={",
678 			ndmp3_error_to_str(p->error),
679 			p->addr_types.addr_types_len);
680 	for (j = 0; j < p->addr_types.addr_types_len; j++) {
681 		sprintf (NDMOS_API_STREND(buf), " %s",
682 			 ndmp3_addr_type_to_str(p->addr_types.addr_types_val[j]));
683 	}
684 	strcat (buf, " }");
685       NDMP_PP_ENDWITH
686       break;
687 
688     case NDMP3_CONFIG_GET_SERVER_INFO:
689     case NDMP3_CONFIG_GET_BUTYPE_INFO:
690     case NDMP3_CONFIG_GET_FS_INFO:
691     case NDMP3_CONFIG_GET_TAPE_INFO:
692     case NDMP3_CONFIG_GET_SCSI_INFO:
693 	strcpy (buf, "<<unimplemented pp>>");
694       break;
695 
696     case NDMP3_CONNECT_CLOSE:
697 	*buf = 0;
698 	return 0;
699 
700     case NDMP3_CONNECT_SERVER_AUTH:
701 	strcpy (buf, "<<unimplemented pp>>");
702       break;
703 
704     case NDMP3_CONFIG_GET_HOST_INFO:
705       NDMP_PP_WITH(ndmp3_config_get_host_info_reply)
706 	switch (lineno) {
707 	case 0: sprintf (buf, "error=%s hostname=%s",
708 			ndmp3_error_to_str(p->error),
709 			p->hostname);
710 		break;
711 	case 1: sprintf (buf, "os_type=%s os_vers=%s hostid=%s",
712 			p->os_type, p->os_vers, p->hostid);
713 		break;
714 	default:
715 		strcpy (buf, "--INVALID--");
716 		break;
717 	}
718 	return 2;
719       NDMP_PP_ENDWITH
720       break;
721 
722     case NDMP3_CONFIG_GET_AUTH_ATTR:
723 	strcpy (buf, "<<unimplemented pp>>");
724       break;
725 
726     case NDMP3_SCSI_GET_STATE:
727       NDMP_PP_WITH(ndmp3_scsi_get_state_reply)
728 	sprintf (buf, "error=%s cont=%d sid=%d lun=%d",
729 		ndmp3_error_to_str(p->error),
730 		p->target_controller,
731 		p->target_id, p->target_lun);
732       NDMP_PP_ENDWITH
733       break;
734 
735     case NDMP3_SCSI_EXECUTE_CDB:
736     case NDMP3_TAPE_EXECUTE_CDB:
737       NDMP_PP_WITH(ndmp3_execute_cdb_reply)
738 	switch (lineno) {
739 	case 0:	sprintf (buf,
740 			"error=%s status=%02x dataout_len=%ld datain_len=%d",
741 			ndmp3_error_to_str(p->error),
742 			p->status, p->dataout_len, p->datain.datain_len);
743 		break;
744 	case 1: sprintf (buf, "sense[%d]={", p->ext_sense.ext_sense_len);
745 		for (j = 0; j < p->ext_sense.ext_sense_len; j++) {
746 			sprintf (NDMOS_API_STREND(buf), " %02x",
747 					p->ext_sense.ext_sense_val[j]&0xFF);
748 		}
749 		strcat (buf, " }");
750 		break;
751 	}
752 	return 2;
753       NDMP_PP_ENDWITH
754       break;
755 
756     case NDMP3_TAPE_GET_STATE:
757       NDMP_PP_WITH(ndmp3_tape_get_state_reply)
758 	switch (lineno) {
759 	case 0:	sprintf (buf, "invalid=%lx error=%s flags=0x%lx file_num=%ld",
760 			p->invalid,
761 			ndmp3_error_to_str(p->error),
762 			p->flags, p->file_num);
763 		break;
764 	case 1:	sprintf (buf, "soft_errors=%lu block_size=%lu blockno=%lu",
765 			p->soft_errors, p->block_size, p->blockno);
766 		break;
767 	case 2:	sprintf (buf, "total_space=%lld space_remain=%lld partition=%lu",
768 			p->total_space, p->space_remain, p->partition);
769 		break;
770 	default:
771 		strcpy (buf, "--INVALID--");
772 		break;
773 	}
774 	return 3;
775       NDMP_PP_ENDWITH
776       break;
777 
778     case NDMP3_TAPE_MTIO:
779       NDMP_PP_WITH(ndmp3_tape_mtio_reply)
780 	sprintf (buf, "error=%s resid_count=%ld",
781 		ndmp3_error_to_str(p->error), p->resid_count);
782       NDMP_PP_ENDWITH
783       break;
784 
785     case NDMP3_TAPE_WRITE:
786       NDMP_PP_WITH(ndmp3_tape_write_reply)
787 	sprintf (buf, "error=%s count=%ld",
788 		ndmp3_error_to_str(p->error), p->count);
789       NDMP_PP_ENDWITH
790       break;
791 
792     case NDMP3_TAPE_READ:
793       NDMP_PP_WITH(ndmp3_tape_read_reply)
794 	sprintf (buf, "error=%s data_in_len=%d",
795 		ndmp3_error_to_str(p->error), p->data_in.data_in_len);
796       NDMP_PP_ENDWITH
797       break;
798 
799     case NDMP3_DATA_GET_STATE:
800       NDMP_PP_WITH(ndmp3_data_get_state_reply)
801 	switch (lineno) {
802 	case 0:	sprintf (buf, "invalid=%lx error=%s op=%s",
803 			p->invalid,
804 			ndmp3_error_to_str(p->error),
805 			ndmp3_data_operation_to_str(p->operation));
806 		break;
807 	case 1:	sprintf (buf, "state=%s",
808 			ndmp3_data_state_to_str(p->state));
809 		break;
810 	case 2:	sprintf (buf, "halt_reason=%s",
811 			ndmp3_data_halt_reason_to_str(p->halt_reason));
812 		break;
813 	case 3:	sprintf (buf, "bytes_processed=%lld est_bytes_remain=%lld",
814 			p->bytes_processed, p->est_bytes_remain);
815 		break;
816 	case 4:	sprintf (buf, "est_time_remain=%ld data_conn_addr=",
817 			p->est_time_remain);
818 		ndmp3_pp_addr (NDMOS_API_STREND(buf),
819 					&p->data_connection_addr);
820 		break;
821 	case 5: sprintf (buf, "read_offset=%lld read_length=%lld",
822 			p->read_offset, p->read_length);
823 		break;
824 	default:
825 		strcpy (buf, "--INVALID--");
826 		break;
827 	}
828 	return 6;
829       NDMP_PP_ENDWITH
830       break;
831 
832     case NDMP3_DATA_GET_ENV:
833       NDMP_PP_WITH(ndmp3_data_get_env_reply)
834 	if (lineno == 0) {
835 		sprintf (buf, "error=%s n_env=%d",
836 			ndmp3_error_to_str(p->error),
837 			p->env.env_len);
838 	} else {
839 		i = lineno - 1;
840 		if (0 <= i && (unsigned)i < p->env.env_len) {
841 			sprintf (buf, "[%d] name='%s' value='%s'",
842 				i, p->env.env_val[i].name,
843 				p->env.env_val[i].value);
844 		} else {
845 			strcpy (buf, "--INVALID--");
846 		}
847 	}
848 	return p->env.env_len + 1;
849       NDMP_PP_ENDWITH
850       break;
851 
852     case NDMP3_NOTIFY_DATA_HALTED:
853     case NDMP3_NOTIFY_CONNECTED:
854     case NDMP3_NOTIFY_MOVER_HALTED:
855     case NDMP3_NOTIFY_MOVER_PAUSED:
856     case NDMP3_NOTIFY_DATA_READ:
857     case NDMP3_LOG_FILE:
858     case NDMP3_LOG_MESSAGE:
859     case NDMP3_FH_ADD_FILE:
860     case NDMP3_FH_ADD_DIR:
861     case NDMP3_FH_ADD_NODE:
862 	strcpy (buf, "<<ILLEGAL REPLY>>");
863       break;
864 
865     case NDMP3_MOVER_GET_STATE:
866       NDMP_PP_WITH(ndmp3_mover_get_state_reply)
867 	switch (lineno) {
868 	case 0:	sprintf (buf, "error=%s state=%s",
869 			ndmp3_error_to_str(p->error),
870 			ndmp3_mover_state_to_str(p->state));
871 		break;
872 	case 1:	sprintf (buf, "pause_reason=%s",
873 			ndmp3_mover_pause_reason_to_str(p->pause_reason));
874 		break;
875 	case 2:	sprintf (buf, "halt_reason=%s",
876 			ndmp3_mover_halt_reason_to_str(p->halt_reason));
877 		break;
878 	case 3:	sprintf (buf,"record_size=%lu record_num=%lu data_written=%lld",
879 			p->record_size, p->record_num, p->data_written);
880 		break;
881 	case 4:	sprintf (buf, "seek=%lld to_read=%lld win_off=%lld win_len=%lld",
882 			p->seek_position, p->bytes_left_to_read,
883 			p->window_offset, p->window_length);
884 		break;
885 	case 5: sprintf (buf, "data_conn_addr=");
886 		ndmp3_pp_addr (NDMOS_API_STREND(buf),
887 					&p->data_connection_addr);
888 		break;
889 	default:
890 		strcpy (buf, "--INVALID--");
891 		break;
892 	}
893 	return 6;
894       NDMP_PP_ENDWITH
895       break;
896 
897     case NDMP3_DATA_LISTEN:
898       NDMP_PP_WITH(ndmp3_data_listen_reply)
899 	sprintf (buf, "error=%s mover_conn_addr=",
900 				ndmp3_error_to_str(p->error));
901 	ndmp3_pp_addr (NDMOS_API_STREND(buf), &p->data_connection_addr);
902       NDMP_PP_ENDWITH
903       break;
904 
905     case NDMP3_MOVER_LISTEN:
906       NDMP_PP_WITH(ndmp3_mover_listen_reply)
907 	sprintf (buf, "error=%s data_conn_addr=",
908 				ndmp3_error_to_str(p->error));
909 	ndmp3_pp_addr (NDMOS_API_STREND(buf), &p->data_connection_addr);
910       NDMP_PP_ENDWITH
911       break;
912     }
913 
914     return 1;	/* one line in buf */
915 }
916 
917 #endif /* !NDMOS_OPTION_NO_NDMP3 */
918