Skip to content

Commit

Permalink
Silence compiler warnings (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala authored Mar 19, 2024
1 parent c8e0237 commit 93cb19f
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 150 deletions.
111 changes: 63 additions & 48 deletions src/rest_vol.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static size_t H5_rest_curl_write_data_callback(char *buffer, size_t size, size_t
static char *H5_rest_url_encode_path(const char *path);

/* Helper function to parse an object's type from server response */
herr_t RV_parse_type(char *HTTP_response, void *callback_data_in, void *callback_data_out);
herr_t RV_parse_object_class(char *HTTP_response, const void *callback_data_in, void *callback_data_out);

/* Helper function to parse an object's creation properties from server response */
herr_t RV_parse_creation_properties_callback(yajl_val parse_tree, char **GCPL_buf);
Expand Down Expand Up @@ -1539,7 +1539,8 @@ H5_rest_url_encode_path(const char *_path)
if (!_path)
FUNC_GOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "path was NULL");

path = (char *)_path;
/* Silence compiler const warnings */
memcpy(&path, &_path, sizeof(char *));

/* Retrieve the length of the possible path prefix, which could be something like '/', '.', etc. */
cur_pos = path;
Expand Down Expand Up @@ -1666,7 +1667,7 @@ H5_rest_url_encode_path(const char *_path)

/* Helper function to parse an object's type from server response */
herr_t
RV_parse_type(char *HTTP_response, void *callback_data_in, void *callback_data_out)
RV_parse_object_class(char *HTTP_response, const void *callback_data_in, void *callback_data_out)
{
yajl_val parse_tree = NULL, key_obj;
char *parsed_object_string;
Expand Down Expand Up @@ -1715,7 +1716,7 @@ RV_parse_type(char *HTTP_response, void *callback_data_in, void *callback_data_o
yajl_tree_free(parse_tree);

return ret_value;
} /* end RV_parse_type */
} /* end RV_parse_object_class */

/*---------------------------------------------------------------------------
* Function: H5_rest_get_conn_cls
Expand Down Expand Up @@ -1804,8 +1805,8 @@ H5_rest_opt_query(void *obj, H5VL_subclass_t cls, int opt_type, uint64_t *flags)
*
*/
herr_t
RV_parse_response(char *HTTP_response, void *callback_data_in, void *callback_data_out,
herr_t (*parse_callback)(char *, void *, void *))
RV_parse_response(char *HTTP_response, const void *callback_data_in, void *callback_data_out,
herr_t (*parse_callback)(char *, const void *, void *))
{
herr_t ret_value = SUCCEED;

Expand Down Expand Up @@ -1837,7 +1838,7 @@ RV_parse_response(char *HTTP_response, void *callback_data_in, void *callback_da
* July, 2017
*/
herr_t
RV_copy_object_URI_callback(char *HTTP_response, void *callback_data_in, void *callback_data_out)
RV_copy_object_URI_callback(char *HTTP_response, const void *callback_data_in, void *callback_data_out)
{
yajl_val parse_tree = NULL, key_obj;
char *parsed_string;
Expand Down Expand Up @@ -1989,7 +1990,7 @@ RV_copy_object_URI_callback(char *HTTP_response, void *callback_data_in, void *c
*/
htri_t
RV_find_object_by_path(RV_object_t *parent_obj, const char *obj_path, H5I_type_t *target_object_type,
herr_t (*obj_found_callback)(char *, void *, void *), void *callback_data_in,
herr_t (*obj_found_callback)(char *, const void *, void *), void *callback_data_in,
void *callback_data_out)
{
RV_object_t *external_file = NULL;
Expand Down Expand Up @@ -2234,7 +2235,7 @@ RV_find_object_by_path(RV_object_t *parent_obj, const char *obj_path, H5I_type_t

if (SERVER_VERSION_MATCHES_OR_EXCEEDS(version, 0, 8, 0)) {

if (0 > RV_parse_response(response_buffer.buffer, NULL, target_object_type, RV_parse_type))
if (0 > RV_parse_response(response_buffer.buffer, NULL, target_object_type, RV_parse_object_class))
FUNC_GOTO_ERROR(H5E_OBJECT, H5E_CANTGET, FAIL, "failed to get type from URI");
}
else {
Expand Down Expand Up @@ -2264,14 +2265,20 @@ RV_find_object_by_path(RV_object_t *parent_obj, const char *obj_path, H5I_type_t
H5L_TYPE_SOFT == link_info.type ? "soft" : "external");
#endif

if (RV_parse_response(response_buffer.buffer, &link_val_len, NULL, RV_get_link_val_callback) <
0)
get_link_val_out get_link_val_args;
get_link_val_args.in_buf_size = &link_val_len;
get_link_val_args.buf = NULL;

if (RV_parse_response(response_buffer.buffer, NULL, &get_link_val_args,
RV_get_link_val_callback) < 0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't retrieve size of link's value");

if (NULL == (tmp_link_val = RV_malloc(link_val_len)))
FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTALLOC, FAIL, "can't allocate space for link's value");

if (RV_parse_response(response_buffer.buffer, &link_val_len, tmp_link_val,
get_link_val_args.buf = tmp_link_val;

if (RV_parse_response(response_buffer.buffer, NULL, &get_link_val_args,
RV_get_link_val_callback) < 0)
FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't retrieve link's value");

Expand Down Expand Up @@ -2411,13 +2418,13 @@ RV_parse_creation_properties_callback(yajl_val parse_tree, char **GCPL_buf_out)
* May, 2023
*/
herr_t
RV_copy_object_loc_info_callback(char *HTTP_response, void *callback_data_in, void *callback_data_out)
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;
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;
yajl_val parse_tree = NULL, key_obj;
char *parsed_string;
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 Expand Up @@ -2566,16 +2573,16 @@ RV_copy_object_loc_info_callback(char *HTTP_response, void *callback_data_in, vo
* May, 2023
*/
herr_t
RV_copy_link_name_by_index(char *HTTP_response, void *callback_data_in, void *callback_data_out)
RV_copy_link_name_by_index(char *HTTP_response, const void *callback_data_in, void *callback_data_out)
{
yajl_val parse_tree = NULL, key_obj = NULL, link_obj = NULL;
const char *parsed_link_name = NULL;
char *parsed_link_buffer = NULL;
H5VL_loc_by_idx_t *idx_params = (H5VL_loc_by_idx_t *)callback_data_in;
hsize_t index = 0;
char **link_name = (char **)callback_data_out;
const char *curr_key = NULL;
herr_t ret_value = SUCCEED;
yajl_val parse_tree = NULL, key_obj = NULL, link_obj = NULL;
const char *parsed_link_name = NULL;
char *parsed_link_buffer = NULL;
const H5VL_loc_by_idx_t *idx_params = (const H5VL_loc_by_idx_t *)callback_data_in;
hsize_t index = 0;
char **link_name = (char **)callback_data_out;
const char *curr_key = NULL;
herr_t ret_value = SUCCEED;

if (!idx_params)
FUNC_GOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "given index params ptr was NULL");
Expand Down Expand Up @@ -2662,15 +2669,15 @@ RV_copy_link_name_by_index(char *HTTP_response, void *callback_data_in, void *ca
* May, 2023
*/
herr_t
RV_copy_attribute_name_by_index(char *HTTP_response, void *callback_data_in, void *callback_data_out)
RV_copy_attribute_name_by_index(char *HTTP_response, const void *callback_data_in, void *callback_data_out)
{
yajl_val parse_tree = NULL, key_obj;
const char *parsed_string = NULL;
char *parsed_string_buffer = NULL;
H5VL_loc_by_idx_t *idx_params = (H5VL_loc_by_idx_t *)callback_data_in;
hsize_t index = 0;
char **attr_name = (char **)callback_data_out;
herr_t ret_value = SUCCEED;
yajl_val parse_tree = NULL, key_obj;
const char *parsed_string = NULL;
char *parsed_string_buffer = NULL;
const H5VL_loc_by_idx_t *idx_params = (const H5VL_loc_by_idx_t *)callback_data_in;
hsize_t index = 0;
char **attr_name = (char **)callback_data_out;
herr_t ret_value = SUCCEED;

if (!attr_name)
FUNC_GOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "given attr_name was NULL");
Expand Down Expand Up @@ -3327,7 +3334,7 @@ RV_base64_decode(const char *in, size_t in_size, char **out, size_t *out_size)

/* Helper function to store the version of the external HSDS server */
herr_t
RV_parse_server_version(char *HTTP_response, void *callback_data_in, void *callback_data_out)
RV_parse_server_version(char *HTTP_response, const void *callback_data_in, void *callback_data_out)
{
yajl_val parse_tree = NULL, key_obj;
herr_t ret_value = SUCCEED;
Expand Down Expand Up @@ -3395,7 +3402,7 @@ RV_parse_server_version(char *HTTP_response, void *callback_data_in, void *callb

/* Helper function to parse an object's allocated size from server response */
herr_t
RV_parse_allocated_size_callback(char *HTTP_response, void *callback_data_in, void *callback_data_out)
RV_parse_allocated_size_callback(char *HTTP_response, const void *callback_data_in, void *callback_data_out)
{
yajl_val parse_tree = NULL, key_obj = NULL;
herr_t ret_value = SUCCEED;
Expand Down Expand Up @@ -3511,10 +3518,7 @@ RV_get_index_of_matching_handle(dataset_transfer_info *transfer_info, size_t cou
}

herr_t
RV_curl_multi_perform(CURL *curl_multi_handle, dataset_transfer_info *transfer_info, size_t count,
herr_t(success_callback)(hid_t mem_type_id, hid_t mem_space_id, hid_t file_type_id,
hid_t file_space_id, void *buf,
struct response_buffer resp_buffer))
RV_curl_multi_perform(CURL *curl_multi_handle, dataset_transfer_info *transfer_info, size_t count)
{

herr_t ret_value = SUCCEED;
Expand Down Expand Up @@ -3643,13 +3647,24 @@ RV_curl_multi_perform(CURL *curl_multi_handle, dataset_transfer_info *transfer_i
FUNC_GOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL,
"can't get handle information for retry");

if (success_callback(
transfer_info[handle_index].mem_type_id, transfer_info[handle_index].mem_space_id,
transfer_info[handle_index].file_type_id,
transfer_info[handle_index].file_space_id, transfer_info[handle_index].buf,
transfer_info[handle_index].resp_buffer) < 0)
FUNC_GOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL,
"failed to post-process data read from dataset");
switch (transfer_info[handle_index].transfer_type) {
case (READ):
if (RV_dataset_read_cb(transfer_info[handle_index].mem_type_id,
transfer_info[handle_index].mem_space_id,
transfer_info[handle_index].file_type_id,
transfer_info[handle_index].file_space_id,
transfer_info[handle_index].u.read_info.buf,
transfer_info[handle_index].resp_buffer) < 0)
FUNC_GOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL,
"failed to post-process data read from dataset");
break;
case (WRITE):
/* No post-processing necessary */
break;
case (UNINIT):
FUNC_GOTO_ERROR(H5E_DATASET, H5E_BADVALUE, FAIL, "invalid transfer type");
break;
}

/* Clean up */
if (CURLM_OK != curl_multi_remove_handle(curl_multi_handle, curl_multi_msg->easy_handle))
Expand Down
40 changes: 25 additions & 15 deletions src/rest_vol.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,13 @@ typedef struct dataset_write_info {
char *base64_encoded_values;
curl_off_t write_len;
upload_info uinfo;
const void *buf;
} dataset_write_info;

typedef struct dataset_read_info {
H5S_sel_type sel_type;
curl_off_t post_len;
void *buf;
} dataset_read_info;

typedef enum transfer_type_t { UNINIT = 0, READ = 1, WRITE = 2 } transfer_type_t;
Expand All @@ -592,7 +594,6 @@ typedef struct dataset_transfer_info {
struct response_buffer resp_buffer;

RV_object_t *dataset;
void *buf;
char *request_url;
hid_t mem_type_id;
hid_t mem_space_id;
Expand Down Expand Up @@ -671,6 +672,10 @@ typedef enum {
RV_TCONV_REUSE_BKG /* Use buffer as background buffer */
} RV_tconv_reuse_t;

typedef struct get_link_val_out {
size_t *in_buf_size;
void *buf;
} get_link_val_out;
/****************************
* *
* Prototypes *
Expand All @@ -691,29 +696,32 @@ const char *H5_rest_basename(const char *path);
char *H5_rest_dirname(const char *path);

/* Helper function to parse an HTTP response according to the given parse callback function */
herr_t RV_parse_response(char *HTTP_response, void *callback_data_in, void *callback_data_out,
herr_t (*parse_callback)(char *, void *, void *));
herr_t RV_parse_response(char *HTTP_response, const void *callback_data_in, void *callback_data_out,
herr_t (*parse_callback)(char *, const void *, void *));

/* Callback for RV_parse_response() to capture an object's URI */
herr_t RV_copy_object_URI_callback(char *HTTP_response, void *callback_data_in, void *callback_data_out);
herr_t RV_copy_object_URI_callback(char *HTTP_response, const void *callback_data_in,
void *callback_data_out);

/* Callback for RV_parse_response() to capture an object's creation properties */
herr_t RV_copy_object_loc_info_callback(char *HTTP_response, void *callback_data_in, void *callback_data_out);
herr_t RV_copy_object_loc_info_callback(char *HTTP_response, const void *callback_data_in,
void *callback_data_out);

/* Callback for RV_parse_response() to access the name of the n-th returned attribute */
herr_t RV_copy_attribute_name_by_index(char *HTTP_response, void *callback_data_in, void *callback_data_out);
herr_t RV_copy_attribute_name_by_index(char *HTTP_response, const void *callback_data_in,
void *callback_data_out);

/* Callback for RV_parse_response() to access the name of the n-th returned link */
herr_t RV_copy_link_name_by_index(char *HTTP_response, void *callback_data_in, void *callback_data_out);
herr_t RV_copy_link_name_by_index(char *HTTP_response, const void *callback_data_in, void *callback_data_out);

/* Callback for RV_parse_response() to capture the version of the server api */
herr_t RV_parse_server_version(char *HTTP_response, void *callback_data_in, void *callback_data_out);
herr_t RV_parse_server_version(char *HTTP_response, const void *callback_data_in, void *callback_data_out);

/* Helper function to find an object given a starting object to search from and a path */

htri_t RV_find_object_by_path(RV_object_t *parent_obj, const char *obj_path, H5I_type_t *target_object_type,
herr_t (*obj_found_callback)(char *, void *, void *), void *callback_data_in,
void *callback_data_out);
herr_t (*obj_found_callback)(char *, const void *, void *),
void *callback_data_in, void *callback_data_out);

/* Helper function to parse a JSON string representing an HDF5 Dataspace and
* setup an hid_t for the Dataspace */
Expand All @@ -738,16 +746,18 @@ size_t H5_rest_curl_write_data_callback_no_global(char *buffer, size_t size, siz
herr_t RV_set_object_type_header(H5I_type_t parent_obj_type, const char **parent_obj_type_header);

/* Helper function to parse an object's allocated size from server response */
herr_t RV_parse_allocated_size_callback(char *HTTP_response, void *callback_data_in, void *callback_data_out);
herr_t RV_parse_allocated_size_callback(char *HTTP_response, const void *callback_data_in,
void *callback_data_out);

void RV_free_visited_link_hash_table_key(rv_hash_table_key_t value);

/* Counterpart of CURL_PERFORM that takes a curl multi handle,
* and waits until all requests on it have finished before returning. */
herr_t RV_curl_multi_perform(CURL *curl_multi_ptr, dataset_transfer_info *transfer_info, size_t count,
herr_t(success_callback)(hid_t mem_type_id, hid_t mem_space_id,
hid_t file_type_id, hid_t file_space_id, void *buf,
struct response_buffer resp_buffer));
herr_t RV_curl_multi_perform(CURL *curl_multi_ptr, dataset_transfer_info *transfer_info, size_t count);

/* Callbacks used for post-processing after a curl request succeeds */
herr_t RV_dataset_read_cb(hid_t mem_type_id, hid_t mem_space_id, hid_t file_type_id, hid_t file_space_id,
void *buf, struct response_buffer resp_buffer);

/* Dtermine if datatype conversion is necessary */
htri_t RV_need_tconv(hid_t src_type_id, hid_t dst_type_id);
Expand Down
Loading

0 comments on commit 93cb19f

Please sign in to comment.