diff --git a/src/rest_vol.c b/src/rest_vol.c index f40423db..a23c409a 100644 --- a/src/rest_vol.c +++ b/src/rest_vol.c @@ -2144,10 +2144,9 @@ 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 { @@ -2155,8 +2154,8 @@ RV_find_object_by_path(RV_object_t *parent_obj, const char *obj_path, H5I_type_t 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"); @@ -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; @@ -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)) @@ -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; diff --git a/src/rest_vol_dataset.c b/src/rest_vol_dataset.c index 3344029e..dfaa66aa 100644 --- a/src/rest_vol_dataset.c +++ b/src/rest_vol_dataset.c @@ -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, @@ -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)) @@ -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)) diff --git a/src/rest_vol_link.c b/src/rest_vol_link.c index f2538f15..88e03f38 100644 --- a/src/rest_vol_link.c +++ b/src/rest_vol_link.c @@ -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//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 { @@ -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); @@ -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; @@ -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), @@ -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) @@ -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 @@ -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;