Imported Upstream version 3.2.0
[debian/amanda] / common-src / amfeatures.c
index 7305793e660ca1a2aa988eb3a6d948eaa7da3b07..c7b80503e7ba4a89406e64bc39c4217dd78a5e92 100644 (file)
  */
 
 /*
- * $Id: amfeatures.c,v 1.1.2.9 2003/01/01 23:28:52 martinea Exp $
+ * $Id: amfeatures.c,v 1.24 2006/07/19 17:46:07 martinea Exp $
  *
  * Feature test related code.
  */
 
-#include <amanda.h>
-#include <amfeatures.h>
+#include "amanda.h"
+#include "amfeatures.h"
 
 /*
  *=====================================================================
@@ -45,9 +45,9 @@
  */
 
 am_feature_t *
-am_init_feature_set()
+am_init_feature_set(void)
 {
-    am_feature_t               *f = NULL;
+    am_feature_t               *f;
 
     if ((f = am_allocate_feature_set()) != NULL) {
        /*
@@ -72,6 +72,7 @@ am_init_feature_set()
 
        am_add_feature(f, fe_program_dump);
        am_add_feature(f, fe_program_gnutar);
+       am_add_feature(f, fe_program_application_api);
 
        am_add_feature(f, fe_options_compress_fast);
        am_add_feature(f, fe_options_compress_best);
@@ -88,7 +89,6 @@ am_init_feature_set()
        am_add_feature(f, fe_options_include_list);
        am_add_feature(f, fe_options_multiple_include);
        am_add_feature(f, fe_options_optional_include);
-       am_add_feature(f, fe_options_krb4_auth);
        am_add_feature(f, fe_options_kencrypt);
 
        am_add_feature(f, fe_req_options_maxdumps);
@@ -106,8 +106,62 @@ am_init_feature_set()
        am_add_feature(f, fe_amidxtaped_disk);
        am_add_feature(f, fe_amidxtaped_datestamp);
        am_add_feature(f, fe_amidxtaped_header);
-       am_add_feature(f, fe_amidxtaped_nargs);
        am_add_feature(f, fe_amidxtaped_config);
+
+       am_add_feature(f, fe_recover_splits);
+       am_add_feature(f, fe_amidxtaped_exchange_features);
+       am_add_feature(f, fe_partial_estimate);
+       am_add_feature(f, fe_calcsize_estimate);
+       am_add_feature(f, fe_selfcheck_calcsize);
+       am_add_feature(f, fe_options_compress_cust);
+       am_add_feature(f, fe_options_srvcomp_cust);
+       am_add_feature(f, fe_options_encrypt_cust);
+       am_add_feature(f, fe_options_encrypt_serv_cust);
+       am_add_feature(f, fe_options_client_decrypt_option);
+       am_add_feature(f, fe_options_server_decrypt_option);
+
+       am_add_feature(f, fe_amindexd_marshall_in_OLSD);
+       am_add_feature(f, fe_amindexd_marshall_in_ORLD);
+       am_add_feature(f, fe_amindexd_marshall_in_DHST);
+
+        am_add_feature(f, fe_amrecover_FEEDME);
+        am_add_feature(f, fe_amrecover_timestamp);
+
+        am_add_feature(f, fe_interface_quoted_text);
+
+       am_add_feature(f, fe_program_star);
+
+       am_add_feature(f, fe_amindexd_options_hostname);
+       am_add_feature(f, fe_amindexd_options_features);
+       am_add_feature(f, fe_amindexd_options_auth);
+
+       am_add_feature(f, fe_amidxtaped_options_hostname);
+       am_add_feature(f, fe_amidxtaped_options_features);
+       am_add_feature(f, fe_amidxtaped_options_auth);
+
+       am_add_feature(f, fe_amrecover_message);
+       am_add_feature(f, fe_amrecover_feedme_tape);
+
+       am_add_feature(f, fe_req_options_config);
+
+       am_add_feature(f, fe_rep_sendsize_quoted_error);
+       am_add_feature(f, fe_req_xml);
+       am_add_feature(f, fe_pp_script);
+       am_add_feature(f, fe_amindexd_DLE);
+       am_add_feature(f, fe_amrecover_dle_in_header);
+       am_add_feature(f, fe_xml_estimate);
+       am_add_feature(f, fe_xml_property_priority);
+       am_add_feature(f, fe_sendsize_rep_warning);
+       am_add_feature(f, fe_xml_estimatelist);
+       am_add_feature(f, fe_xml_level_server);
+       am_add_feature(f, fe_xml_data_path);
+       am_add_feature(f, fe_xml_directtcp_list);
+       am_add_feature(f, fe_amidxtaped_datapath);
+       am_add_feature(f, fe_sendbackup_noop);
+       am_add_feature(f, fe_amrecover_origsize_in_header);
+       am_add_feature(f, fe_amidxtaped_abort);
+       am_add_feature(f, fe_amrecover_correct_disk_quoting);
+       am_add_feature(f, fe_amindexd_quote_label);
     }
     return f;
 }
@@ -148,7 +202,6 @@ am_set_default_feature_set(void)
        am_add_feature(f, fe_options_index);
        am_add_feature(f, fe_options_exclude_file);
        am_add_feature(f, fe_options_exclude_list);
-       am_add_feature(f, fe_options_krb4_auth);
        am_add_feature(f, fe_options_kencrypt);
 
        am_add_feature(f, fe_req_options_maxdumps);
@@ -172,13 +225,13 @@ am_set_default_feature_set(void)
  */
 
 am_feature_t *
-am_allocate_feature_set()
+am_allocate_feature_set(void)
 {
     size_t                     nbytes;
     am_feature_t               *result;
 
-    result = (am_feature_t *)alloc(sizeof(*result));
-    memset(result, 0, sizeof(*result));
+    result = (am_feature_t *)alloc(SIZEOF(*result));
+    memset(result, 0, SIZEOF(*result));
     nbytes = (((size_t)last_feature) + 8) >> 3;
     result->size = nbytes;
     result->bytes = (unsigned char *)alloc(nbytes);
@@ -198,8 +251,8 @@ am_allocate_feature_set()
  */
 
 void
-am_release_feature_set(f)
-    am_feature_t               *f;
+am_release_feature_set(
+    am_feature_t       *f)
 {
     if (f != NULL) {
        amfree(f->bytes);
@@ -222,9 +275,9 @@ am_release_feature_set(f)
  */
 
 int
-am_add_feature(f, n)
-    am_feature_t               *f;
-    am_feature_e               n;
+am_add_feature(
+    am_feature_t       *f,
+    am_feature_e       n)
 {
     size_t                     byte;
     int                                bit;
@@ -234,7 +287,7 @@ am_add_feature(f, n)
        byte = ((size_t)n) >> 3;
        if (byte < f->size) {
            bit = ((int)n) & 0x7;
-           f->bytes[byte] |= (1 << bit);
+           f->bytes[byte] = (unsigned char)((int)f->bytes[byte] | (unsigned char)(1 << bit));
            result = 1;
        }
     }
@@ -255,9 +308,9 @@ am_add_feature(f, n)
  */
 
 int
-am_remove_feature(f, n)
-    am_feature_t               *f;
-    am_feature_e               n;
+am_remove_feature(
+    am_feature_t       *f,
+    am_feature_e       n)
 {
     size_t                     byte;
     int                                bit;
@@ -267,7 +320,7 @@ am_remove_feature(f, n)
        byte = ((size_t)n) >> 3;
        if (byte < f->size) {
            bit = ((int)n) & 0x7;
-           f->bytes[byte] &= ~(1 << bit);
+           f->bytes[byte] = (unsigned char)((int)f->bytes[byte] & (unsigned char)~(1 << bit));
            result = 1;
        }
     }
@@ -287,9 +340,9 @@ am_remove_feature(f, n)
  */
 
 int
-am_has_feature(f, n)
-    am_feature_t               *f;
-    am_feature_e               n;
+am_has_feature(
+    am_feature_t       *f,
+    am_feature_e       n)
 {
     size_t                     byte;
     int                                bit;
@@ -317,18 +370,18 @@ am_has_feature(f, n)
  */
 
 char *
-am_feature_to_string(f)
-    am_feature_t               *f;
+am_feature_to_string(
+    am_feature_t       *f)
 {
     char                       *result;
     size_t                     i;
 
     if (f == NULL) {
-       result = stralloc("UNKNOWNFEATURE");
+       result = stralloc(_("UNKNOWNFEATURE"));
     } else {
        result = alloc((f->size * 2) + 1);
        for (i = 0; i < f->size; i++) {
-           ap_snprintf(result + (i * 2), 2 + 1, "%02x", f->bytes[i]);
+           g_snprintf(result + (i * 2), 2 + 1, "%02x", f->bytes[i]);
        }
        result[i * 2] = '\0';
     }
@@ -356,12 +409,13 @@ am_feature_to_string(f)
  */
 
 am_feature_t *
-am_string_to_feature(s)
-    char                       *s;
+am_string_to_feature(
+    char               *s)
 {
     am_feature_t               *f = NULL;
     size_t                     i;
     int                                ch1, ch2;
+    char *                     orig = s;
 
     if (s != NULL && strcmp(s,"UNKNOWNFEATURE") != 0) {
        f = am_allocate_feature_set();
@@ -372,10 +426,10 @@ am_string_to_feature(s)
                ch1 -= 'a';
                ch1 += 10;
            } else if (ch1 >= 'A' && ch1 <= 'F') {
-               ch1 -= 'a';
+               ch1 -= 'A';
                ch1 += 10;
            } else {
-               break;
+               goto bad;
            }
            ch2 = *s++;
            if (isdigit(ch2)) {
@@ -384,79 +438,21 @@ am_string_to_feature(s)
                ch2 -= 'a';
                ch2 += 10;
            } else if (ch2 >= 'A' && ch2 <= 'F') {
-               ch2 -= 'a';
+               ch2 -= 'A';
                ch2 += 10;
-           } else {
-               amfree(f);                              /* bad conversion */
+           } else if (ch2 == '\0') {
+               g_warning("odd number of digits in amfeature string; truncating");
                break;
-           }
-           f->bytes[i] = (ch1 << 4) | ch2;
-       }
-    }
-    return f;
-}
-
-#if defined(TEST)
-int
-main(argc, argv)
-    int                                argc;
-    char                       **argv;
-{
-    am_feature_t               *f;
-    am_feature_t               *f1;
-    char                       *s;
-    char                       *s1;
-    int                                i;
-    int                                n;
-
-    f = am_init_feature_set();
-    if (f == NULL) {
-       fprintf(stderr, "cannot initialize feature set\n");
-       return 1;
-    }
-
-    s = am_feature_to_string(f);
-    printf("base features=%s\n", s);
-
-    f1 = am_string_to_feature(s);
-    s1 = am_feature_to_string(f1);
-    if (strcmp(s, s1) != 0) {
-       fprintf(stderr, "base feature -> string -> feature set mismatch\n");
-       fprintf(stderr, "conv features=%s\n", s);
-    }
-
-    amfree(s1);
-    amfree(s);
-
-    for (i = 1; i < argc; i++) {
-       if (argv[i][0] == '+') {
-           n = atoi(&argv[i][1]);
-           if (am_add_feature(f, (am_feature_e)n)) {
-               printf("added feature number %d\n", n);
-           } else {
-               printf("could not add feature number %d\n", n);
-           }
-       } else if (argv[i][0] == '-') {
-           n = atoi(&argv[i][1]);
-           if (am_remove_feature(f, (am_feature_e)n)) {
-               printf("removed feature number %d\n", n);
            } else {
-               printf("could not remove feature number %d\n", n);
-           }
-       } else {
-           n = atoi(argv[i]);
-           if (am_has_feature(f, (am_feature_e)n)) {
-               printf("feature %d is set\n", n);
-           } else {
-               printf("feature %d is not set\n", n);
+               goto bad;
            }
+           f->bytes[i] = (unsigned char)((ch1 << 4) | ch2);
        }
     }
+    return f;
 
-    s = am_feature_to_string(f);
-    printf(" new features=%s\n", s);
-    amfree(s);
-
-    return 0;
+bad:
+    g_warning("Bad feature string '%s'", orig);
+    am_release_feature_set(f);
+    return NULL;
 }
-#endif