From fc5772960472279db3e3d6b47b26c9f0e045e64f Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Thu, 12 Oct 2023 16:41:28 -0500 Subject: [PATCH] Make server connection info file-local H5Fdelete doesn't receive file information besides the name, so this may be a non-starter. --- src/rest_vol.c | 91 +++++++++++++++++++++++------ src/rest_vol.h | 25 +++++--- src/rest_vol_attr.c | 123 +++++++++++++++++++++++++++++++++++----- src/rest_vol_dataset.c | 20 +++++-- src/rest_vol_datatype.c | 10 +++- src/rest_vol_file.c | 52 ++++++++++++++--- src/rest_vol_group.c | 22 +++++-- src/rest_vol_link.c | 44 +++++++++++++- src/rest_vol_object.c | 83 +++++++++++++++++++++++---- 9 files changed, 397 insertions(+), 73 deletions(-) diff --git a/src/rest_vol.c b/src/rest_vol.c index 72852f32..b74d50ab 100644 --- a/src/rest_vol.c +++ b/src/rest_vol.c @@ -661,8 +661,9 @@ H5Pset_fapl_rest_vol(hid_t fapl_id) if ((ret_value = H5Pset_vol(fapl_id, H5_rest_id_g, NULL)) < 0) FUNC_GOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't set REST VOL connector in FAPL"); - if (H5_rest_set_connection_information() < 0) - FUNC_GOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't set REST VOL connector connection information"); + // now always handled at file open/create time + // if (H5_rest_set_connection_information() < 0) + // FUNC_GOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't set REST VOL connector connection information"); done: PRINT_ERROR_STACK; @@ -702,7 +703,7 @@ H5rest_get_object_uri(hid_t obj_id) * June, 2018 */ herr_t -H5_rest_set_connection_information(void) +H5_rest_set_connection_information(server_info_t *server_info) { H5_rest_ad_info_t ad_info; const char *URL; @@ -710,6 +711,9 @@ H5_rest_set_connection_information(void) FILE *config_file = NULL; herr_t ret_value = SUCCEED; + const char *username = NULL; + const char *password = NULL; + memset(&ad_info, 0, sizeof(ad_info)); /* @@ -765,8 +769,8 @@ H5_rest_set_connection_information(void) } } - const char *username = getenv("HSDS_USERNAME"); - const char *password = getenv("HSDS_PASSWORD"); + username = getenv("HSDS_USERNAME"); + password = getenv("HSDS_PASSWORD"); if (username || password) { /* Attempt to set authentication information */ @@ -942,10 +946,44 @@ H5_rest_set_connection_information(void) "must specify a base URL - please set HSDS_ENDPOINT environment variable or create a " "config file"); + /* Copy server information */ + if (server_info) { + if (username) { + if ((server_info->username = RV_calloc(strlen(username) + 1)) == NULL) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, "can't allocate space for username"); + + strcpy(server_info->username, username); + } + + if (password) { + if ((server_info->password = RV_calloc(strlen(password) + 1)) == NULL) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, "can't allocate space for password"); + + strcpy(server_info->password, password); + } + + if ((server_info->base_URL = RV_calloc(strlen(base_URL) + 1)) == NULL) { + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, "can't allocate space for URL"); + + strcpy(server_info->base_URL, base_URL); + } + } + done: if (config_file) fclose(config_file); + if (ret_value < 0 && server_info) { + RV_free(server_info->username); + server_info->username = NULL; + + RV_free(server_info->password); + server_info->password = NULL; + + RV_free(server_info->base_URL); + server_info->base_URL = NULL; + } + PRINT_ERROR_STACK; return ret_value; @@ -2057,7 +2095,7 @@ RV_find_object_by_path(RV_object_t *parent_obj, const char *obj_path, H5I_type_t object_type_to_string(parent_obj->obj_type), parent_obj->URI); #endif - version = parent_obj->domain->u.file.server_version; + version = parent_obj->domain->u.file.server_info.version; /* In order to not confuse the server, make sure the path has no leading spaces */ while (*obj_path == ' ') @@ -2442,10 +2480,11 @@ RV_parse_creation_properties_callback(yajl_val parse_tree, char **GCPL_buf_out) herr_t RV_copy_object_loc_info_callback(char *HTTP_response, void *callback_data_in, void *callback_data_out) { - yajl_val parse_tree = NULL, key_obj; - char *parsed_string; - loc_info *loc_info_out = (loc_info *)callback_data_out; - herr_t ret_value = SUCCEED; + yajl_val parse_tree = NULL, key_obj; + char *parsed_string; + loc_info *loc_info_out = (loc_info *)callback_data_out; + server_info_t *server_info = (server_info_t *)callback_data_in; + herr_t ret_value = SUCCEED; char *GCPL_buf = NULL; @@ -2462,6 +2501,8 @@ RV_copy_object_loc_info_callback(char *HTTP_response, void *callback_data_in, vo FUNC_GOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "HTTP response buffer was NULL"); if (!loc_info_out) FUNC_GOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "output buffer was NULL"); + if (!server_info) + FUNC_GOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "server info was NULL"); if (NULL == (parse_tree = yajl_tree_parse(HTTP_response, NULL, 0))) FUNC_GOTO_ERROR(H5E_OBJECT, H5E_PARSEERROR, FAIL, "parsing JSON failed"); @@ -2523,14 +2564,28 @@ RV_copy_object_loc_info_callback(char *HTTP_response, void *callback_data_in, vo FUNC_GOTO_ERROR(H5E_CALLBACK, H5E_CANTALLOC, FAIL, "failed to allocate memory for new domain path"); - strncpy(new_domain->u.file.filepath_name, found_domain.u.file.filepath_name, - strlen(found_domain.u.file.filepath_name) + 1); + strcpy(new_domain->u.file.filepath_name, found_domain.u.file.filepath_name); + + if ((new_domain->u.file.server_info.username = RV_malloc(strlen(server_info->username) + 1)) == NULL) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, "can't allocate space for copied username"); + + strcpy(new_domain->u.file.server_info.username, server_info->username); + + if ((new_domain->u.file.server_info.password = RV_malloc(strlen(server_info->password) + 1)) == NULL) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, "can't allocate space for copied password"); + + strcpy(new_domain->u.file.server_info.password, server_info->password); + + if ((new_domain->u.file.server_info.base_URL = RV_malloc(strlen(server_info->base_URL) + 1)) == NULL) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, "can't allocate space for copied URL"); + + strcpy(new_domain->u.file.server_info.base_URL, server_info->base_URL); - new_domain->u.file.intent = loc_info_out->domain->u.file.intent; - new_domain->u.file.fapl_id = H5Pcopy(loc_info_out->domain->u.file.fapl_id); - new_domain->u.file.fcpl_id = H5Pcopy(loc_info_out->domain->u.file.fcpl_id); - new_domain->u.file.ref_count = 1; - new_domain->u.file.server_version = found_domain.u.file.server_version; + new_domain->u.file.intent = loc_info_out->domain->u.file.intent; + new_domain->u.file.fapl_id = H5Pcopy(loc_info_out->domain->u.file.fapl_id); + new_domain->u.file.fcpl_id = H5Pcopy(loc_info_out->domain->u.file.fcpl_id); + new_domain->u.file.ref_count = 1; + new_domain->u.file.server_info.version = found_domain.u.file.server_info.version; /* Allocate root "path" on heap for consistency with other RV_object_t types */ if ((new_domain->handle_path = RV_malloc(2)) == NULL) @@ -2541,7 +2596,7 @@ RV_copy_object_loc_info_callback(char *HTTP_response, void *callback_data_in, vo /* Assume that original domain and external domain have the same server version. * This will always be true unless it becomes possible for external links to point to * objects on different servers entirely. */ - memcpy(&new_domain->u.file.server_version, &loc_info_out->domain->u.file.server_version, + memcpy(&new_domain->u.file.server_info.version, &loc_info_out->domain->u.file.server_info.version, sizeof(server_api_version)); if (RV_file_close(loc_info_out->domain, H5P_DEFAULT, NULL) < 0) diff --git a/src/rest_vol.h b/src/rest_vol.h index f5b19e9d..a82e5e33 100644 --- a/src/rest_vol.h +++ b/src/rest_vol.h @@ -490,6 +490,14 @@ typedef struct server_api_version { size_t patch; } server_api_version; +// TODO +typedef struct server_info_t { + char *username; + char *password; + char *base_URL; + server_api_version version; +} server_info_t; + /* * Definitions for the basic objects which the REST VOL uses * to represent various HDF5 objects internally. The base object @@ -499,12 +507,13 @@ typedef struct server_api_version { typedef struct RV_object_t RV_object_t; typedef struct RV_file_t { - unsigned intent; - unsigned ref_count; - char *filepath_name; - hid_t fcpl_id; - hid_t fapl_id; - server_api_version server_version; + unsigned intent; + unsigned ref_count; + char *filepath_name; + /* TODO - Username/password in global curl handle are still used for now */ + server_info_t server_info; + hid_t fcpl_id; + hid_t fapl_id; } RV_file_t; typedef struct RV_group_t { @@ -653,8 +662,8 @@ typedef struct loc_info { extern "C" { #endif -/* Function to set the connection information for the connector to connect to the server */ -herr_t H5_rest_set_connection_information(void); +/* Function to set the connection information on a file for the connector to connect to the server */ +herr_t H5_rest_set_connection_information(server_info_t *server_info); /* Alternate, more portable version of the basename function which doesn't modify its argument */ const char *H5_rest_basename(const char *path); diff --git a/src/rest_vol_attr.c b/src/rest_vol_attr.c index 3f8eea48..8269055b 100644 --- a/src/rest_vol_attr.c +++ b/src/rest_vol_attr.c @@ -171,7 +171,7 @@ RV_attr_create(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_ /* See HSDS#223 */ if ((H5I_DATATYPE == new_attribute->u.attribute.parent_obj_type) && - !(SERVER_VERSION_MATCHES_OR_EXCEEDS(parent->domain->u.file.server_version, 0, 8, 0))) + !(SERVER_VERSION_MATCHES_OR_EXCEEDS(parent->domain->u.file.server_info.version, 0, 8, 0))) FUNC_GOTO_ERROR(H5E_ATTR, H5E_UNSUPPORTED, NULL, "server versions before 0.8.0 cannot properly create attributes on datatypes"); @@ -327,6 +327,12 @@ RV_attr_create(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_ uinfo.buffer_size = (size_t)create_request_body_len; uinfo.bytes_sent = 0; + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, new_attribute->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, NULL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, new_attribute->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, NULL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, NULL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_UPLOAD, 1)) @@ -549,7 +555,8 @@ RV_attr_open(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_na switch (loc_params->loc_data.loc_by_idx.idx_type) { case (H5_INDEX_CRT_ORDER): - if (SERVER_VERSION_MATCHES_OR_EXCEEDS(parent->domain->u.file.server_version, 0, 8, 0)) { + if (SERVER_VERSION_MATCHES_OR_EXCEEDS(parent->domain->u.file.server_info.version, 0, 8, + 0)) { request_idx_type = "&CreateOrder=1"; } else { @@ -619,6 +626,12 @@ RV_attr_open(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_na FUNC_GOTO_ERROR(H5E_ATTR, H5E_SYSERRSTR, NULL, "attribute open URL exceeded maximum URL size"); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, attribute->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, NULL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, attribute->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, NULL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, NULL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPGET, 1)) @@ -703,6 +716,10 @@ RV_attr_open(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_na printf("-> URL for attribute open request: %s\n\n", request_url); #endif + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_USERNAME, attribute->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, NULL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_PASSWORD, attribute->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, NULL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, NULL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPGET, 1)) @@ -938,6 +955,10 @@ RV_attr_read(void *attr, hid_t dtype_id, void *buf, hid_t dxpl_id, void **req) printf("-> URL for attribute read request: %s\n\n", request_url); #endif + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_USERNAME, attribute->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_PASSWORD, attribute->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPGET, 1)) @@ -1142,6 +1163,11 @@ RV_attr_write(void *attr, hid_t dtype_id, const void *buf, hid_t dxpl_id, void * uinfo.buffer_size = write_body_len; uinfo.bytes_sent = 0; + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_USERNAME, attribute->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_PASSWORD, attribute->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_UPLOAD, 1)) @@ -1427,8 +1453,8 @@ RV_attr_get(void *obj, H5VL_attr_get_args_t *args, hid_t dxpl_id, void **req) switch (loc_params->loc_data.loc_by_idx.idx_type) { case (H5_INDEX_CRT_ORDER): - if (SERVER_VERSION_MATCHES_OR_EXCEEDS(loc_obj->domain->u.file.server_version, 0, - 8, 0)) { + if (SERVER_VERSION_MATCHES_OR_EXCEEDS(loc_obj->domain->u.file.server_info.version, + 0, 8, 0)) { request_idx_type = "&CreateOrder=1"; } else { @@ -1486,7 +1512,14 @@ RV_attr_get(void *obj, H5VL_attr_get_args_t *args, hid_t dxpl_id, void **req) if (url_len >= URL_MAX_LENGTH) FUNC_GOTO_ERROR(H5E_ATTR, H5E_SYSERRSTR, FAIL, "attribute open URL exceeded maximum URL size"); - + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_USERNAME, + loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL username: %s", + curl_err_buf); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_PASSWORD, + loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL password: %s", + curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); @@ -1551,6 +1584,12 @@ RV_attr_get(void *obj, H5VL_attr_get_args_t *args, hid_t dxpl_id, void **req) /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPGET, 1)) @@ -1626,8 +1665,8 @@ RV_attr_get(void *obj, H5VL_attr_get_args_t *args, hid_t dxpl_id, void **req) switch (loc_params->loc_data.loc_by_idx.idx_type) { case (H5_INDEX_CRT_ORDER): - if (SERVER_VERSION_MATCHES_OR_EXCEEDS(loc_obj->domain->u.file.server_version, 0, - 7, 3)) { + if (SERVER_VERSION_MATCHES_OR_EXCEEDS(loc_obj->domain->u.file.server_info.version, + 0, 7, 3)) { request_idx_type = "&CreateOrder=1"; } else { @@ -1682,6 +1721,14 @@ RV_attr_get(void *obj, H5VL_attr_get_args_t *args, hid_t dxpl_id, void **req) FUNC_GOTO_ERROR(H5E_ATTR, H5E_SYSERRSTR, FAIL, "attribute open URL exceeded maximum URL size"); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_USERNAME, + loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL username: %s", + curl_err_buf); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_PASSWORD, + loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL password: %s", + curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); @@ -1892,6 +1939,12 @@ RV_attr_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_attr_speci /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE")) @@ -2062,7 +2115,12 @@ RV_attr_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_attr_speci /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); - + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE")) @@ -2224,6 +2282,12 @@ RV_attr_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_attr_speci /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPGET, 1)) @@ -2311,7 +2375,7 @@ RV_attr_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_attr_speci switch (parent_obj_type) { case H5I_FILE: - /* Copy fapl, fcpl, and filepath name to new object */ + /* Copy plists, filepath, and server info to new object */ if (H5I_INVALID_HID == (attr_iter_obj->u.file.fapl_id = H5Pcopy(loc_obj->u.file.fapl_id))) @@ -2319,14 +2383,42 @@ RV_attr_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_attr_speci if (H5I_INVALID_HID == (attr_iter_obj->u.file.fcpl_id = H5Pcopy(loc_obj->u.file.fcpl_id))) FUNC_GOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "can't copy FCPL"); - if (NULL == (attr_iter_obj->u.file.filepath_name = - RV_malloc(strlen(loc_obj->u.file.filepath_name) + 1))) + + if ((attr_iter_obj->u.file.filepath_name = + RV_malloc(strlen(loc_obj->u.file.filepath_name) + 1)) == NULL) FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, - "can't allocate space for copied filepath_name object"); + "can't allocate space for copied filepath"); strncpy(attr_iter_obj->u.file.filepath_name, loc_obj->u.file.filepath_name, strlen(loc_obj->u.file.filepath_name) + 1); + if ((attr_iter_obj->u.file.server_info.username = + RV_malloc(strlen(loc_obj->u.file.server_info.username) + 1)) == NULL) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, + "can't allocate space for copied username"); + + strncpy(attr_iter_obj->u.file.server_info.username, + loc_obj->u.file.server_info.username, + strlen(loc_obj->u.file.server_info.username) + 1); + + if ((attr_iter_obj->u.file.server_info.password = + RV_malloc(strlen(loc_obj->u.file.server_info.password) + 1)) == NULL) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, + "can't allocate space for copied password"); + + strncpy(attr_iter_obj->u.file.server_info.password, + loc_obj->u.file.server_info.password, + strlen(loc_obj->u.file.server_info.password) + 1); + + if ((attr_iter_obj->u.file.server_info.base_URL = + RV_malloc(strlen(loc_obj->u.file.server_info.base_URL) + 1)) == NULL) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, + "can't allocate space for copied URL"); + + strncpy(attr_iter_obj->u.file.server_info.base_URL, + loc_obj->u.file.server_info.base_URL, + strlen(loc_obj->u.file.server_info.base_URL) + 1); + /* This is a copy of the file, not a reference to the same memory */ loc_obj->domain->u.file.ref_count--; break; @@ -2599,7 +2691,12 @@ RV_attr_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_attr_speci /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); - + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPGET, 1)) diff --git a/src/rest_vol_dataset.c b/src/rest_vol_dataset.c index de977f17..675dbabc 100644 --- a/src/rest_vol_dataset.c +++ b/src/rest_vol_dataset.c @@ -247,6 +247,12 @@ RV_dataset_create(void *obj, const H5VL_loc_params_t *loc_params, const char *na printf("-> Dataset creation request URL: %s\n\n", request_url); #endif + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, new_dataset->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_DATASET, H5E_CANTSET, NULL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, new_dataset->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_DATASET, H5E_CANTSET, NULL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_DATASET, H5E_CANTSET, NULL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_POST, 1)) @@ -382,8 +388,8 @@ RV_dataset_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name loc_info_out.GCPL_base64 = NULL; /* Locate dataset and set domain */ - search_ret = RV_find_object_by_path(parent, name, &obj_type, RV_copy_object_loc_info_callback, NULL, - &loc_info_out); + search_ret = RV_find_object_by_path(parent, name, &obj_type, RV_copy_object_loc_info_callback, + &dataset->domain->u.file.server_info, &loc_info_out); if (!search_ret || search_ret < 0) FUNC_GOTO_ERROR(H5E_DATASET, H5E_PATH, NULL, "can't locate dataset by path"); @@ -1305,6 +1311,12 @@ RV_dataset_get(void *obj, H5VL_dataset_get_args_t *args, hid_t dxpl_id, void **r /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, dset->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, dset->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); @@ -3304,13 +3316,13 @@ RV_setup_dataset_create_request_body(void *parent_obj, const char *name, hid_t t * Dataset create request */ if (H5P_DATASET_CREATE_DEFAULT != dcpl) { if ((H5Pget_layout(dcpl) == H5D_CONTIGUOUS) && - !(SERVER_VERSION_MATCHES_OR_EXCEEDS(pobj->domain->u.file.server_version, 0, 8, 0))) + !(SERVER_VERSION_MATCHES_OR_EXCEEDS(pobj->domain->u.file.server_info.version, 0, 8, 0))) FUNC_GOTO_ERROR(H5E_PLIST, H5E_UNSUPPORTED, FAIL, "layout H5D_CONTIGUOUS is unsupported for server versions before 0.8.0"); if (RV_convert_dataset_creation_properties_to_JSON(dcpl, &creation_properties_body, &creation_properties_body_len, type_id, - pobj->domain->u.file.server_version) < 0) + pobj->domain->u.file.server_info.version) < 0) FUNC_GOTO_ERROR(H5E_DATASET, H5E_CANTCONVERT, FAIL, "can't convert Dataset Creation Properties to JSON representation"); } diff --git a/src/rest_vol_datatype.c b/src/rest_vol_datatype.c index 43bba653..edc48515 100644 --- a/src/rest_vol_datatype.c +++ b/src/rest_vol_datatype.c @@ -254,6 +254,12 @@ RV_datatype_commit(void *obj, const H5VL_loc_params_t *loc_params, const char *n printf("-> Datatype commit URL: %s\n\n", request_url); #endif + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, new_datatype->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, NULL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, new_datatype->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, NULL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, NULL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_POST, 1)) @@ -388,8 +394,8 @@ RV_datatype_open(void *obj, const H5VL_loc_params_t *loc_params, const char *nam loc_info_out.GCPL_base64 = NULL; /* Locate datatype and set domain */ - search_ret = RV_find_object_by_path(parent, name, &obj_type, RV_copy_object_loc_info_callback, NULL, - &loc_info_out); + search_ret = RV_find_object_by_path(parent, name, &obj_type, RV_copy_object_loc_info_callback, + &datatype->domain->u.file.server_info, &loc_info_out); if (!search_ret || search_ret < 0) FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_PATH, NULL, "can't locate datatype by path"); diff --git a/src/rest_vol_file.c b/src/rest_vol_file.c index 00845e0e..3d80fb53 100644 --- a/src/rest_vol_file.c +++ b/src/rest_vol_file.c @@ -64,9 +64,6 @@ RV_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, h printf(" - Default FAPL? %s\n\n", (H5P_FILE_ACCESS_DEFAULT == fapl_id) ? "yes" : "no"); #endif - if (H5_rest_set_connection_information() < 0) - FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "can't set REST VOL connector connection information"); - if (fapl_id == H5I_INVALID_HID) FUNC_GOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid FAPL"); @@ -74,6 +71,9 @@ RV_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, h if (NULL == (new_file = (RV_object_t *)RV_malloc(sizeof(*new_file)))) FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, NULL, "can't allocate space for file object"); + if (H5_rest_set_connection_information(&new_file->u.file.server_info) < 0) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "can't set REST VOL connector connection information"); + new_file->URI[0] = '\0'; new_file->obj_type = H5I_FILE; new_file->u.file.intent = H5F_ACC_RDWR; @@ -137,6 +137,10 @@ RV_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, h /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_USERNAME, new_file->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTSET, NULL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_PASSWORD, new_file->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTSET, NULL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTSET, NULL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_URL, base_URL)) @@ -256,7 +260,7 @@ RV_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, h FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTCREATE, NULL, "can't parse new file's URI"); /* Store server version */ - if (RV_parse_response(response_buffer.buffer, NULL, &new_file->u.file.server_version, + if (RV_parse_response(response_buffer.buffer, NULL, &new_file->u.file.server_info.version, RV_parse_server_version) < 0) FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTCREATE, NULL, "can't parse server version"); @@ -333,9 +337,6 @@ RV_file_open(const char *name, unsigned flags, hid_t fapl_id, hid_t dxpl_id, voi printf(" - Default FAPL? %s\n\n", (H5P_FILE_ACCESS_DEFAULT == fapl_id) ? "yes" : "no"); #endif - if (H5_rest_set_connection_information() < 0) - FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "can't set REST VOL connector connection information"); - if (fapl_id == H5I_INVALID_HID) FUNC_GOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid FAPL"); @@ -343,6 +344,9 @@ RV_file_open(const char *name, unsigned flags, hid_t fapl_id, hid_t dxpl_id, voi if (NULL == (file = (RV_object_t *)RV_malloc(sizeof(*file)))) FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, NULL, "can't allocate space for file object"); + if (H5_rest_set_connection_information(&file->u.file.server_info) < 0) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "can't set REST VOL connector connection information"); + file->URI[0] = '\0'; file->obj_type = H5I_FILE; file->u.file.intent = flags; @@ -382,6 +386,10 @@ RV_file_open(const char *name, unsigned flags, hid_t fapl_id, hid_t dxpl_id, voi /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_USERNAME, file->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTSET, NULL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_PASSWORD, file->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTSET, NULL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTSET, NULL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPGET, 1)) @@ -405,7 +413,7 @@ RV_file_open(const char *name, unsigned flags, hid_t fapl_id, hid_t dxpl_id, voi FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "can't parse file's URI"); /* Store server version */ - if (RV_parse_response(response_buffer.buffer, NULL, &file->u.file.server_version, + if (RV_parse_response(response_buffer.buffer, NULL, &file->u.file.server_info.version, RV_parse_server_version) < 0) FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTCREATE, NULL, "can't parse server version"); @@ -668,6 +676,10 @@ RV_file_specific(void *obj, H5VL_file_specific_args_t *args, hid_t dxpl_id, void snprintf(request_url, URL_MAX_LENGTH, "%s%s", base_URL, flush_string); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_USERNAME, file->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_PASSWORD, file->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_URL, request_url)) @@ -747,6 +759,15 @@ RV_file_specific(void *obj, H5VL_file_specific_args_t *args, hid_t dxpl_id, void /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); + /* TODO - H5Fdelete doesn't receive a file handle, so the username/password can't be pulled from + * it */ + /* + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_USERNAME, + file->domain->u.file.server_info.username)) FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't + set cURL username: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_PASSWORD, + file->domain->u.file.server_info.password)) FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't + set cURL password: %s", curl_err_buf); + */ if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_URL, base_URL)) @@ -843,6 +864,21 @@ RV_file_close(void *file, hid_t dxpl_id, void **req) _file->u.file.filepath_name = NULL; } + if (_file->u.file.server_info.username) { + RV_free(_file->u.file.server_info.username); + _file->u.file.server_info.username; + } + + if (_file->u.file.server_info.password) { + RV_free(_file->u.file.server_info.password); + _file->u.file.server_info.password; + } + + if (_file->u.file.server_info.base_URL) { + RV_free(_file->u.file.server_info.base_URL); + _file->u.file.server_info.base_URL; + } + if (_file->handle_path) { RV_free(_file->handle_path); _file->handle_path = NULL; diff --git a/src/rest_vol_group.c b/src/rest_vol_group.c index 0367ae7d..f3319b7f 100644 --- a/src/rest_vol_group.c +++ b/src/rest_vol_group.c @@ -252,6 +252,10 @@ RV_group_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name printf("-> Group create request URL: %s\n\n", request_url); #endif + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_USERNAME, new_group->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_SYM, H5E_CANTSET, NULL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_PASSWORD, new_group->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_SYM, H5E_CANTSET, NULL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_SYM, H5E_CANTSET, NULL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_POST, 1)) @@ -395,8 +399,8 @@ RV_group_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, loc_info_out.domain = group->domain; loc_info_out.GCPL_base64 = NULL; - search_ret = RV_find_object_by_path(parent, name, &obj_type, RV_copy_object_loc_info_callback, NULL, - &loc_info_out); + search_ret = RV_find_object_by_path(parent, name, &obj_type, RV_copy_object_loc_info_callback, + &group->domain->u.file.server_info, &loc_info_out); if (!search_ret || search_ret < 0) FUNC_GOTO_ERROR(H5E_SYM, H5E_PATH, NULL, "can't locate group by path"); @@ -407,7 +411,7 @@ RV_group_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, #endif /* Decode creation properties, if server supports them and file has them */ - if (SERVER_VERSION_MATCHES_OR_EXCEEDS(parent->domain->u.file.server_version, 0, 8, 0) && + if (SERVER_VERSION_MATCHES_OR_EXCEEDS(parent->domain->u.file.server_info.version, 0, 8, 0) && loc_info_out.GCPL_base64) { if (RV_base64_decode(loc_info_out.GCPL_base64, strlen(loc_info_out.GCPL_base64), (char **)&binary_gcpl, binary_gcpl_size) < 0) @@ -554,9 +558,9 @@ RV_group_get(void *obj, H5VL_group_get_args_t *args, hid_t dxpl_id, void **req) loc_info_out.domain = loc_obj->domain; loc_info_out.GCPL_base64 = NULL; - search_ret = - RV_find_object_by_path(loc_obj, loc_params->loc_data.loc_by_name.name, &obj_type, - RV_copy_object_loc_info_callback, NULL, &loc_info_out); + search_ret = RV_find_object_by_path(loc_obj, loc_params->loc_data.loc_by_name.name, + &obj_type, RV_copy_object_loc_info_callback, + &loc_obj->domain->u.file.server_info, &loc_info_out); if (!search_ret || search_ret < 0) FUNC_GOTO_ERROR(H5E_SYM, H5E_PATH, FAIL, "can't locate group"); @@ -611,6 +615,12 @@ RV_group_get(void *obj, H5VL_group_get_args_t *args, hid_t dxpl_id, void **req) /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_SYM, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_SYM, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_SYM, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPGET, 1)) diff --git a/src/rest_vol_link.c b/src/rest_vol_link.c index 2ee54e45..032cad8d 100644 --- a/src/rest_vol_link.c +++ b/src/rest_vol_link.c @@ -336,7 +336,12 @@ RV_link_create(H5VL_link_create_args_t *args, void *obj, const H5VL_loc_params_t uinfo.buffer = create_request_body; uinfo.buffer_size = (size_t)create_request_body_len; uinfo.bytes_sent = 0; - + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, new_link_loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, new_link_loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_UPLOAD, 1)) @@ -565,7 +570,12 @@ RV_link_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_get_args_t /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); - + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPGET, 1)) @@ -658,6 +668,12 @@ RV_link_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_get_args_t /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPGET, 1)) @@ -773,6 +789,12 @@ RV_link_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_get_args_t /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPGET, 1)) @@ -942,6 +964,12 @@ RV_link_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_speci /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE")) @@ -1020,6 +1048,12 @@ RV_link_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_speci /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPGET, 1)) @@ -1165,6 +1199,12 @@ RV_link_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_speci /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPGET, 1)) diff --git a/src/rest_vol_object.c b/src/rest_vol_object.c index e4ea4af6..b3587c29 100644 --- a/src/rest_vol_object.c +++ b/src/rest_vol_object.c @@ -421,9 +421,9 @@ RV_object_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_object_get_ar /* loc_info_out.domain was copied at function start */ /* Locate group and set domain */ - search_ret = - RV_find_object_by_path(loc_obj, loc_params->loc_data.loc_by_name.name, &obj_type, - RV_copy_object_loc_info_callback, NULL, &loc_info_out); + search_ret = RV_find_object_by_path(loc_obj, loc_params->loc_data.loc_by_name.name, + &obj_type, RV_copy_object_loc_info_callback, + &loc_obj->domain->u.file.server_info, &loc_info_out); if (!search_ret || search_ret < 0) FUNC_GOTO_ERROR(H5E_OBJECT, H5E_PATH, FAIL, "can't locate object by path"); @@ -521,9 +521,9 @@ RV_object_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_object_get_ar /* loc_info_out.domain was copied at function start */ /* Locate group and set domain */ - search_ret = - RV_find_object_by_path(loc_obj, loc_params->loc_data.loc_by_name.name, &obj_type, - RV_copy_object_loc_info_callback, NULL, &loc_info_out); + search_ret = RV_find_object_by_path(loc_obj, loc_params->loc_data.loc_by_name.name, + &obj_type, RV_copy_object_loc_info_callback, + &loc_obj->domain->u.file.server_info, &loc_info_out); if (!search_ret || search_ret < 0) FUNC_GOTO_ERROR(H5E_OBJECT, H5E_PATH, FAIL, "can't locate object by path"); @@ -532,8 +532,8 @@ RV_object_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_object_get_ar switch (loc_params->loc_data.loc_by_idx.idx_type) { case (H5_INDEX_CRT_ORDER): - if (SERVER_VERSION_MATCHES_OR_EXCEEDS(loc_obj->domain->u.file.server_version, 0, - 8, 0)) { + if (SERVER_VERSION_MATCHES_OR_EXCEEDS(loc_obj->domain->u.file.server_info.version, + 0, 8, 0)) { request_idx_type = "&CreateOrder=1"; } else { @@ -580,6 +580,14 @@ RV_object_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_object_get_ar FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "attribute open URL exceeded maximum URL size"); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_USERNAME, + loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL username: %s", + curl_err_buf); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_PASSWORD, + loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL password: %s", + curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); @@ -614,9 +622,9 @@ RV_object_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_object_get_ar loc_info_out.GCPL_base64 = NULL; } - search_ret = - RV_find_object_by_path(loc_obj, found_object_name, &obj_type, - RV_copy_object_loc_info_callback, NULL, &loc_info_out); + search_ret = RV_find_object_by_path(loc_obj, found_object_name, &obj_type, + RV_copy_object_loc_info_callback, + &loc_obj->domain->u.file.server_info, &loc_info_out); if (!search_ret || search_ret < 0) FUNC_GOTO_ERROR(H5E_OBJECT, H5E_PATH, FAIL, "can't locate object by path"); @@ -657,6 +665,12 @@ RV_object_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_object_get_ar /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_OBJECT, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); @@ -827,7 +841,7 @@ RV_object_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_object_s /* Increment refs for specific type */ switch (loc_obj->obj_type) { case H5I_FILE: - /* Copy fapl, fcpl, and filepath name to new object */ + /* Copy plists, filepath, and server info to new object */ if (H5I_INVALID_HID == (iter_object->u.file.fapl_id = H5Pcopy(loc_obj->u.file.fapl_id))) @@ -843,6 +857,33 @@ RV_object_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_object_s strncpy(iter_object->u.file.filepath_name, loc_obj->u.file.filepath_name, strlen(loc_obj->u.file.filepath_name) + 1); + if ((iter_object->u.file.server_info.username = + RV_malloc(strlen(loc_obj->u.file.server_info.username) + 1)) == NULL) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, + "can't allocate space for copied username"); + + strncpy(iter_object->u.file.server_info.username, + loc_obj->u.file.server_info.username, + strlen(loc_obj->u.file.server_info.username) + 1); + + if ((iter_object->u.file.server_info.password = + RV_malloc(strlen(loc_obj->u.file.server_info.password) + 1)) == NULL) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, + "can't allocate space for copied password"); + + strncpy(iter_object->u.file.server_info.password, + loc_obj->u.file.server_info.password, + strlen(loc_obj->u.file.server_info.password) + 1); + + if ((iter_object->u.file.server_info.base_URL = + RV_malloc(strlen(loc_obj->u.file.server_info.base_URL) + 1)) == NULL) + FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, + "can't allocate space for copied URL"); + + strncpy(iter_object->u.file.server_info.base_URL, + loc_obj->u.file.server_info.base_URL, + strlen(loc_obj->u.file.server_info.base_URL) + 1); + /* This is a copy of the file, not a reference to the same memory */ loc_obj->domain->u.file.ref_count--; iter_object->u.file.ref_count = 1; @@ -1065,6 +1106,12 @@ RV_object_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_object_s /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_USERNAME, loc_obj->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL username: %s", curl_err_buf); + if (CURLE_OK != + curl_easy_setopt(curl, CURLOPT_PASSWORD, loc_obj->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL password: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPGET, 1)) @@ -1775,6 +1822,18 @@ RV_build_object_table(char *HTTP_response, hbool_t is_recursive, int (*sort_func /* Disable use of Expect: 100 Continue HTTP response */ curl_headers = curl_slist_append(curl_headers, "Expect:"); + if (CURLE_OK != + curl_easy_setopt( + curl, CURLOPT_USERNAME, + object_iter_data->iter_obj_parent->domain->u.file.server_info.username)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL username: %s", + curl_err_buf); + if (CURLE_OK != + curl_easy_setopt( + curl, CURLOPT_PASSWORD, + object_iter_data->iter_obj_parent->domain->u.file.server_info.password)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL password: %s", + curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", curl_err_buf);