Skip to content

Commit

Permalink
Merge remote-tracking branch 'public/master' into H5Iget_name
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Aug 1, 2023
2 parents 0d71b34 + b47ab4a commit feafc77
Show file tree
Hide file tree
Showing 6 changed files with 1,370 additions and 80 deletions.
86 changes: 76 additions & 10 deletions src/rest_vol.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ hid_t H5_rest_id_g = H5I_UNINIT;
static hbool_t H5_rest_initialized_g = FALSE;

/* Identifiers for HDF5's error API */
hid_t H5_rest_err_stack_g = H5I_INVALID_HID;
hid_t H5_rest_err_class_g = H5I_INVALID_HID;
hid_t H5_rest_obj_err_maj_g = H5I_INVALID_HID;
hid_t H5_rest_parse_err_min_g = H5I_INVALID_HID;
hid_t H5_rest_link_table_err_min_g = H5I_INVALID_HID;
hid_t H5_rest_link_table_iter_err_min_g = H5I_INVALID_HID;
hid_t H5_rest_attr_table_err_min_g = H5I_INVALID_HID;
hid_t H5_rest_attr_table_iter_err_min_g = H5I_INVALID_HID;
hid_t H5_rest_err_stack_g = H5I_INVALID_HID;
hid_t H5_rest_err_class_g = H5I_INVALID_HID;
hid_t H5_rest_obj_err_maj_g = H5I_INVALID_HID;
hid_t H5_rest_parse_err_min_g = H5I_INVALID_HID;
hid_t H5_rest_link_table_err_min_g = H5I_INVALID_HID;
hid_t H5_rest_link_table_iter_err_min_g = H5I_INVALID_HID;
hid_t H5_rest_attr_table_err_min_g = H5I_INVALID_HID;
hid_t H5_rest_attr_table_iter_err_min_g = H5I_INVALID_HID;
hid_t H5_rest_object_table_err_min_g = H5I_INVALID_HID;
hid_t H5_rest_object_table_iter_err_min_g = H5I_INVALID_HID;

/*
* The CURL pointer used for all cURL operations.
Expand Down Expand Up @@ -122,7 +124,16 @@ const char *dataspace_max_dims_keys[] = {"shape", "maxdims", (const char *)0};
/* JSON keys to retrieve the path of a domain */
const char *domain_keys[] = {"domain", (const char *)0};

/* JSON keys to retrieve a list of attributes */
/* JSON keys to retrieve all of the information from a link when doing link iteration */
const char *links_keys[] = {"links", (const char *)0};
const char *link_title_keys[] = {"title", (const char *)0};
const char *link_creation_time_keys[] = {"created", (const char *)0};

/* JSON keys to retrieve the collection that a hard link belongs to
* (the type of object it points to), "groups", "datasets" or "datatypes"
*/
const char *link_collection_keys2[] = {"collection", (const char *)0};

const char *attributes_keys[] = {"attributes", (const char *)0};

/* Default size for the buffer to allocate during base64-encoding if the caller
Expand Down Expand Up @@ -461,6 +472,13 @@ H5_rest_init(hid_t vipl_id)
if ((H5_rest_attr_table_iter_err_min_g =
H5Ecreate_msg(H5_rest_err_class_g, H5E_MINOR, "Can't iterate through attribute table")) < 0)
FUNC_GOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't create message for attribute iteration error");
if ((H5_rest_object_table_err_min_g =
H5Ecreate_msg(H5_rest_err_class_g, H5E_MINOR, "Can't build table of objects for iteration")) < 0)
FUNC_GOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL,
"can't create error message for object table build error");
if ((H5_rest_object_table_iter_err_min_g =
H5Ecreate_msg(H5_rest_err_class_g, H5E_MINOR, "Can't iterate through object table")) < 0)
FUNC_GOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't create message for object iteration error");

/* Initialized */
H5_rest_initialized_g = TRUE;
Expand Down Expand Up @@ -521,6 +539,12 @@ H5rest_term(void)
if (H5_rest_attr_table_iter_err_min_g >= 0 && H5Eclose_msg(H5_rest_attr_table_iter_err_min_g) < 0)
FUNC_DONE_ERROR(H5E_VOL, H5E_CLOSEERROR, FAIL,
"can't unregister error message for iterating over attribute table");
if (H5_rest_object_table_iter_err_min_g >= 0 && H5Eclose_msg(H5_rest_object_table_err_min_g) < 0)
FUNC_DONE_ERROR(H5E_VOL, H5E_CLOSEERROR, FAIL,
"can't unregister error message for build object table");
if (H5_rest_object_table_iter_err_min_g >= 0 && H5Eclose_msg(H5_rest_object_table_iter_err_min_g) < 0)
FUNC_DONE_ERROR(H5E_VOL, H5E_CLOSEERROR, FAIL,
"can't unregister error message for iterating over object table");

