2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
28 * $Id: amfeatures.c,v 1.24 2006/07/19 17:46:07 martinea Exp $
30 * Feature test related code.
34 #include "amfeatures.h"
37 *=====================================================================
38 * Initialize the base feature set for this version of Amanda.
40 * am_feature_t *am_init_feature_set()
43 * exit: dynamically allocated feature set structure
44 *=====================================================================
48 am_init_feature_set(void)
52 if ((f = am_allocate_feature_set()) != NULL) {
54 * Whenever a new feature is added, a new line usually needs
55 * to be added here to show that we support it.
57 am_add_feature(f, have_feature_support);
58 am_add_feature(f, fe_options_auth);
60 am_add_feature(f, fe_selfcheck_req);
61 am_add_feature(f, fe_selfcheck_req_device);
62 am_add_feature(f, fe_selfcheck_rep);
63 am_add_feature(f, fe_sendsize_req_no_options);
64 am_add_feature(f, fe_sendsize_req_options);
65 am_add_feature(f, fe_sendsize_req_device);
66 am_add_feature(f, fe_sendsize_rep);
67 am_add_feature(f, fe_sendbackup_req);
68 am_add_feature(f, fe_sendbackup_req_device);
69 am_add_feature(f, fe_sendbackup_rep);
70 am_add_feature(f, fe_noop_req);
71 am_add_feature(f, fe_noop_rep);
73 am_add_feature(f, fe_program_dump);
74 am_add_feature(f, fe_program_gnutar);
75 am_add_feature(f, fe_program_application_api);
77 am_add_feature(f, fe_options_compress_fast);
78 am_add_feature(f, fe_options_compress_best);
79 am_add_feature(f, fe_options_srvcomp_fast);
80 am_add_feature(f, fe_options_srvcomp_best);
81 am_add_feature(f, fe_options_no_record);
82 am_add_feature(f, fe_options_bsd_auth);
83 am_add_feature(f, fe_options_index);
84 am_add_feature(f, fe_options_exclude_file);
85 am_add_feature(f, fe_options_exclude_list);
86 am_add_feature(f, fe_options_multiple_exclude);
87 am_add_feature(f, fe_options_optional_exclude);
88 am_add_feature(f, fe_options_include_file);
89 am_add_feature(f, fe_options_include_list);
90 am_add_feature(f, fe_options_multiple_include);
91 am_add_feature(f, fe_options_optional_include);
92 am_add_feature(f, fe_options_kencrypt);
94 am_add_feature(f, fe_req_options_maxdumps);
95 am_add_feature(f, fe_req_options_hostname);
96 am_add_feature(f, fe_req_options_features);
98 am_add_feature(f, fe_rep_options_features);
100 am_add_feature(f, fe_amindexd_fileno_in_OLSD);
101 am_add_feature(f, fe_amindexd_fileno_in_ORLD);
102 am_add_feature(f, fe_amidxtaped_fsf);
103 am_add_feature(f, fe_amidxtaped_label);
104 am_add_feature(f, fe_amidxtaped_device);
105 am_add_feature(f, fe_amidxtaped_host);
106 am_add_feature(f, fe_amidxtaped_disk);
107 am_add_feature(f, fe_amidxtaped_datestamp);
108 am_add_feature(f, fe_amidxtaped_header);
109 am_add_feature(f, fe_amidxtaped_config);
111 am_add_feature(f, fe_recover_splits);
112 am_add_feature(f, fe_amidxtaped_exchange_features);
113 am_add_feature(f, fe_partial_estimate);
114 am_add_feature(f, fe_calcsize_estimate);
115 am_add_feature(f, fe_selfcheck_calcsize);
116 am_add_feature(f, fe_options_compress_cust);
117 am_add_feature(f, fe_options_srvcomp_cust);
118 am_add_feature(f, fe_options_encrypt_cust);
119 am_add_feature(f, fe_options_encrypt_serv_cust);
120 am_add_feature(f, fe_options_client_decrypt_option);
121 am_add_feature(f, fe_options_server_decrypt_option);
123 am_add_feature(f, fe_amindexd_marshall_in_OLSD);
124 am_add_feature(f, fe_amindexd_marshall_in_ORLD);
125 am_add_feature(f, fe_amindexd_marshall_in_DHST);
127 am_add_feature(f, fe_amrecover_FEEDME);
128 am_add_feature(f, fe_amrecover_timestamp);
130 am_add_feature(f, fe_interface_quoted_text);
132 am_add_feature(f, fe_program_star);
134 am_add_feature(f, fe_amindexd_options_hostname);
135 am_add_feature(f, fe_amindexd_options_features);
136 am_add_feature(f, fe_amindexd_options_auth);
138 am_add_feature(f, fe_amidxtaped_options_hostname);
139 am_add_feature(f, fe_amidxtaped_options_features);
140 am_add_feature(f, fe_amidxtaped_options_auth);
142 am_add_feature(f, fe_amrecover_message);
143 am_add_feature(f, fe_amrecover_feedme_tape);
145 am_add_feature(f, fe_req_options_config);
147 am_add_feature(f, fe_rep_sendsize_quoted_error);
148 am_add_feature(f, fe_req_xml);
149 am_add_feature(f, fe_pp_script);
150 am_add_feature(f, fe_amindexd_DLE);
151 am_add_feature(f, fe_amrecover_dle_in_header);
152 am_add_feature(f, fe_xml_estimate);
153 am_add_feature(f, fe_xml_property_priority);
154 am_add_feature(f, fe_sendsize_rep_warning);
155 am_add_feature(f, fe_xml_estimatelist);
156 am_add_feature(f, fe_xml_level_server);
157 am_add_feature(f, fe_xml_data_path);
158 am_add_feature(f, fe_xml_directtcp_list);
159 am_add_feature(f, fe_amidxtaped_datapath);
160 am_add_feature(f, fe_sendbackup_noop);
161 am_add_feature(f, fe_amrecover_origsize_in_header);
162 am_add_feature(f, fe_amidxtaped_abort);
163 am_add_feature(f, fe_amrecover_correct_disk_quoting);
164 am_add_feature(f, fe_amindexd_quote_label);
170 *=====================================================================
171 * Set a default feature set for client that doesn't have noop service.
172 * This is all the features available in 2.4.2p2.
175 * exit: dynamically allocated feature set
176 *=====================================================================
180 am_set_default_feature_set(void)
184 if ((f = am_allocate_feature_set()) != NULL) {
186 am_add_feature(f, fe_selfcheck_req);
187 am_add_feature(f, fe_selfcheck_rep);
188 am_add_feature(f, fe_sendsize_req_no_options);
189 am_add_feature(f, fe_sendsize_rep);
190 am_add_feature(f, fe_sendbackup_req);
191 am_add_feature(f, fe_sendbackup_rep);
193 am_add_feature(f, fe_program_dump);
194 am_add_feature(f, fe_program_gnutar);
196 am_add_feature(f, fe_options_compress_fast);
197 am_add_feature(f, fe_options_compress_best);
198 am_add_feature(f, fe_options_srvcomp_fast);
199 am_add_feature(f, fe_options_srvcomp_best);
200 am_add_feature(f, fe_options_no_record);
201 am_add_feature(f, fe_options_bsd_auth);
202 am_add_feature(f, fe_options_index);
203 am_add_feature(f, fe_options_exclude_file);
204 am_add_feature(f, fe_options_exclude_list);
205 am_add_feature(f, fe_options_kencrypt);
207 am_add_feature(f, fe_req_options_maxdumps);
208 am_add_feature(f, fe_req_options_hostname);
209 am_add_feature(f, fe_req_options_features);
211 am_add_feature(f, fe_rep_options_sendbackup_options);
217 *=====================================================================
218 * Allocate space for a feature set.
220 * am_feature_t *am_allocate_feature_set()
223 * exit: dynamically allocated feature set structure
224 *=====================================================================
228 am_allocate_feature_set(void)
231 am_feature_t *result;
233 result = (am_feature_t *)alloc(SIZEOF(*result));
234 memset(result, 0, SIZEOF(*result));
235 nbytes = (((size_t)last_feature) + 8) >> 3;
236 result->size = nbytes;
237 result->bytes = (unsigned char *)alloc(nbytes);
238 memset(result->bytes, 0, nbytes);
243 *=====================================================================
244 * Release space allocated to a feature set.
246 * void am_release_feature_set(am_feature_t *f)
248 * entry: f = feature set to release
250 *=====================================================================
254 am_release_feature_set(
265 *=====================================================================
266 * Add a feature to a feature set.
268 * int am_add_feature(am_feature_t *f, am_feature_e n)
270 * entry: f = feature set to add to
272 * exit: non-zero if feature added, else zero (e.g. if the feature
273 * is beyond what is currently supported)
274 *=====================================================================
286 if (f != NULL && (int)n >= 0) {
287 byte = ((size_t)n) >> 3;
288 if (byte < f->size) {
289 bit = ((int)n) & 0x7;
290 f->bytes[byte] = (unsigned char)((int)f->bytes[byte] | (unsigned char)(1 << bit));
298 *=====================================================================
299 * Remove a feature from a feature set.
301 * int am_remove_feature(am_feature_t *f, am_feature_e n)
303 * entry: f = feature set to remove from
304 * n = feature to remove
305 * exit: non-zero if feature removed, else zero (e.g. if the feature
306 * is beyond what is currently supported)
307 *=====================================================================
319 if (f != NULL && (int)n >= 0) {
320 byte = ((size_t)n) >> 3;
321 if (byte < f->size) {
322 bit = ((int)n) & 0x7;
323 f->bytes[byte] = (unsigned char)((int)f->bytes[byte] & (unsigned char)~(1 << bit));
331 *=====================================================================
332 * Return true if a given feature is available.
334 * int am_has_feature(am_feature_t *f, am_feature_e n)
336 * entry: f = feature set to test
337 * n = feature to test
338 * exit: non-zero if feature is enabled
339 *=====================================================================
351 if (f != NULL && (int)n >= 0) {
352 byte = ((size_t)n) >> 3;
353 if (byte < f->size) {
354 bit = ((int)n) & 0x7;
355 result = ((f->bytes[byte] & (1 << bit)) != 0);
362 *=====================================================================
363 * Convert a feature set to string.
365 * char *am_feature_to_string(am_feature_t *f)
367 * entry: f = feature set to convet
368 * exit: dynamically allocated string
369 *=====================================================================
373 am_feature_to_string(
380 result = stralloc(_("UNKNOWNFEATURE"));
382 result = alloc((f->size * 2) + 1);
383 for (i = 0; i < f->size; i++) {
384 g_snprintf(result + (i * 2), 2 + 1, "%02x", f->bytes[i]);
386 result[i * 2] = '\0';
392 *=====================================================================
393 * Convert a sting back to a feature set.
395 * am_feature_t *am_string_to_feature(char *s)
397 * entry: s = string to convert
398 * exit: dynamically allocated feature set
400 * Note: if the string is longer than the list of features we support,
401 * the remaining input features are ignored. If it is shorter, the
402 * missing features are disabled.
404 * If the string is not formatted properly (not a multiple of two bytes),
407 * Conversion stops at the first non-hex character.
408 *=====================================================================
412 am_string_to_feature(
415 am_feature_t *f = NULL;
420 if (s != NULL && strcmp(s,"UNKNOWNFEATURE") != 0) {
421 f = am_allocate_feature_set();
422 for (i = 0; i < f->size && (ch1 = *s++) != '\0'; i++) {
425 } else if (ch1 >= 'a' && ch1 <= 'f') {
428 } else if (ch1 >= 'A' && ch1 <= 'F') {
437 } else if (ch2 >= 'a' && ch2 <= 'f') {
440 } else if (ch2 >= 'A' && ch2 <= 'F') {
443 } else if (ch2 == '\0') {
444 g_warning("odd number of digits in amfeature string; truncating");
449 f->bytes[i] = (unsigned char)((ch1 << 4) | ch2);
455 g_warning("Bad feature string '%s'", orig);
456 am_release_feature_set(f);