Skip to content

Commit 238bc5c

Browse files
committed
Use parsed url always
1 parent 369132b commit 238bc5c

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

src/H5FDros3.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ H5FD__ros3_open(const char *url, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
926926
char *fapl_token = NULL;
927927
char *fapl_endpoint = NULL;
928928
H5FD_t *ret_value = NULL;
929+
htri_t endpt_exists = false;
929930

930931
FUNC_ENTER_PACKAGE
931932

@@ -969,19 +970,14 @@ H5FD__ros3_open(const char *url, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
969970
}
970971
}
971972
972-
/* Get the endpoint url, if it exists */
973-
if (fa->authenticate) {
974-
htri_t endpoint_exists;
975-
976-
/* Does the endpoint exist in the fapl? */
977-
if ((endpoint_exists = H5P_exist_plist(plist, ROS3_ENDPOINT_PROP_NAME)) < 0)
978-
HGOTO_ERROR(H5E_VFL, H5E_CANTGET, NULL, "failed check for property endpoint in plist");
973+
/* Does the endpoint exist in the fapl? */
974+
if ((endpt_exists = H5P_exist_plist(plist, ROS3_ENDPOINT_PROP_NAME)) < 0)
975+
HGOTO_ERROR(H5E_VFL, H5E_CANTGET, NULL, "failed check for property endpoint in plist");
979976
980-
/* If so, get it */
981-
if (endpoint_exists) {
982-
if (H5P_get(plist, ROS3_ENDPOINT_PROP_NAME, &fapl_endpoint) < 0)
983-
HGOTO_ERROR(H5E_VFL, H5E_CANTGET, NULL, "unable to get endpoint value");
984-
}
977+
/* If so, get it */
978+
if (endpt_exists) {
979+
if (H5P_get(plist, ROS3_ENDPOINT_PROP_NAME, &fapl_endpoint) < 0)
980+
HGOTO_ERROR(H5E_VFL, H5E_CANTGET, NULL, "unable to get endpoint value");
985981
}
986982
987983
/* Open file; procedure depends on whether or not the fapl instructs to

src/H5FDs3comms.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static void H5FD__s3comms_load_aws_creds_from_env(char *key_id, char *secret_acc
105105

106106
static herr_t H5FD__s3comms_make_iso_8661_string(time_t time, char iso8601[ISO8601_SIZE]);
107107

108-
static parsed_url_t *H5FD__s3comms_parse_url(const char *url, const char *fapl_endpoint);
108+
static parsed_url_t *H5FD__s3comms_parse_url(const char *url, const char *aws_region, const char *fapl_endpoint);
109109

110110
static herr_t H5FD__s3comms_free_purl(parsed_url_t *purl);
111111

@@ -758,7 +758,7 @@ H5FD__s3comms_s3r_open(const char *url, const H5FD_ros3_fapl_t *fa, const char *
758758
HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "unable to allocate space for S3 request HTTP verb");
759759

760760
/* Parse URL */
761-
if (NULL == (handle->purl = H5FD__s3comms_parse_url(url, fapl_endpoint)))
761+
if (NULL == (handle->purl = H5FD__s3comms_parse_url(url, handle->aws_region, fapl_endpoint)))
762762
HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "could not allocate and create parsed URL");
763763

764764
/*************************************
@@ -784,7 +784,7 @@ H5FD__s3comms_s3r_open(const char *url, const H5FD_ros3_fapl_t *fa, const char *
784784
HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, NULL, "error while setting CURL option (CURLOPT_FAILONERROR)");
785785
if (CURLE_OK != curl_easy_setopt(curlh, CURLOPT_WRITEFUNCTION, H5FD__s3comms_curl_write_callback))
786786
HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, NULL, "error while setting CURL option (CURLOPT_WRITEFUNCTION)");
787-
if (CURLE_OK != curl_easy_setopt(curlh, CURLOPT_URL, url))
787+
if (CURLE_OK != curl_easy_setopt(curlh, CURLOPT_URL, handle->purl->url))
788788
HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, NULL, "error while setting CURL option (CURLOPT_URL)");
789789

790790
#if S3COMMS_CURL_VERBOSITY > 1
@@ -1434,14 +1434,14 @@ H5FD__s3comms_bytes_to_hex(char *dest, size_t dest_len, const unsigned char *msg
14341434
/*----------------------------------------------------------------------------
14351435
* Function: H5FD__s3comms_parse_url
14361436
*
1437-
* Purpose: Release resources from a parsed_url_t pointer
1437+
* Purpose: Parse args to a parsed_url_t pointer
14381438
*
14391439
* Return: Success: A pointer to a parsed_url_t
14401440
* Failure: NULL
14411441
*----------------------------------------------------------------------------
14421442
*/
14431443
static parsed_url_t *
1444-
H5FD__s3comms_parse_url(const char *url, const char *fapl_endpoint)
1444+
H5FD__s3comms_parse_url(const char *url, const char *aws_region, const char *fapl_endpoint)
14451445
{
14461446
CURLUcode rc;
14471447
CURLU *curlurl = NULL;
@@ -1467,22 +1467,27 @@ H5FD__s3comms_parse_url(const char *url, const char *fapl_endpoint)
14671467

14681468
// Calculate lengths
14691469
size_t bucket_len = slash_pos - path_start;
1470-
size_t key_len = strlen(slash_pos + 1);
1470+
slash_pos++; /*skip over slash */
1471+
size_t key_len = strlen(slash_pos);
14711472

14721473
/* Copy bucket and key strings into temp variables */
14731474
strncpy(bucket_name, path_start, bucket_len);
14741475
bucket_name[bucket_len] = '\0';
14751476

1476-
strncpy(object_key, slash_pos + 1, key_len);
1477-
object_key[bucket_len] = '\0';
1477+
strncpy(object_key, slash_pos, key_len);
1478+
object_key[key_len] = '\0';
14781479

14791480
if(fapl_endpoint)
14801481
snprintf(s3_url, strlen(fapl_endpoint) + strlen(bucket_name) + strlen(object_key) + 3,
14811482
"%s/%s/%s", fapl_endpoint, bucket_name, object_key);
1482-
else
1483-
/*object_url = "https://s3."+region_code+".amazonaws.com/"+bucket_name+"/"+object_key;*/
1484-
snprintf(s3_url, 24 + strlen(bucket_name) + strlen(object_key) + 3,
1485-
"https://s3.amazonaws.com/%s/%s", bucket_name, object_key);
1483+
else {
1484+
if (aws_region == NULL)
1485+
snprintf(s3_url, 24 + strlen(bucket_name) + strlen(object_key) + 3,
1486+
"https://s3.amazonaws.com/%s/%s", bucket_name, object_key);
1487+
else
1488+
snprintf(s3_url, 24 + strlen(aws_region) + strlen(bucket_name) + strlen(object_key) + 3,
1489+
"https://s3.%s.amazonaws.com/%s/%s", bucket_name, object_key);
1490+
}
14861491
object_url = s3_url;
14871492
}
14881493
else
@@ -1559,6 +1564,7 @@ H5FD__s3comms_free_purl(parsed_url_t *purl)
15591564
curl_free(purl->port);
15601565
curl_free(purl->path);
15611566
curl_free(purl->query);
1567+
curl_free(purl->url);
15621568

15631569
H5MM_xfree(purl);
15641570

src/H5FDs3comms.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ typedef struct {
309309
char *port;
310310
char *path;
311311
char *query;
312+
char *url;
312313
} parsed_url_t;
313314

314315
/*----------------------------------------------------------------------------

0 commit comments

Comments
 (0)