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.1.2.9 2003/01/01 23:28:52 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 *=====================================================================
50 am_feature_t *f = NULL;
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);
76 am_add_feature(f, fe_options_compress_fast);
77 am_add_feature(f, fe_options_compress_best);
78 am_add_feature(f, fe_options_srvcomp_fast);
79 am_add_feature(f, fe_options_srvcomp_best);
80 am_add_feature(f, fe_options_no_record);
81 am_add_feature(f, fe_options_bsd_auth);
82 am_add_feature(f, fe_options_index);
83 am_add_feature(f, fe_options_exclude_file);
84 am_add_feature(f, fe_options_exclude_list);
85 am_add_feature(f, fe_options_multiple_exclude);
86 am_add_feature(f, fe_options_optional_exclude);
87 am_add_feature(f, fe_options_include_file);
88 am_add_feature(f, fe_options_include_list);
89 am_add_feature(f, fe_options_multiple_include);
90 am_add_feature(f, fe_options_optional_include);
91 am_add_feature(f, fe_options_krb4_auth);
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_nargs);
110 am_add_feature(f, fe_amidxtaped_config);
116 *=====================================================================
117 * Set a default feature set for client that doesn't have noop service.
118 * This is all the features available in 2.4.2p2.
121 * exit: dynamically allocated feature set
122 *=====================================================================
126 am_set_default_feature_set(void)
130 if ((f = am_allocate_feature_set()) != NULL) {
132 am_add_feature(f, fe_selfcheck_req);
133 am_add_feature(f, fe_selfcheck_rep);
134 am_add_feature(f, fe_sendsize_req_no_options);
135 am_add_feature(f, fe_sendsize_rep);
136 am_add_feature(f, fe_sendbackup_req);
137 am_add_feature(f, fe_sendbackup_rep);
139 am_add_feature(f, fe_program_dump);
140 am_add_feature(f, fe_program_gnutar);
142 am_add_feature(f, fe_options_compress_fast);
143 am_add_feature(f, fe_options_compress_best);
144 am_add_feature(f, fe_options_srvcomp_fast);
145 am_add_feature(f, fe_options_srvcomp_best);
146 am_add_feature(f, fe_options_no_record);
147 am_add_feature(f, fe_options_bsd_auth);
148 am_add_feature(f, fe_options_index);
149 am_add_feature(f, fe_options_exclude_file);
150 am_add_feature(f, fe_options_exclude_list);
151 am_add_feature(f, fe_options_krb4_auth);
152 am_add_feature(f, fe_options_kencrypt);
154 am_add_feature(f, fe_req_options_maxdumps);
155 am_add_feature(f, fe_req_options_hostname);
156 am_add_feature(f, fe_req_options_features);
158 am_add_feature(f, fe_rep_options_sendbackup_options);
164 *=====================================================================
165 * Allocate space for a feature set.
167 * am_feature_t *am_allocate_feature_set()
170 * exit: dynamically allocated feature set structure
171 *=====================================================================
175 am_allocate_feature_set()
178 am_feature_t *result;
180 result = (am_feature_t *)alloc(sizeof(*result));
181 memset(result, 0, sizeof(*result));
182 nbytes = (((size_t)last_feature) + 8) >> 3;
183 result->size = nbytes;
184 result->bytes = (unsigned char *)alloc(nbytes);
185 memset(result->bytes, 0, nbytes);
190 *=====================================================================
191 * Release space allocated to a feature set.
193 * void am_release_feature_set(am_feature_t *f)
195 * entry: f = feature set to release
197 *=====================================================================
201 am_release_feature_set(f)
212 *=====================================================================
213 * Add a feature to a feature set.
215 * int am_add_feature(am_feature_t *f, am_feature_e n)
217 * entry: f = feature set to add to
219 * exit: non-zero if feature added, else zero (e.g. if the feature
220 * is beyond what is currently supported)
221 *=====================================================================
233 if (f != NULL && (int)n >= 0) {
234 byte = ((size_t)n) >> 3;
235 if (byte < f->size) {
236 bit = ((int)n) & 0x7;
237 f->bytes[byte] |= (1 << bit);
245 *=====================================================================
246 * Remove a feature from a feature set.
248 * int am_remove_feature(am_feature_t *f, am_feature_e n)
250 * entry: f = feature set to remove from
251 * n = feature to remove
252 * exit: non-zero if feature removed, else zero (e.g. if the feature
253 * is beyond what is currently supported)
254 *=====================================================================
258 am_remove_feature(f, n)
266 if (f != NULL && (int)n >= 0) {
267 byte = ((size_t)n) >> 3;
268 if (byte < f->size) {
269 bit = ((int)n) & 0x7;
270 f->bytes[byte] &= ~(1 << bit);
278 *=====================================================================
279 * Return true if a given feature is available.
281 * int am_has_feature(am_feature_t *f, am_feature_e n)
283 * entry: f = feature set to test
284 * n = feature to test
285 * exit: non-zero if feature is enabled
286 *=====================================================================
298 if (f != NULL && (int)n >= 0) {
299 byte = ((size_t)n) >> 3;
300 if (byte < f->size) {
301 bit = ((int)n) & 0x7;
302 result = ((f->bytes[byte] & (1 << bit)) != 0);
309 *=====================================================================
310 * Convert a feature set to string.
312 * char *am_feature_to_string(am_feature_t *f)
314 * entry: f = feature set to convet
315 * exit: dynamically allocated string
316 *=====================================================================
320 am_feature_to_string(f)
327 result = stralloc("UNKNOWNFEATURE");
329 result = alloc((f->size * 2) + 1);
330 for (i = 0; i < f->size; i++) {
331 ap_snprintf(result + (i * 2), 2 + 1, "%02x", f->bytes[i]);
333 result[i * 2] = '\0';
339 *=====================================================================
340 * Convert a sting back to a feature set.
342 * am_feature_t *am_string_to_feature(char *s)
344 * entry: s = string to convert
345 * exit: dynamically allocated feature set
347 * Note: if the string is longer than the list of features we support,
348 * the remaining input features are ignored. If it is shorter, the
349 * missing features are disabled.
351 * If the string is not formatted properly (not a multiple of two bytes),
354 * Conversion stops at the first non-hex character.
355 *=====================================================================
359 am_string_to_feature(s)
362 am_feature_t *f = NULL;
366 if (s != NULL && strcmp(s,"UNKNOWNFEATURE") != 0) {
367 f = am_allocate_feature_set();
368 for (i = 0; i < f->size && (ch1 = *s++) != '\0'; i++) {
371 } else if (ch1 >= 'a' && ch1 <= 'f') {
374 } else if (ch1 >= 'A' && ch1 <= 'F') {
383 } else if (ch2 >= 'a' && ch2 <= 'f') {
386 } else if (ch2 >= 'A' && ch2 <= 'F') {
390 amfree(f); /* bad conversion */
393 f->bytes[i] = (ch1 << 4) | ch2;
412 f = am_init_feature_set();
414 fprintf(stderr, "cannot initialize feature set\n");
418 s = am_feature_to_string(f);
419 printf("base features=%s\n", s);
421 f1 = am_string_to_feature(s);
422 s1 = am_feature_to_string(f1);
423 if (strcmp(s, s1) != 0) {
424 fprintf(stderr, "base feature -> string -> feature set mismatch\n");
425 fprintf(stderr, "conv features=%s\n", s);
431 for (i = 1; i < argc; i++) {
432 if (argv[i][0] == '+') {
433 n = atoi(&argv[i][1]);
434 if (am_add_feature(f, (am_feature_e)n)) {
435 printf("added feature number %d\n", n);
437 printf("could not add feature number %d\n", n);
439 } else if (argv[i][0] == '-') {
440 n = atoi(&argv[i][1]);
441 if (am_remove_feature(f, (am_feature_e)n)) {
442 printf("removed feature number %d\n", n);
444 printf("could not remove feature number %d\n", n);
448 if (am_has_feature(f, (am_feature_e)n)) {
449 printf("feature %d is set\n", n);
451 printf("feature %d is not set\n", n);
456 s = am_feature_to_string(f);
457 printf(" new features=%s\n", s);