Skip to content

Commit

Permalink
Check server version for long link URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Dec 18, 2023
1 parent cc2a6e5 commit bf04eb9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/rest_vol.h
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,8 @@ herr_t RV_convert_datatype_to_JSON(hid_t type_id, char **type_body, size_t *type
#define SERVER_VERSION_SUPPORTS_FIXED_LENGTH_UTF8(version) \
(SERVER_VERSION_MATCHES_OR_EXCEEDS(version, 0, 8, 5))

#define SERVER_VERSION_SUPPORTS_LONG_URLS(version) (SERVER_VERSION_MATCHES_OR_EXCEEDS(version, 0, 8, 5))

#ifdef __cplusplus
}
#endif
Expand Down
50 changes: 50 additions & 0 deletions src/rest_vol_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ RV_link_create(H5VL_link_create_args_t *args, void *obj, const H5VL_loc_params_t
new_link_loc_obj->URI, url_encoded_link_name)) < 0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "snprintf error");

if (!(SERVER_VERSION_SUPPORTS_LONG_URLS(new_link_loc_obj->domain->u.file.server_version)) &&
(url_len >= OLD_URL_MAX_LENGTH))
FUNC_GOTO_ERROR(H5E_LINK, H5E_UNSUPPORTED, FAIL,
"URL with length > 2048 not supported by server versions before 0.8.5");

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

Expand Down Expand Up @@ -542,6 +547,12 @@ RV_link_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_get_args_t
0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "snprintf error");

if (!(SERVER_VERSION_SUPPORTS_LONG_URLS(loc_obj->domain->u.file.server_version)) &&
(url_len >= OLD_URL_MAX_LENGTH))
FUNC_GOTO_ERROR(
H5E_LINK, H5E_UNSUPPORTED, FAIL,
"URL with length > 2048 not supported by server versions before 0.8.5");

if (url_len >= URL_MAX_LENGTH)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL,
"H5Lget_info request URL size exceeded maximum URL size");
Expand Down Expand Up @@ -653,6 +664,11 @@ RV_link_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_get_args_t
0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "snprintf error");

if (!(SERVER_VERSION_SUPPORTS_LONG_URLS(loc_obj->domain->u.file.server_version)) &&
(url_len >= OLD_URL_MAX_LENGTH))
FUNC_GOTO_ERROR(H5E_LINK, H5E_UNSUPPORTED, FAIL,
"URL with length > 2048 not supported by server versions before 0.8.5");

if (url_len >= URL_MAX_LENGTH)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL,
"H5Lget_name_by_idx request URL size exceeded maximum URL size");
Expand Down Expand Up @@ -760,6 +776,12 @@ RV_link_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_get_args_t
0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "snprintf error");

if (!(SERVER_VERSION_SUPPORTS_LONG_URLS(loc_obj->domain->u.file.server_version)) &&
(url_len >= OLD_URL_MAX_LENGTH))
FUNC_GOTO_ERROR(
H5E_LINK, H5E_UNSUPPORTED, FAIL,
"URL with length > 2048 not supported by server versions before 0.8.5");

if (url_len >= URL_MAX_LENGTH)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL,
"H5Lget_val request URL size exceeded maximum URL size");
Expand Down Expand Up @@ -938,6 +960,12 @@ RV_link_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_speci
0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "snprintf error");

if (!(SERVER_VERSION_SUPPORTS_LONG_URLS(loc_obj->domain->u.file.server_version)) &&
(url_len >= OLD_URL_MAX_LENGTH))
FUNC_GOTO_ERROR(
H5E_LINK, H5E_UNSUPPORTED, FAIL,
"URL with length > 2048 not supported by server versions before 0.8.5");

if (url_len >= URL_MAX_LENGTH)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL,
"H5Ldelete request URL size exceeded maximum URL size");
Expand Down Expand Up @@ -1036,6 +1064,11 @@ 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");

if (!(SERVER_VERSION_SUPPORTS_LONG_URLS(loc_obj->domain->u.file.server_version)) &&
(url_len >= OLD_URL_MAX_LENGTH))
FUNC_GOTO_ERROR(H5E_LINK, H5E_UNSUPPORTED, FAIL,
"URL with length > 2048 not supported by server versions before 0.8.5");

if (url_len >= URL_MAX_LENGTH)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL,
"H5Lexists request URL size exceeded maximum URL size");
Expand Down Expand Up @@ -1121,6 +1154,12 @@ RV_link_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_speci
loc_obj->URI)) < 0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "snprintf error");

if (!(SERVER_VERSION_SUPPORTS_LONG_URLS(loc_obj->domain->u.file.server_version)) &&
(url_len >= OLD_URL_MAX_LENGTH))
FUNC_GOTO_ERROR(
H5E_LINK, H5E_UNSUPPORTED, FAIL,
"URL with length > 2048 not supported by server versions before 0.8.5");

if (url_len >= URL_MAX_LENGTH)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL,
"H5Literate/visit request URL size exceeded maximum URL size");
Expand Down Expand Up @@ -1157,6 +1196,12 @@ RV_link_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_speci
((RV_object_t *)link_iter_group_object)->URI)) < 0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "snprintf error");

if (!(SERVER_VERSION_SUPPORTS_LONG_URLS(loc_obj->domain->u.file.server_version)) &&
(url_len >= OLD_URL_MAX_LENGTH))
FUNC_GOTO_ERROR(
H5E_LINK, H5E_UNSUPPORTED, FAIL,
"URL with length > 2048 not supported by server versions before 0.8.5");

if (url_len >= URL_MAX_LENGTH)
FUNC_GOTO_ERROR(
H5E_LINK, H5E_SYSERRSTR, FAIL,
Expand Down Expand Up @@ -2020,6 +2065,11 @@ RV_build_link_table(char *HTTP_response, hbool_t is_recursive, int (*sort_func)(
url_encoded_link_name)) < 0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "snprintf error");

// if (!(SERVER_VERSION_SUPPORTS_LONG_URLS(???->domain->u.file.server_version))
// && (url_len >= OLD_URL_MAX_LENGTH))
// FUNC_GOTO_ERROR(H5E_LINK, H5E_UNSUPPORTED, FAIL, "URL with length > 2048 not
// supported by server versions before 0.8.5");

if (url_len >= URL_MAX_LENGTH)
FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL,
"link GET request URL size exceeded maximum URL size");
Expand Down
3 changes: 3 additions & 0 deletions src/rest_vol_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
*/
#define URL_MAX_LENGTH ((64 * 1024) + 1024) + 2048

/* Maximum URL length supported by server API versions <= 0.8.4 */
#define OLD_URL_MAX_LENGTH 2048

/* Maximum length in characters of the URI of an object as returned by the server. If the
* server in question returns URIs which are longer than this, the value will have to be
* adjusted. Otherwise, the URIs will be truncated and invalid, likely causing severe
Expand Down

0 comments on commit bf04eb9

Please sign in to comment.