Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions device-src/s3-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,14 @@ static DevicePropertyBase device_property_refresh_token;
static DevicePropertyBase device_property_project_id;
#define PROPERTY_PROJECT_ID (device_property_project_id.ID)

/* The PROJECT ID */
/* Create Bucket */
static DevicePropertyBase device_property_create_bucket;
#define PROPERTY_CREATE_BUCKET (device_property_create_bucket.ID)

/* Set HTTP version for CURL requests */
static DevicePropertyBase device_property_http_version;
#define PROPERTY_HTTP_V1_1_VERSION (device_property_http_v1_1_version.ID)

/* glacier */
static DevicePropertyBase device_property_read_from_glacier;
#define PROPERTY_READ_FROM_GLACIER (device_property_read_from_glacier.ID)
Expand Down Expand Up @@ -520,6 +524,10 @@ static gboolean s3_device_set_reps_bucket_fn(Device *self,
DevicePropertyBase *base, GValue *val,
PropertySurety surety, PropertySource source);

static gboolean s3_device_set_http_v1_1_version(Device *self,
DevicePropertyBase *base, GValue *val,
PropertySurety surety, PropertySource source);

static void s3_thread_read_block(gpointer thread_data,
gpointer data);
static void s3_thread_write_block(gpointer thread_data,
Expand Down Expand Up @@ -1186,6 +1194,10 @@ s3_device_register(void)
G_TYPE_UINT64, "timeout",
"The timeout for one tranfer");

device_property_fill_and_register(&device_property_http_version,
G_TYPE_BOOLEAN, "http_v1_1",
"Use HTTP version 1.1");

/* register the device itself */
register_device(s3_device_factory, device_prefix_list);
}
Expand Down Expand Up @@ -1242,6 +1254,7 @@ s3_device_init(S3Device * self)
self->reps = NULL;
self->reps_bucket = NULL;
self->transition_to_glacier = -1;
self->http_version_v1_1 = FALSE;

/* Register property values
* Note: Some aren't added until s3_device_open_device()
Expand Down Expand Up @@ -1580,6 +1593,11 @@ s3_device_base_init(
PROPERTY_ACCESS_GET_MASK | PROPERTY_ACCESS_SET_BEFORE_START,
device_simple_property_get_fn,
s3_device_set_reps_bucket_fn);

device_class_register_property(device_class, PROPERTY_HTTP_V1_1_VERSION,
PROPERTY_ACCESS_GET_MASK | PROPERTY_ACCESS_SET_BEFORE_START,
device_simple_property_get_fn,
s3_device_set_http_version);
}

static gboolean
Expand Down Expand Up @@ -2315,6 +2333,18 @@ s3_device_set_reps_bucket_fn(Device *p_self, DevicePropertyBase *base,
return device_simple_property_set_fn(p_self, base, val, surety, source);
}

static gboolean
s3_device_set_http_v1_1_version(Device *p_self, DevicePropertyBase *base,
GValue *val, PropertySurety surety, PropertySource source)
{
S3Device *self = S3_DEVICE(p_self);

self->http_v1_1 = g_value_get_boolean(val);

return device_simple_property_set_fn(p_self, base, val, surety, source);
}
/* end of setter functions */

static Device*
s3_device_factory(char * device_name, char * device_type, char * device_node)
{
Expand Down Expand Up @@ -2774,7 +2804,8 @@ setup_handle(S3Device * self) {
self->reuse_connection,
self->read_from_glacier,
self->timeout,
self->reps, self->reps_bucket);
self->reps, self->reps_bucket
self->http_version_v1_1);
if (self->s3t[thread].s3 == NULL) {
device_set_error(d_self,
g_strdup(_("Internal error creating S3 handle")),
Expand Down
2 changes: 2 additions & 0 deletions device-src/s3-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ struct _S3Device {
/* CAStor */
char *reps;
char *reps_bucket;

gboolean http_version_v1_1;
};

/*
Expand Down
19 changes: 14 additions & 5 deletions device-src/s3.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ struct S3Handle {
/* CAStor */
char *reps;
char *reps_bucket;

gboolean http_v1_1;
};

typedef struct {
Expand Down Expand Up @@ -2918,8 +2920,8 @@ compile_regexes(void)
{"^[a-z0-9](-*[a-z0-9]){2,62}$", REG_EXTENDED | REG_NOSUB, &subdomain_regex},
{"(/>)|(>([^<]*)</LocationConstraint>)", REG_EXTENDED | REG_ICASE, &location_con_regex},
{"^Date:(.*)$",REG_EXTENDED | REG_ICASE | REG_NEWLINE, &date_sync_regex},
{"\"access_token\" : \"([^\"]*)\",", REG_EXTENDED | REG_ICASE | REG_NEWLINE, &access_token_regex},
{"\"expires_in\" : (.*)", REG_EXTENDED | REG_ICASE | REG_NEWLINE, &expires_in_regex},
{"\"access_token\"[[:space:]]*:[[:space:]]*\"([^\"]*)\",", REG_EXTENDED | REG_ICASE | REG_NEWLINE, &access_token_regex},
{"\"expires_in\"[[:space:]]*:[[:space:]]*(.*),", REG_EXTENDED | REG_ICASE | REG_NEWLINE, &expires_in_regex},
{"\"details\": \"([^\"]*)\",", REG_EXTENDED | REG_ICASE | REG_NEWLINE, &details_regex},
{"\"code\": (.*),", REG_EXTENDED | REG_ICASE | REG_NEWLINE, &code_regex},
{"\"message\": \"([^\"]*)\",", REG_EXTENDED | REG_ICASE | REG_NEWLINE, &json_message_regex},
Expand Down Expand Up @@ -2978,10 +2980,10 @@ compile_regexes(void)
{"^Date:(.*)$",
G_REGEX_OPTIMIZE | G_REGEX_CASELESS,
&date_sync_regex},
{"\"access_token\" : \"([^\"]*)\"",
{"\"access_token\"\\s*:\\s*\"([^\"]*)\"",
G_REGEX_OPTIMIZE | G_REGEX_CASELESS,
&access_token_regex},
{"\"expires_n\" : (.*)",
{"\"expires_in\"\\s*:\\s*(.*),",
G_REGEX_OPTIMIZE | G_REGEX_CASELESS,
&expires_in_regex},
{"\"details\" : \"([^\"]*)\"",
Expand Down Expand Up @@ -3205,7 +3207,8 @@ s3_open(const char *access_key,
const gboolean read_from_glacier,
const long timeout,
const char *reps,
const char *reps_bucket)
const char *reps_bucket,
const gboolean http_v1_1)
{
S3Handle *hdl;
char *hwp;
Expand Down Expand Up @@ -3330,6 +3333,8 @@ s3_open(const char *access_key,
hdl->service_path = NULL;
}

hdl->http_v1_1 = http_v1_1;

s3_new_curl(hdl);
if (!hdl->curl) goto error;
return hdl;
Expand Down Expand Up @@ -3372,6 +3377,10 @@ s3_new_curl(
}
#endif
}

/* if user wants to set HTTP version to 1.1 */
if (hdl->http_v1_1)
curl_easy_setopt(hdl->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
}

gboolean
Expand Down