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