if (H5Eunregister_class(H5_rest_err_class_g) < 0)
FUNC_DONE_ERROR(H5E_VOL, H5E_CLOSEERROR, FAIL, "can't unregister from HDF5 error API");
Expand Down Expand Up @@ -2153,7 +2177,7 @@ RV_find_object_by_path(RV_object_t *parent_obj, const char *obj_path, H5I_type_t
printf(" \\**********************************/\n\n");
#endif

CURL_PERFORM(curl, H5E_LINK, H5E_PATH, FALSE);
CURL_PERFORM(curl, H5E_LINK, H5E_PATH, FAIL);

if (CURLE_OK != curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_response))
FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't get HTTP response code");
Expand Down Expand Up @@ -3238,6 +3262,7 @@ RV_base64_decode(const char *in, size_t in_size, char **out, size_t *out_size)
done:
return ret_value;
} /* end RV_base64_decode() */

/* 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)
Expand Down Expand Up @@ -3373,3 +3398,44 @@ H5PLget_plugin_info(void)
{
return &H5VL_rest_g;
} /* end H5PLget_plugin_info() */

/*-------------------------------------------------------------------------
* Function: H5_rest_compare_string_keys
*
* Purpose: Comparison function to compare two string keys in an
* rv_hash_table_t. This function is mostly used when
* attempting to determine object uniqueness by some
* information from the server, such as an object ID.
*
* Return: Non-zero if the two string keys are equal/Zero if the two
* string keys are not equal
*
* Programmer: Jordan Henderson
* May, 2018
*/
int
H5_rest_compare_string_keys(void *value1, void *value2)
{
const char *val1 = (const char *)value1;
const char *val2 = (const char *)value2;

return !strcmp(val1, val2);
} /* end H5_rest_compare_string_keys() */

/*-------------------------------------------------------------------------
* Function: RV_free_visited_link_hash_table_key
*
* Purpose: Helper function to free keys in the visited link hash table
* used by link iteration.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Jordan Henderson
* June, 2018
*/
void
RV_free_visited_link_hash_table_key(rv_hash_table_key_t value)
{
RV_free(value);
value = NULL;
} /* end RV_free_visited_link_hash_table_key() */
46 changes: 37 additions & 9 deletions src/rest_vol.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,24 @@ typedef struct link_name_by_idx_data {
char *link_name;
} link_name_by_idx_data;

/*
* A struct which is filled out during link iteration and contains
* all of the information needed to iterate through links by both
* alphabetical order and link creation order in increasing and
* decreasing fashion.
*/
typedef struct link_table_entry link_table_entry;
struct link_table_entry {
H5L_info2_t link_info;
double crt_time;
char link_name[LINK_NAME_MAX_LENGTH];

struct {
link_table_entry *subgroup_link_table;
size_t num_entries;
} subgroup;
};

/*
* A struct which is filled out during attribute iteration and
* contains all of the information needed to iterate through
Expand Down Expand Up @@ -498,39 +516,44 @@ struct RV_object_t {
};

/*
* A struct which is filled out and passed to the
* A struct which is filled out and passed to the link and attribute
* iteration callback functions when calling
* H5Literate(_by_name)/H5Lvisit(_by_name), H5Aiterate(_by_name), or H5Ovisit(_by_name)
* H5Literate(_by_name)/H5Lvisit(_by_name) or H5Aiterate(_by_name).
*/
typedef struct iter_data {
H5_iter_order_t iter_order;
H5_index_t index_type;
hbool_t is_recursive;
hsize_t *idx_p;
hid_t iter_obj_id;
unsigned oinfo_fields;
void *op_data;
RV_object_t *iter_obj_parent;

union {
H5A_operator2_t attr_iter_op;
H5L_iterate_t link_iter_op;
H5O_iterate2_t object_iter_op;
} iter_function;
} iter_data;

