Imported Upstream version 3.2.0
[debian/amanda] / device-src / s3-device.c
index 53692aa3d54e779f00647d10d11e3329aa329200..d060974fff944a9d2153f69605bd34e77bc12780 100644 (file)
@@ -83,6 +83,7 @@ struct _S3Device {
     char *user_token;
 
     char *bucket_location;
+    char *storage_class;
 
     char *ca_info;
 
@@ -153,6 +154,10 @@ static DevicePropertyBase device_property_s3_user_token;
 static DevicePropertyBase device_property_s3_bucket_location;
 #define PROPERTY_S3_BUCKET_LOCATION (device_property_s3_bucket_location.ID)
 
+/* Storage class */
+static DevicePropertyBase device_property_s3_storage_class;
+#define PROPERTY_S3_STORAGE_CLASS (device_property_s3_storage_class.ID)
+
 /* Path to certificate authority certificate */
 static DevicePropertyBase device_property_ssl_ca_info;
 #define PROPERTY_SSL_CA_INFO (device_property_ssl_ca_info.ID)
@@ -289,6 +294,10 @@ static gboolean s3_device_set_bucket_location_fn(Device *self,
     DevicePropertyBase *base, GValue *val,
     PropertySurety surety, PropertySource source);
 
+static gboolean s3_device_set_storage_class_fn(Device *self,
+    DevicePropertyBase *base, GValue *val,
+    PropertySurety surety, PropertySource source);
+
 static gboolean s3_device_set_ca_info_fn(Device *self,
     DevicePropertyBase *base, GValue *val,
     PropertySurety surety, PropertySource source);
@@ -655,6 +664,9 @@ s3_device_register(void)
     device_property_fill_and_register(&device_property_s3_bucket_location,
                                       G_TYPE_STRING, "s3_bucket_location",
        "Location constraint for buckets on Amazon S3");
+    device_property_fill_and_register(&device_property_s3_storage_class,
+                                      G_TYPE_STRING, "s3_storage_class",
+       "Storage class as specified by Amazon (STANDARD or REDUCED_REDUNDANCY)");
     device_property_fill_and_register(&device_property_ssl_ca_info,
                                       G_TYPE_STRING, "ssl_ca_info",
        "Path to certificate authority certificate");
@@ -739,6 +751,12 @@ s3_device_init(S3Device * self)
            &response, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DETECTED);
     g_value_unset(&response);
 
+    g_value_init(&response, G_TYPE_BOOLEAN);
+    g_value_set_boolean(&response, TRUE); /* well, there *is* no EOM on S3 .. */
+    device_set_simple_property(dself, PROPERTY_LEOM,
+           &response, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DETECTED);
+    g_value_unset(&response);
+
     g_value_init(&response, G_TYPE_BOOLEAN);
     g_value_set_boolean(&response, FALSE);
     device_set_simple_property(dself, PROPERTY_COMPRESSION,
@@ -799,6 +817,11 @@ s3_device_class_init(S3DeviceClass * c G_GNUC_UNUSED)
            device_simple_property_get_fn,
            s3_device_set_bucket_location_fn);
 
+    device_class_register_property(device_class, PROPERTY_S3_STORAGE_CLASS,
+           PROPERTY_ACCESS_GET_MASK | PROPERTY_ACCESS_SET_BEFORE_START,
+           device_simple_property_get_fn,
+           s3_device_set_storage_class_fn);
+
     device_class_register_property(device_class, PROPERTY_SSL_CA_INFO,
            PROPERTY_ACCESS_GET_MASK | PROPERTY_ACCESS_SET_BEFORE_START,
            device_simple_property_get_fn,
@@ -894,7 +917,7 @@ s3_device_set_bucket_location_fn(Device *p_self, DevicePropertyBase *base,
     }
 
     amfree(self->bucket_location);
-    self->bucket_location = g_value_dup_string(val);
+    self->bucket_location = str_val;
     device_clear_volume_details(p_self);
 
     return device_simple_property_set_fn(p_self, base, val, surety, source);
@@ -904,18 +927,24 @@ fail:
 }
 
 static gboolean
-s3_device_set_ca_info_fn(Device *p_self, DevicePropertyBase *base,
+s3_device_set_storage_class_fn(Device *p_self, DevicePropertyBase *base,
     GValue *val, PropertySurety surety, PropertySource source)
 {
     S3Device *self = S3_DEVICE(p_self);
+    char *str_val = g_value_dup_string(val);
 
-    if (!self->use_ssl) {
-       device_set_error(p_self, stralloc(_(
-               "Path to certificate authority certificate can not be "
-               "set if SSL/TLS is not being used.")),
-           DEVICE_STATUS_DEVICE_ERROR);
-       return FALSE;
-    }
+    amfree(self->storage_class);
+    self->storage_class = str_val;
+    device_clear_volume_details(p_self);
+
+    return device_simple_property_set_fn(p_self, base, val, surety, source);
+}
+
+static gboolean
+s3_device_set_ca_info_fn(Device *p_self, DevicePropertyBase *base,
+    GValue *val, PropertySurety surety, PropertySource source)
+{
+    S3Device *self = S3_DEVICE(p_self);
 
     amfree(self->ca_info);
     self->ca_info = g_value_dup_string(val);
@@ -1081,6 +1110,7 @@ static void s3_device_finalize(GObject * obj_self) {
     if(self->secret_key) g_free(self->secret_key);
     if(self->user_token) g_free(self->user_token);
     if(self->bucket_location) g_free(self->bucket_location);
+    if(self->storage_class) g_free(self->storage_class);
     if(self->ca_info) g_free(self->ca_info);
 }
 
@@ -1102,8 +1132,12 @@ static gboolean setup_handle(S3Device * self) {
             return FALSE;
        }
 
+       if (!self->use_ssl && self->ca_info) {
+           amfree(self->ca_info);
+       }
+
         self->s3 = s3_open(self->access_key, self->secret_key, self->user_token,
-            self->bucket_location, self->ca_info);
+            self->bucket_location, self->storage_class, self->ca_info);
         if (self->s3 == NULL) {
            device_set_error(d_self,
                stralloc(_("Internal error creating S3 handle")),
@@ -1289,11 +1323,11 @@ s3_device_start (Device * pself, DeviceAccessMode mode,
 
 static gboolean
 s3_device_finish (Device * pself) {
-    if (device_in_error(pself)) return FALSE;
-
     /* we're not in a file anymore */
     pself->access_mode = ACCESS_NULL;
 
+    if (device_in_error(pself)) return FALSE;
+
     return TRUE;
 }