Skip to content

Commit

Permalink
Sync changes with master
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Mar 21, 2024
1 parent 71ba400 commit 5cbc938
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 72 deletions.
52 changes: 23 additions & 29 deletions src/rest_vol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2144,19 +2144,18 @@ RV_find_object_by_path(RV_object_t *parent_obj, const char *obj_path, H5I_type_t
if (RV_JSON_escape_string(obj_path, escaped_obj_path, &escaped_path_size) < 0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_BADVALUE, FAIL, "can't escape object path");

if ((url_len = snprintf(request_url, URL_MAX_LENGTH,
"%s/?follow_soft_links=1&follow_external_links=1%s%s", base_URL,
is_relative_path ? "&parent_id=" : "",
is_relative_path ? parent_obj->URI : "")) < 0)
if ((url_len = snprintf(
request_endpoint, URL_MAX_LENGTH, "/?follow_soft_links=1&follow_external_links=1%s%s",
is_relative_path ? "&parent_id=" : "", is_relative_path ? parent_obj->URI : "")) < 0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "snprintf error");
}
else {
/* Send object path in URL of GET request */
if (NULL == (url_encoded_path_name = H5_rest_url_encode_path(obj_path)))
FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTENCODE, FAIL, "can't URL-encode object path");

if ((url_len = snprintf(request_url, URL_MAX_LENGTH,
"%s/?h5path=%s%s%s&follow_soft_links=1&follow_external_links=1", base_URL,
if ((url_len = snprintf(request_endpoint, URL_MAX_LENGTH,
"/?h5path=%s%s%s&follow_soft_links=1&follow_external_links=1",
url_encoded_path_name, is_relative_path ? "&parent_id=" : "",
is_relative_path ? parent_obj->URI : "")) < 0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "snprintf error");
Expand Down Expand Up @@ -2257,24 +2256,9 @@ RV_find_object_by_path(RV_object_t *parent_obj, const char *obj_path, H5I_type_t
if (url_len >= URL_MAX_LENGTH)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "Request URL size exceeded maximum URL size");


/* Make POST request that supports long paths if server supports it.
Otherwise, make GET request */
if (SERVER_VERSION_SUPPORTS_LONG_NAMES(version)) {
#ifdef RV_CONNECTOR_DEBUG
printf(" /**********************************\\\n");
printf("-> | Making GET request to the server |\n");
printf(" \\**********************************/\n\n");
#endif

http_response = RV_curl_get(curl, &parent_obj->domain->u.file.server_info, request_endpoint,
parent_obj->domain->u.file.filepath_name, CONTENT_TYPE_JSON);
} else {
#ifdef RV_CONNECTOR_DEBUG
printf(" /**********************************\\\n");
printf("-> | Making POST request to the server |\n");
printf(" \\**********************************/\n\n");
#endif
const char *fmt_string = "{\"h5paths\": [\"%s\"]}";
size_t request_body_len = 0;
int bytes_printed = 0;
Expand All @@ -2291,8 +2275,18 @@ RV_find_object_by_path(RV_object_t *parent_obj, const char *obj_path, H5I_type_t
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL,
"request body size exceeded allocated buffer size");

http_response = RV_curl_post(curl, &parent_obj->domain->u.file.server_info, request_endpoint,
parent_obj->domain->u.file.filepath_name, CONTENT_TYPE_JSON)
if ((http_response = RV_curl_post(curl, &parent_obj->domain->u.file.server_info, request_endpoint,
parent_obj->domain->u.file.filepath_name, request_body,
(size_t)bytes_printed, CONTENT_TYPE_JSON)) < 0)
FUNC_GOTO_ERROR(H5E_OBJECT, H5E_CANTGET, FAIL,
"internal failure while making POST request to server");
}
else {

if ((http_response = RV_curl_get(curl, &parent_obj->domain->u.file.server_info, request_endpoint,
parent_obj->domain->u.file.filepath_name, CONTENT_TYPE_JSON)) < 0)
FUNC_GOTO_ERROR(H5E_OBJECT, H5E_CANTGET, FAIL,
"internal failure while making GET request to server");
}

if (HTTP_SUCCESS(http_response))
Expand Down Expand Up @@ -2492,12 +2486,12 @@ RV_parse_creation_properties_callback(yajl_val parse_tree, char **GCPL_buf_out)
herr_t
RV_copy_object_loc_info_callback(char *HTTP_response, const void *callback_data_in, void *callback_data_out)
{
yajl_val parse_tree = NULL, key_obj = NULL, target_tree = NULL;
char *parsed_string = NULL;
const char *path_name = NULL;
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;
yajl_val parse_tree = NULL, key_obj = NULL, target_tree = NULL;
char *parsed_string = NULL;
const char *path_name = NULL;
loc_info *loc_info_out = (loc_info *)callback_data_out;
const server_info_t *server_info = (const server_info_t *)callback_data_in;
herr_t ret_value = SUCCEED;

char *GCPL_buf = NULL;

Expand Down
10 changes: 1 addition & 9 deletions src/rest_vol_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ RV_dataset_create(void *obj, const H5VL_loc_params_t *loc_params, const char *na
"dataset create URL size exceeded maximum URL size");

#ifdef RV_CONNECTOR_DEBUG
printf("-> Dataset creation request URL: %s\n\n", request_url);
printf("-> Dataset creation request endpoint: %s\n\n", request_endpoint);
#endif

http_response = RV_curl_post(curl, &new_dataset->domain->u.file.server_info, request_endpoint,
Expand Down Expand Up @@ -722,10 +722,6 @@ RV_dataset_read(size_t count, void *dset[], hid_t mem_type_id[], hid_t _mem_spac

#ifdef RV_CONNECTOR_DEBUG
printf("-> Reading dataset\n\n");

printf(" /***************************************\\\n");
printf("-> | Making GET/POST request to the server |\n");
printf(" \\***************************************/\n\n");
#endif

if (CURLM_OK != curl_multi_setopt(curl_multi_handle, CURLMOPT_MAX_HOST_CONNECTIONS, NUM_MAX_HOST_CONNS))
Expand Down Expand Up @@ -1194,10 +1190,6 @@ RV_dataset_write(size_t count, void *dset[], hid_t mem_type_id[], hid_t _mem_spa

#ifdef RV_CONNECTOR_DEBUG
printf("-> Writing dataset\n\n");

printf(" /**********************************\\\n");
printf("-> | Making PUT request to the server |\n");
printf(" \\**********************************/\n\n");
#endif

if (CURLM_OK != curl_multi_setopt(curl_multi_handle, CURLMOPT_MAX_HOST_CONNECTIONS, NUM_MAX_HOST_CONNS))
Expand Down
68 changes: 34 additions & 34 deletions src/rest_vol_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ RV_link_create(H5VL_link_create_args_t *args, void *obj, const H5VL_loc_params_t
if (SERVER_VERSION_SUPPORTS_LONG_NAMES(new_link_loc_obj->domain->u.file.server_info.version) &&
loc_params->loc_data.loc_by_name.name) {
/* Redirect cURL from the base URL to "/groups/<id>/links" to create the link */
if ((url_len = snprintf(request_endpoint, URL_MAX_LENGTH, "/groups/%s/links",
new_link_loc_obj->URI)) < 0)
if ((url_len =
snprintf(request_endpoint, URL_MAX_LENGTH, "/groups/%s/links", new_link_loc_obj->URI)) < 0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "snprintf error");
}
else {
Expand Down Expand Up @@ -424,7 +424,6 @@ RV_link_create(H5VL_link_create_args_t *args, void *obj, const H5VL_loc_params_t
uinfo.buffer_size = (size_t)create_request_body_len;
uinfo.bytes_sent = 0;

// TODO - Check this uses right filename for external links
http_response = RV_curl_put(curl, &new_link_loc_obj->domain->u.file.server_info, request_endpoint,
new_link_loc_obj->domain->u.file.filepath_name, &uinfo, CONTENT_TYPE_JSON);

Expand Down Expand Up @@ -813,7 +812,7 @@ RV_link_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_speci
RV_object_t *loc_obj = (RV_object_t *)obj;
hbool_t empty_dirname;
size_t escaped_link_size = 0;
size_t request_body_len = 0;
int request_body_len = 0;
hid_t link_iter_group_id = H5I_INVALID_HID;
void *link_iter_group_object = NULL;
char *link_path_dirname = NULL;
Expand Down Expand Up @@ -933,11 +932,10 @@ RV_link_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_speci
} /* end if */

/* Setup cURL to make the request */
if (SERVER_VERSION_SUPPORTS_LONG_NAMES(loc_obj->domain->u.file.server_info.version) &&
loc_params->loc_data.loc_by_name.name) {
if (SERVER_VERSION_SUPPORTS_LONG_NAMES(loc_obj->domain->u.file.server_info.version)) {
/* Send link name in body of POST request */
const char *fmt_string = "{\"titles\": [\"%s\"]}";
int bytes_printed = 0;
const char *fmt_string = "{\"titles\": [\"%s\"]}";
int bytes_printed;

/* JSON escape link name */
if (RV_JSON_escape_string(H5_rest_basename(loc_params->loc_data.loc_by_name.name),
Expand All @@ -952,14 +950,14 @@ RV_link_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_speci
escaped_link_name, &escaped_link_size) < 0)
FUNC_GOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "can't JSON escape link name");

request_body_len = strlen(fmt_string) - 2 + strlen(escaped_link_name) + 1;
request_body_len = (int)(strlen(fmt_string) - 2 + strlen(escaped_link_name) + 1);

if ((request_body = RV_malloc(request_body_len)) == NULL)
if ((request_body = RV_malloc((size_t)request_body_len)) == NULL)
FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTALLOC, FAIL,
"can't allocate space for link query body");

if ((bytes_printed =
snprintf(request_body, request_body_len, fmt_string, escaped_link_name)) < 0)
snprintf(request_body, (size_t)request_body_len, fmt_string, escaped_link_name)) < 0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "snprintf error");

if (bytes_printed >= request_body_len)
Expand All @@ -969,7 +967,17 @@ RV_link_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_speci
if ((url_len = snprintf(request_endpoint, URL_MAX_LENGTH, "/groups/%s/links",
empty_dirname ? loc_obj->URI : temp_URI)) < 0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "snprintf error");


#ifdef RV_CONNECTOR_DEBUG
printf("-> Checking for existence of link using endpoint: %s\n\n", request_endpoint);
#endif

if ((http_response = RV_curl_post(curl, &loc_obj->domain->u.file.server_info,
request_endpoint, loc_obj->domain->u.file.filepath_name,
request_body, (size_t)bytes_printed, CONTENT_TYPE_JSON)) <
0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL,
"internal failure while making POST request to server");
}
else {
/* URL-encode the link name so that the resulting URL for the link GET
Expand All @@ -983,36 +991,28 @@ RV_link_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_speci
empty_dirname ? loc_obj->URI : temp_URI, url_encoded_link_name)) < 0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "snprintf error");

#ifdef RV_CONNECTOR_DEBUG
printf("-> Checking for existence of link using endpoint: %s\n\n", request_endpoint);
#endif
if ((http_response = RV_curl_get(curl, &loc_obj->domain->u.file.server_info, request_endpoint,
loc_obj->domain->u.file.filepath_name, CONTENT_TYPE_JSON)) <
0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL,
"internal failure while making GET request to server");
}

if (url_len >= URL_MAX_LENGTH)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL,
"H5Lexists request URL size exceeded maximum URL size");

#ifdef RV_CONNECTOR_DEBUG
printf("-> Checking for existence of link using URL: %s\n\n", request_url);
#endif
if (SERVER_VERSION_SUPPORTS_LONG_NAMES(loc_obj->domain->u.file.server_info.version)) {
#ifdef RV_CONNECTOR_DEBUG
printf(" /**********************************\\\n");
printf("-> | Making POST request to the server |\n");
printf(" \\**********************************/\n\n");
#endif
if (HTTP_CLIENT_ERROR(http_response) && http_response != 404 && http_response != 410)
FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "malformed client request: response code %zu\n",
http_response);

http_response = RV_curl_post(curl, &loc_obj->domain->u.file.server_info, request_endpoint,
loc_obj->domain->u.file.filepath_name, request_body, bytes_printed, CONTENT_TYPE_JSON)
} else {
#ifdef RV_CONNECTOR_DEBUG
printf(" /**********************************\\\n");
printf("-> | Making GET request to the server |\n");
printf(" \\**********************************/\n\n");
#endif

http_response = RV_curl_get(curl, &loc_obj->domain->u.file.server_info, request_endpoint,
loc_obj->domain->u.file.filepath_name, CONTENT_TYPE_JSON);
}
if (HTTP_SERVER_ERROR(http_response))
FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "internal server failure: response code %zu\n",
http_response);


*ret = HTTP_SUCCESS(http_response);

break;
Expand Down

0 comments on commit 5cbc938

Please sign in to comment.