/*
* A struct which is filled out during link iteration and contains
* all of the information needed to iterate through links by both
* alphabetical order and link creation order in increasing and
* A struct which is filled out during object iteration and contains
* all of the information needed to iterate through objects by both
* alphabetical order and object creation order in increasing and
* decreasing fashion.
*/
typedef struct link_table_entry link_table_entry;
struct link_table_entry {
typedef struct object_table_entry object_table_entry;
struct object_table_entry {
H5O_info2_t object_info;
H5L_info2_t link_info;
double crt_time;
char object_URI[URI_MAX_LENGTH];
char link_name[LINK_NAME_MAX_LENGTH];

struct {
link_table_entry *subgroup_link_table;
size_t num_entries;
object_table_entry *subgroup_object_table;
size_t num_entries;
} subgroup;
};

Expand Down Expand Up @@ -599,9 +622,14 @@ herr_t RV_convert_dataspace_shape_to_JSON(hid_t space_id, char **shape_body, cha
herr_t RV_base64_encode(const void *in, size_t in_size, char **out, size_t *out_size);
herr_t RV_base64_decode(const char *in, size_t in_size, char **out, size_t *out_size);

/* Comparison function to compare two keys in an rv_hash_table_t */
int H5_rest_compare_string_keys(void *value1, void *value2);

/* Helper to turn an object type into a string for a server request */
herr_t RV_set_object_type_header(H5I_type_t parent_obj_type, const char **parent_obj_type_header);

void RV_free_visited_link_hash_table_key(rv_hash_table_key_t value);

#define SERVER_VERSION_MATCHES_OR_EXCEEDS(version, major_needed, minor_needed, patch_needed) \
(version.major > major_needed) || (version.major == major_needed && version.minor > minor_needed) || \
(version.major == major_needed && version.minor == minor_needed && version.patch >= patch_needed)
Expand Down
5 changes: 5 additions & 0 deletions src/rest_vol_datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ RV_datatype_commit(void *obj, const H5VL_loc_params_t *loc_params, const char *n
new_datatype->domain = parent->domain;
parent->domain->u.file.ref_count++;

if (type_id > 0) {
if ((new_datatype->u.datatype.dtype_id = H5Tcopy(type_id)) == H5I_INVALID_HID)
FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't copy type id");
}

new_datatype->handle_path = NULL;

if (name) {
Expand Down
56 changes: 3 additions & 53 deletions src/rest_vol_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ static herr_t RV_build_link_table(char *HTTP_response, hbool_t is_recursive,
static void RV_free_link_table(link_table_entry *link_table, size_t num_entries);
static herr_t RV_traverse_link_table(link_table_entry *link_table, size_t num_entries, iter_data *iter_data,
const char *cur_link_rel_path);
static void RV_free_visited_link_hash_table_key(rv_hash_table_key_t value);

/* Comparison function to compare two string keys in an rv_hash_table_t. */
static int H5_rest_compare_string_keys(void *value1, void *value2);

/* Qsort callbacks to sort links by name or creation order */
static int H5_rest_cmp_links_by_creation_order_inc(const void *link1, const void *link2);
Expand All @@ -52,17 +48,12 @@ const char *link_path_keys2[] = {"h5path", (const char *)0};
const char *link_domain_keys[] = {"link", "h5domain", (const char *)0};
const char *link_domain_keys2[] = {"h5domain", (const char *)0};

/* JSON keys to retrieve all of the information from a link when doing link iteration */
const char *links_keys[] = {"links", (const char *)0};
const char *link_title_keys[] = {"title", (const char *)0};
const char *link_creation_time_keys[] = {"created", (const char *)0};

/* JSON keys to retrieve the collection that a hard link belongs to
* (the type of object it points to), "groups", "datasets" or "datatypes"
*/
const char *link_collection_keys[] = {"link", "collection", (const char *)0};
const char *link_collection_keys2[] = {"collection", (const char *)0};
/*-------------------------------------------------------------------------
const char *link_collection_keys[] = {"link", "collection", (const char *)0};

/*
* Function: RV_link_create
*
* Purpose: Creates an HDF5 link in the given object by making the
Expand Down Expand Up @@ -2272,47 +2263,6 @@ RV_traverse_link_table(link_table_entry *link_table, size_t num_entries, iter_da
return ret_value;
} /* end RV_traverse_link_table() */

/*-------------------------------------------------------------------------
* Function: RV_free_visited_link_hash_table_key
*
* Purpose: Helper function to free keys in the visited link hash table
* used by link iteration.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Jordan Henderson
* June, 2018
*/
static void
RV_free_visited_link_hash_table_key(rv_hash_table_key_t value)
{
RV_free(value);
value = NULL;
} /* end RV_free_visited_link_hash_table_key() */

/*-------------------------------------------------------------------------
* Function: H5_rest_compare_string_keys
*
* Purpose: Comparison function to compare two string keys in an
* rv_hash_table_t. This function is mostly used when
* attempting to determine object uniqueness by some
* information from the server, such as an object ID.
*
* Return: Non-zero if the two string keys are equal/Zero if the two
* string keys are not equal
*
* Programmer: Jordan Henderson
* May, 2018
*/
static int
H5_rest_compare_string_keys(void *value1, void *value2)
{
const char *val1 = (const char *)value1;
const char *val2 = (const char *)value2;

return !strcmp(val1, val2);
} /* end H5_rest_compare_string_keys() */

/*-------------------------------------------------------------------------
* Function: H5_rest_cmp_links_by_creation_order_inc
*
Expand Down
Loading

0 comments on commit feafc77

Please sign in to comment.