Imported Upstream version 3.1.0
[debian/amanda] / ndmp-src / ndmp_translate.h
1 /*
2  * Copyright (c) 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
39
40 /*
41  * conversion macros
42  ****************************************************************
43  * These make things a bit more readable and less error prone.
44  * They also foster consistency.
45  */
46
47
48 /* straight assignments */
49 #define CNVT_TO_9(PX, P9, MEMBER)       ((P9)->MEMBER = (PX)->MEMBER)
50 #define CNVT_FROM_9(PX, P9, MEMBER)     ((PX)->MEMBER = (P9)->MEMBER)
51 #define CNVT_TO_9x(PX, P9, MEMBERX, MEMBER9)    ((P9)->MEMBER9 = (PX)->MEMBERX)
52 #define CNVT_FROM_9x(PX, P9, MEMBERX, MEMBER9)  ((PX)->MEMBERX = (P9)->MEMBER9)
53
54 /* enum conversion */
55 #define CNVT_E_TO_9(PX, P9, MEMBER, ENUM_CONVERSION_TABLE) \
56     ((P9)->MEMBER = convert_enum_to_9 (ENUM_CONVERSION_TABLE, (PX)->MEMBER))
57
58 #define CNVT_E_FROM_9(PX, P9, MEMBER, ENUM_CONVERSION_TABLE) \
59     ((PX)->MEMBER = convert_enum_from_9 (ENUM_CONVERSION_TABLE, (P9)->MEMBER))
60
61 #define CNVT_VUL_TO_9(PX, P9, MEMBER) \
62     convert_valid_u_long_to_9 (&(PX)->MEMBER, &(P9)->MEMBER)
63
64 #define CNVT_VUL_FROM_9(PX, P9, MEMBER) \
65     convert_valid_u_long_from_9 (&(PX)->MEMBER, &(P9)->MEMBER)
66
67 #define CNVT_VUL_TO_9x(PX, P9, MEMBERX, MEMBER9) \
68     convert_valid_u_long_to_9 (&(PX)->MEMBERX, &(P9)->MEMBER9)
69
70 #define CNVT_VUL_FROM_9x(PX, P9, MEMBERX, MEMBER9) \
71     convert_valid_u_long_from_9 (&(PX)->MEMBERX, &(P9)->MEMBER9)
72
73 #define CNVT_IUL_TO_9(P9, MEMBER) \
74     convert_invalid_u_long_9 (&(P9)->MEMBER)
75
76 #define CNVT_VUQ_TO_9(PX, P9, MEMBER) \
77     convert_valid_u_quad_to_9 (&(PX)->MEMBER, &(P9)->MEMBER)
78
79 #define CNVT_VUQ_FROM_9(PX, P9, MEMBER) \
80     convert_valid_u_quad_from_9 (&(PX)->MEMBER, &(P9)->MEMBER)
81
82 #define CNVT_VUQ_TO_9x(PX, P9, MEMBERX, MEMBER9) \
83     convert_valid_u_quad_to_9 (&(PX)->MEMBERX, &(P9)->MEMBER9)
84
85 #define CNVT_VUQ_FROM_9x(PX, P9, MEMBERX, MEMBER9) \
86     convert_valid_u_quad_from_9 (&(PX)->MEMBERX, &(P9)->MEMBER9)
87
88 #define CNVT_IUQ_TO_9(P9, MEMBER) \
89     convert_invalid_u_quad_9 (&(P9)->MEMBER)
90
91 #define CNVT_STRDUP_TO_9(PX, P9, MEMBER) \
92     convert_strdup ((PX)->MEMBER, &(P9)->MEMBER)
93
94 #define CNVT_STRDUP_FROM_9(PX, P9, MEMBER) \
95     convert_strdup ((P9)->MEMBER, &(PX)->MEMBER)
96
97 #define CNVT_STRDUP_TO_9x(PX, P9, MEMBERX, MEMBER9) \
98     convert_strdup ((PX)->MEMBERX, &(P9)->MEMBER9)
99
100 #define CNVT_STRDUP_FROM_9x(PX, P9, MEMBERX, MEMBER9) \
101     convert_strdup ((P9)->MEMBER9, &(PX)->MEMBERX)
102
103
104
105 /*
106  * enum_conversion tables
107  ****************************************************************
108  * Used to make enum conversion convenient and dense.
109  * The first row is the default case in both directions,
110  * and is skipped while attempting precise conversion.
111  * The search stops with the first match.
112  */
113
114 struct enum_conversion {
115         int     enum_x;
116         int     enum_9;
117 };
118
119 #define END_ENUM_CONVERSION_TABLE               { -1, -1 }
120 #define IS_END_ENUM_CONVERSION_TABLE(EC) \
121                 ((EC)->enum_x == -1 && (EC)->enum_9 == -1)
122
123
124
125 extern int      /* ndmp9_.... */
126 convert_enum_to_9 (struct enum_conversion *ectab, int enum_x);
127 extern int      /* ndmpx_.... */
128 convert_enum_from_9 (struct enum_conversion *ectab, int enum_9);
129 extern int
130 convert_valid_u_long_to_9 (u_long *valx, ndmp9_valid_u_long *val9);
131 extern int
132 convert_valid_u_long_from_9 (u_long *valx, ndmp9_valid_u_long *val9);
133 extern int
134 convert_invalid_u_long_9 (struct ndmp9_valid_u_long *val9);
135 extern int
136 convert_valid_u_quad_to_9 (ndmp9_u_quad *valx, ndmp9_valid_u_quad *val9);
137 extern int
138 convert_valid_u_quad_from_9 (ndmp9_u_quad *valx, ndmp9_valid_u_quad *val9);
139 extern int
140 convert_invalid_u_quad_9 (struct ndmp9_valid_u_quad *val9);
141 extern int
142 convert_strdup (char *src, char **dstp);
143
144
145
146 /*
147  * request/reply translation tables
148  ****************************************************************
149  */
150
151 struct reqrep_xlate {
152         int             vx_message;
153         ndmp9_message   v9_message;
154
155         int             (*request_xto9) (/* void *vxbody, void *v9body */);
156         int             (*request_9tox) (/* void *v9body, void *vxbody */);
157         int             (*reply_xto9) (/* void *vxbody, void *v9body */);
158         int             (*reply_9tox) (/* void *v9body, void *vxbody */);
159
160         int             (*free_request_xto9) (/* void *v9body */);
161         int             (*free_request_9tox) (/* void *vxbody */);
162         int             (*free_reply_xto9) (/* void *v9body */);
163         int             (*free_reply_9tox) (/* void *vxbody */);
164
165 };
166
167 struct reqrep_xlate_version_table {
168         int                             protocol_version;
169         struct reqrep_xlate *           reqrep_xlate_table;
170 };
171
172 extern struct reqrep_xlate_version_table        reqrep_xlate_version_table[];
173
174 extern struct reqrep_xlate *reqrep_xlate_lookup_version (
175                                 struct reqrep_xlate_version_table *rrvt,
176                                 unsigned protocol_version);
177
178 extern struct reqrep_xlate *ndmp_reqrep_by_v9 (struct reqrep_xlate *table,
179                                 ndmp9_message v9_message);
180 extern struct reqrep_xlate *ndmp_reqrep_by_vx (struct reqrep_xlate *table,
181                                 int vx_message);
182
183 extern int      ndmp_xtox_no_arguments (void *vxbody, void *vybody);
184
185 extern int      ndmp_xtox_no_memused (void *vxbody);
186
187
188
189
190 /*
191  * PROTOCOL VERSIONS
192  ****************************************************************
193  *
194  */
195
196 #ifndef NDMOS_OPTION_NO_NDMP2
197 #include "ndmp2_translate.h"
198 #endif /* !NDMOS_OPTION_NO_NDMP2 */
199
200 #ifndef NDMOS_OPTION_NO_NDMP3
201 #include "ndmp3_translate.h"
202 #endif /* !NDMOS_OPTION_NO_NDMP3 */
203
204 #ifndef NDMOS_OPTION_NO_NDMP4
205 #include "ndmp4_translate.h"
206 #endif /* !NDMOS_OPTION_NO_NDMP4 */
207