summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5tools_utils.c
diff options
context:
space:
mode:
authorLarry Knox <lrknox@hdfgroup.org>2021-07-06 18:21:42 (GMT)
committerLarry Knox <lrknox@hdfgroup.org>2021-07-06 18:21:42 (GMT)
commit820695a78e3a277daea1bdcbb8ad54b8ee6650a5 (patch)
treefe7545305c0a77db3b9671e5a82fdffc4b2cc82e /tools/lib/h5tools_utils.c
parent9f13ecfa2e93840d1cc45dbf0bfcf8b955814931 (diff)
parent18bbd3f0a7f14adeebf8f342ed242ff191f9b7c5 (diff)
downloadhdf5-hdf5-1_12_1.zip
hdf5-hdf5-1_12_1.tar.gz
hdf5-hdf5-1_12_1.tar.bz2
Merge remote-tracking branch 'origin/hdf5_1_12_1' into 1.12/master forhdf5-1_12_1
HDF5 1.12.1 release.
Diffstat (limited to 'tools/lib/h5tools_utils.c')
-rw-r--r--tools/lib/h5tools_utils.c205
1 files changed, 131 insertions, 74 deletions
diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c
index 41ebded..6aec6b8 100644
--- a/tools/lib/h5tools_utils.c
+++ b/tools/lib/h5tools_utils.c
@@ -6,7 +6,7 @@
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -194,44 +194,48 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
if (sp == 1 && argv[opt_ind][0] == '-' && argv[opt_ind][1] == '-') {
/* long command line option */
- const char *arg = &argv[opt_ind][2];
- int i;
+ int i;
+ const char ch = '=';
+ char * arg = HDstrdup(&argv[opt_ind][2]);
+ size_t arg_len = 0;
+
+ opt_arg = strchr(&argv[opt_ind][2], ch);
+ arg_len = HDstrlen(&argv[opt_ind][2]);
+ if (opt_arg) {
+ arg_len -= HDstrlen(opt_arg);
+ opt_arg++; /* skip the equal sign */
+ }
+ arg[arg_len] = 0;
for (i = 0; l_opts && l_opts[i].name; i++) {
- size_t len = HDstrlen(l_opts[i].name);
-
- if (HDstrncmp(arg, l_opts[i].name, len) == 0) {
+ if (HDstrcmp(arg, l_opts[i].name) == 0) {
/* we've found a matching long command line flag */
opt_opt = l_opts[i].shortval;
if (l_opts[i].has_arg != no_arg) {
- if (arg[len] == '=') {
- opt_arg = &arg[len + 1];
- }
- else if (l_opts[i].has_arg != optional_arg) {
- if (opt_ind < (argc - 1))
- if (argv[opt_ind + 1][0] != '-')
- opt_arg = argv[++opt_ind];
- }
- else if (l_opts[i].has_arg == require_arg) {
- if (opt_err)
- HDfprintf(rawerrorstream, "%s: option required for \"--%s\" flag\n", argv[0],
- arg);
-
- opt_opt = '?';
+ if (opt_arg == NULL) {
+ if (l_opts[i].has_arg != optional_arg) {
+ if (opt_ind < (argc - 1))
+ if (argv[opt_ind + 1][0] != '-')
+ opt_arg = argv[++opt_ind];
+ }
+ else if (l_opts[i].has_arg == require_arg) {
+ if (opt_err)
+ HDfprintf(rawerrorstream, "%s: option required for \"--%s\" flag\n", argv[0],
+ arg);
+
+ opt_opt = '?';
+ }
}
- else
- opt_arg = NULL;
}
else {
- if (arg[len] == '=') {
+ if (opt_arg) {
if (opt_err)
HDfprintf(rawerrorstream, "%s: no option required for \"%s\" flag\n", argv[0],
arg);
opt_opt = '?';
}
- opt_arg = NULL;
}
break;
}
@@ -247,6 +251,8 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
opt_ind++;
sp = 1;
+
+ HDfree(arg);
}
else {
register char *cp; /* pointer into current token */
@@ -378,8 +384,6 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
* Programmer: Jacob Smith
* 2017-11-10
*
- * Changes: None.
- *
*****************************************************************************
*/
herr_t
@@ -627,16 +631,16 @@ static void
dump_table(hid_t fid, char *tablename, table_t *table)
{
unsigned u;
- char * obj_addr_str = NULL;
+ char * obj_tok_str = NULL;
PRINTSTREAM(rawoutstream, "%s: # of entries = %d\n", tablename, table->nobjs);
for (u = 0; u < table->nobjs; u++) {
- H5VLconnector_token_to_str(fid, table->objs[u].obj_token, &obj_addr_str);
+ H5VLconnector_token_to_str(fid, table->objs[u].obj_token, &obj_tok_str);
- PRINTSTREAM(rawoutstream, "%s %s %d %d\n", obj_addr_str, table->objs[u].objname,
+ PRINTSTREAM(rawoutstream, "%s %s %d %d\n", obj_tok_str, table->objs[u].objname,
table->objs[u].displayed, table->objs[u].recorded);
- H5VLfree_token_str(fid, obj_addr_str);
+ H5VLfree_token_str(fid, obj_tok_str);
}
}
@@ -1052,6 +1056,53 @@ done:
return ret_value;
}
+#ifdef H5_HAVE_ROS3_VFD
+/*----------------------------------------------------------------------------
+ *
+ * Function: h5tools_parse_ros3_fapl_tuple
+ *
+ * Purpose: A convenience function that parses a string containing a tuple
+ * of S3 VFD credential information and then passes the result to
+ * `h5tools_populate_ros3_fapl()` in order to setup a valid
+ * configuration for the S3 VFD.
+ *
+ * Return: SUCCEED/FAIL
+ *
+ *----------------------------------------------------------------------------
+ */
+herr_t
+h5tools_parse_ros3_fapl_tuple(const char *tuple_str, int delim, H5FD_ros3_fapl_t *fapl_config_out)
+{
+ const char *ccred[3];
+ unsigned nelems = 0;
+ char * s3cred_src = NULL;
+ char ** s3cred = NULL;
+ herr_t ret_value = SUCCEED;
+
+ /* Attempt to parse S3 credentials tuple */
+ if (parse_tuple(tuple_str, delim, &s3cred_src, &nelems, &s3cred) < 0)
+ H5TOOLS_GOTO_ERROR(FAIL, "failed to parse S3 VFD info tuple");
+
+ /* Sanity-check tuple count */
+ if (nelems != 3)
+ H5TOOLS_GOTO_ERROR(FAIL, "invalid S3 VFD credentials");
+
+ ccred[0] = (const char *)s3cred[0];
+ ccred[1] = (const char *)s3cred[1];
+ ccred[2] = (const char *)s3cred[2];
+
+ if (0 == h5tools_populate_ros3_fapl(fapl_config_out, ccred))
+ H5TOOLS_GOTO_ERROR(FAIL, "failed to populate S3 VFD FAPL config");
+
+done:
+ if (s3cred)
+ HDfree(s3cred);
+ if (s3cred_src)
+ HDfree(s3cred_src);
+
+ return ret_value;
+}
+
/*----------------------------------------------------------------------------
*
* Function: h5tools_populate_ros3_fapl()
@@ -1114,7 +1165,6 @@ done:
*
*----------------------------------------------------------------------------
*/
-#ifdef H5_HAVE_ROS3_VFD
int
h5tools_populate_ros3_fapl(H5FD_ros3_fapl_t *fa, const char **values)
{
@@ -1224,63 +1274,70 @@ h5tools_populate_ros3_fapl(H5FD_ros3_fapl_t *fa, const char **values)
done:
return ret_value;
-
} /* h5tools_populate_ros3_fapl */
#endif /* H5_HAVE_ROS3_VFD */
-/*-----------------------------------------------------------------------------
- *
- * Function: h5tools_set_configured_fapl
- *
- * Purpose: prepare fapl_id with the given property list, according to
- * VFD prototype.
+#ifdef H5_HAVE_LIBHDFS
+/*----------------------------------------------------------------------------
*
- * Return: 0 on failure, 1 on success
+ * Function: h5tools_parse_hdfs_fapl_tuple
*
- * Programmer: Jacob Smith
- * 2018-05-21
+ * Purpose: A convenience function that parses a string containing a tuple
+ * of HDFS VFD configuration information.
*
- * Changes: None.
+ * Return: SUCCEED/FAIL
*
- *-----------------------------------------------------------------------------
+ *----------------------------------------------------------------------------
*/
-int
-h5tools_set_configured_fapl(hid_t fapl_id, const char vfd_name[], void *fapl_t_ptr)
+herr_t
+h5tools_parse_hdfs_fapl_tuple(const char *tuple_str, int delim, H5FD_hdfs_fapl_t *fapl_config_out)
{
- int ret_value = 1;
-
- if (fapl_id < 0) {
- return 0;
+ unsigned long k = 0;
+ unsigned nelems = 0;
+ char * props_src = NULL;
+ char ** props = NULL;
+ herr_t ret_value = SUCCEED;
+
+ /* Attempt to parse HDFS configuration tuple */
+ if (parse_tuple(tuple_str, delim, &props_src, &nelems, &props) < 0)
+ H5TOOLS_GOTO_ERROR(FAIL, "failed to parse HDFS VFD configuration tuple");
+
+ /* Sanity-check tuple count */
+ if (nelems != 5)
+ H5TOOLS_GOTO_ERROR(FAIL, "invalid HDFS VFD configuration");
+
+ /* Populate fapl configuration structure with given properties.
+ * WARNING: No error-checking is done on length of input strings...
+ * Silent overflow is possible, albeit unlikely.
+ */
+ if (HDstrncmp(props[0], "", 1)) {
+ HDstrncpy(fapl_config_out->namenode_name, (const char *)props[0], HDstrlen(props[0]));
}
-
- if (!strcmp("", vfd_name)) {
- goto done;
-
-#ifdef H5_HAVE_ROS3_VFD
+ if (HDstrncmp(props[1], "", 1)) {
+ k = strtoul((const char *)props[1], NULL, 0);
+ if (errno == ERANGE)
+ H5TOOLS_GOTO_ERROR(FAIL, "supposed port number wasn't");
+ fapl_config_out->namenode_port = (int32_t)k;
}
- else if (!strcmp("ros3", vfd_name)) {
- if ((fapl_id == H5P_DEFAULT) || (fapl_t_ptr == NULL) ||
- (FAIL == H5Pset_fapl_ros3(fapl_id, (H5FD_ros3_fapl_t *)fapl_t_ptr))) {
- ret_value = 0;
- goto done;
- }
-#endif /* H5_HAVE_ROS3_VFD */
-
-#ifdef H5_HAVE_LIBHDFS
+ if (HDstrncmp(props[2], "", 1)) {
+ HDstrncpy(fapl_config_out->kerberos_ticket_cache, (const char *)props[2], HDstrlen(props[2]));
}
- else if (!strcmp("hdfs", vfd_name)) {
- if ((fapl_id == H5P_DEFAULT) || (fapl_t_ptr == NULL) ||
- (FAIL == H5Pset_fapl_hdfs(fapl_id, (H5FD_hdfs_fapl_t *)fapl_t_ptr))) {
- ret_value = 0;
- goto done;
- }
-#endif /* H5_HAVE_LIBHDFS */
+ if (HDstrncmp(props[3], "", 1)) {
+ HDstrncpy(fapl_config_out->user_name, (const char *)props[3], HDstrlen(props[3]));
}
- else {
- ret_value = 0; /* unrecognized fapl type "name" */
+ if (HDstrncmp(props[4], "", 1)) {
+ k = HDstrtoul((const char *)props[4], NULL, 0);
+ if (errno == ERANGE)
+ H5TOOLS_GOTO_ERROR(FAIL, "supposed buffersize number wasn't");
+ fapl_config_out->stream_buffer_size = (int32_t)k;
}
done:
- return ret_value;
+ if (props)
+ HDfree(props);
+ if (props_src)
+ HDfree(props_src);
-} /* h5tools_set_configured_fapl() */
+ return ret_value;
+}
+#endif /* H5_HAVE_LIBHDFS */