summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/H5FDhdfs.c1263
-rw-r--r--src/H5FDhdfs.h8
-rw-r--r--src/H5FDros3.c749
-rw-r--r--src/H5FDs3comms.c1715
4 files changed, 1310 insertions, 2425 deletions
diff --git a/src/H5FDhdfs.c b/src/H5FDhdfs.c
index 2eb53d6..29d032e 100644
--- a/src/H5FDhdfs.c
+++ b/src/H5FDhdfs.c
@@ -20,9 +20,6 @@
* File System (HDFS).
*/
-/* This source code file is part of the H5FD driver module */
-#include "H5FDdrvr_module.h"
-
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5FDprivate.h" /* File drivers */
@@ -32,8 +29,12 @@
#include "H5MMprivate.h" /* Memory management */
#ifdef H5_HAVE_LIBHDFS
+
+/* This source code file is part of the H5FD driver module */
+#include "H5FDdrvr_module.h"
+
+/* HDFS routines */
#include "hdfs.h"
-#endif
/* toggle function call prints: 1 turns on */
#define HDFS_DEBUG 0
@@ -128,7 +129,6 @@ typedef struct {
#endif /* HDFS_STATS */
-#ifdef H5_HAVE_LIBHDFS
/* "unique" identifier for `hdfs_t` structures.
* Randomly generated by unweighted dice rolls.
@@ -144,7 +144,7 @@ typedef struct {
*
* Contain/retain information associated with a file hosted on Hadoop
* Distributed File System (HDFS). Instantiated and populated via
- * `H5FD_hdfs_handle_open()` and cleaned up via `H5FD_hdfs_handle_close()`.
+ * `H5FD__hdfs_handle_open()` and cleaned up via `H5FD__hdfs_handle_close()`.
*
* `magic` (unisgned long)
*
@@ -181,192 +181,6 @@ typedef struct {
} hdfs_t;
-/*--------------------------------------------------------------------------
- * Function: H5FD_hdfs_handle_open
- *
- * Purpose: Create a HDFS file handle, 'opening' the target file.
- *
- * Return: Success: Pointer to HDFS container/handle of opened file.
- * Failure: NULL
- *
- * Programmer: Gerd Herber
- * May 2018
- *
- *--------------------------------------------------------------------------
- */
-static hdfs_t *
-H5FD_hdfs_handle_open(
- const char *path,
- const char *namenode_name,
- const int32_t namenode_port,
- const char *user_name,
- const char *kerberos_ticket_cache,
- const int32_t stream_buffer_size)
-{
- struct hdfsBuilder *builder = NULL;
- hdfs_t *handle = NULL;
- hdfs_t *ret_value = NULL;
-
- FUNC_ENTER_NOAPI_NOINIT
-
-#if HDFS_DEBUG
- HDfprintf(stdout, "called H5FD_hdfs_handle_open.\n");
-#endif
-
- if (path == NULL || path[0] == '\0') {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "path cannot be null.\n")
- }
- if (namenode_name == NULL /* || namenode_name[0] == '\0' */ ) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "namenode name cannot be null.\n")
- }
- if (namenode_port < 0 || namenode_port > 65535) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "namenode port must be non-negative and <= 65535.\n")
- }
- if (stream_buffer_size < 0) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "buffer size must non-negative.\n")
- }
-
- handle = (hdfs_t *)H5MM_malloc(sizeof(hdfs_t));
- if (handle == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, NULL,
- "could not malloc space for handle.\n")
- }
-
- handle->magic = (unsigned long)HDFS_HDFST_MAGIC;
- handle->filesystem = NULL; /* TODO: not a pointer; NULL may cause bug */
- handle->fileinfo = NULL;
- handle->file = NULL; /* TODO: not a pointer; NULL may cause bug */
-
- builder = hdfsNewBuilder();
- if (!builder) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "(hdfs) failed to create builder")
- }
- hdfsBuilderSetNameNode(builder, namenode_name);
- hdfsBuilderSetNameNodePort(builder, (tPort)namenode_port);
- if (user_name != NULL && user_name[0] != '\0') {
- hdfsBuilderSetUserName(builder, user_name);
- }
- if (kerberos_ticket_cache != NULL && kerberos_ticket_cache[0] != '\0') {
- hdfsBuilderSetKerbTicketCachePath(builder, kerberos_ticket_cache);
- }
- /* Call to `hdfsBuilderConnect` releases builder, regardless of success. */
- handle->filesystem = hdfsBuilderConnect(builder);
- if (!handle->filesystem) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "(hdfs) could not connect to default namenode")
- }
- handle->fileinfo = hdfsGetPathInfo(handle->filesystem, path);
- if (!handle->fileinfo) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "hdfsGetPathInfo failed")
- }
- handle->file = hdfsOpenFile(
- handle->filesystem,
- path,
- O_RDONLY,
- stream_buffer_size,
- 0,
- 0);
- if (!handle->file) {
- HGOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, NULL,
- "(hdfs) could not open")
- }
-
- ret_value = handle;
-
-done:
- if (ret_value == NULL && handle != NULL) {
- /* error; clean up */
- HDassert(handle->magic == HDFS_HDFST_MAGIC);
- handle->magic++;
- if (handle->file != NULL) {
- if (FAIL == (hdfsCloseFile(handle->filesystem, handle->file))) {
- HDONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, NULL,
- "unable to close hdfs file handle")
- }
- }
- if (handle->fileinfo != NULL) {
- hdfsFreeFileInfo(handle->fileinfo, 1);
- }
- if (handle->filesystem != NULL) {
- if (FAIL == (hdfsDisconnect(handle->filesystem))) {
- HDONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, NULL,
- "unable to disconnect from hdfs")
- }
- }
- H5MM_xfree(handle);
- }
-
- FUNC_LEAVE_NOAPI(ret_value)
-
-} /* H5FD_hdfs_handle_open() */
-
-
-/*--------------------------------------------------------------------------
- * Function: H5FD_hdfs_handle_close
- *
- * Purpose: 'Close' an HDFS file container/handle, releasing underlying
- * resources.
- *
- * Return: Success: `SUCCEED` (0)
- * Failure: `FAIL` (-1)
- *
- * Programmer: Gerd Herber
- * May 2018
- *
- *--------------------------------------------------------------------------
- */
-static herr_t
-H5FD_hdfs_handle_close(hdfs_t *handle)
-{
- herr_t ret_value = SUCCEED;
-
- FUNC_ENTER_NOAPI_NOINIT
-
-#if HDFS_DEBUG
- HDfprintf(stdout, "called H5FD_hdfs_close.\n");
-#endif
-
- if (handle == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle cannot be null.\n")
- }
- if (handle->magic != HDFS_HDFST_MAGIC) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle has invalid magic.\n")
- }
-
- handle->magic++;
- if (handle->file != NULL) {
- if (FAIL == (hdfsCloseFile(handle->filesystem, handle->file))) {
- HDONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL,
- "unable to close hdfs file handle")
- }
- }
- if (handle->fileinfo != NULL) {
- hdfsFreeFileInfo(handle->fileinfo, 1);
- }
- if (handle->filesystem != NULL) {
- if (FAIL == (hdfsDisconnect(handle->filesystem))) {
- HDONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL,
- "unable to disconnect hdfs file system")
- }
- }
-
- H5MM_xfree(handle);
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-
-} /* H5FD_hdfs_close() */
-
-#endif /* H5_HAVE_LIBHDFS */
-
/***************************************************************************
*
@@ -430,9 +244,7 @@ typedef struct H5FD_hdfs_t {
H5FD_t pub;
H5FD_hdfs_fapl_t fa;
haddr_t eoa;
-#ifdef H5_HAVE_LIBHDFS
hdfs_t *hdfs_handle;
-#endif
#if HDFS_STATS
hdfs_statsbin meta[HDFS_STATS_BIN_COUNT + 1];
hdfs_statsbin raw[HDFS_STATS_BIN_COUNT + 1];
@@ -449,75 +261,72 @@ typedef struct H5FD_hdfs_t {
* Only included if HDFS code should compile.
*
*/
-#define MAXADDR (((haddr_t)1<<(8*sizeof(HDoff_t)-1))-1)
-#ifdef H5_HAVE_LIBHDFS
+#define MAXADDR (((haddr_t)1 << (8 * sizeof(HDoff_t) - 1)) - 1)
#define ADDR_OVERFLOW(A) (HADDR_UNDEF==(A) || ((A) & ~(haddr_t)MAXADDR))
-#endif /* H5_HAVE_LIBHDFS */
/* Prototypes */
-static herr_t H5FD_hdfs_term(void);
-static void *H5FD_hdfs_fapl_get(H5FD_t *_file);
-static void *H5FD_hdfs_fapl_copy(const void *_old_fa);
-static herr_t H5FD_hdfs_fapl_free(void *_fa);
-static H5FD_t *H5FD_hdfs_open(const char *name, unsigned flags, hid_t fapl_id,
+static herr_t H5FD__hdfs_term(void);
+static void *H5FD__hdfs_fapl_get(H5FD_t *_file);
+static void *H5FD__hdfs_fapl_copy(const void *_old_fa);
+static herr_t H5FD__hdfs_fapl_free(void *_fa);
+static H5FD_t *H5FD__hdfs_open(const char *name, unsigned flags, hid_t fapl_id,
haddr_t maxaddr);
-static herr_t H5FD_hdfs_close(H5FD_t *_file);
-static int H5FD_hdfs_cmp(const H5FD_t *_f1, const H5FD_t *_f2);
-static herr_t H5FD_hdfs_query(const H5FD_t *_f1, unsigned long *flags);
-static haddr_t H5FD_hdfs_get_eoa(const H5FD_t *_file, H5FD_mem_t type);
-static herr_t H5FD_hdfs_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t addr);
-static haddr_t H5FD_hdfs_get_eof(const H5FD_t *_file, H5FD_mem_t type);
-static herr_t H5FD_hdfs_get_handle(H5FD_t *_file, hid_t fapl,
+static herr_t H5FD__hdfs_close(H5FD_t *_file);
+static int H5FD__hdfs_cmp(const H5FD_t *_f1, const H5FD_t *_f2);
+static herr_t H5FD__hdfs_query(const H5FD_t *_f1, unsigned long *flags);
+static haddr_t H5FD__hdfs_get_eoa(const H5FD_t *_file, H5FD_mem_t type);
+static herr_t H5FD__hdfs_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t addr);
+static haddr_t H5FD__hdfs_get_eof(const H5FD_t *_file, H5FD_mem_t type);
+static herr_t H5FD__hdfs_get_handle(H5FD_t *_file, hid_t fapl,
void** file_handle);
-static herr_t H5FD_hdfs_read(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id,
+static herr_t H5FD__hdfs_read(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id,
haddr_t addr, size_t size, void *buf);
-static herr_t H5FD_hdfs_write(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id,
+static herr_t H5FD__hdfs_write(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id,
haddr_t addr, size_t size, const void *buf);
-static herr_t H5FD_hdfs_truncate(H5FD_t *_file, hid_t dxpl_id,
+static herr_t H5FD__hdfs_truncate(H5FD_t *_file, hid_t dxpl_id,
hbool_t closing);
-static herr_t H5FD_hdfs_lock(H5FD_t *_file, hbool_t rw);
-static herr_t H5FD_hdfs_unlock(H5FD_t *_file);
-static herr_t H5FD_hdfs_validate_config(const H5FD_hdfs_fapl_t * fa);
+static herr_t H5FD__hdfs_lock(H5FD_t *_file, hbool_t rw);
+static herr_t H5FD__hdfs_unlock(H5FD_t *_file);
+
+static herr_t H5FD__hdfs_validate_config(const H5FD_hdfs_fapl_t * fa);
static const H5FD_class_t H5FD_hdfs_g = {
"hdfs", /* name */
MAXADDR, /* maxaddr */
H5F_CLOSE_WEAK, /* fc_degree */
- H5FD_hdfs_term, /* terminate */
+ H5FD__hdfs_term, /* terminate */
NULL, /* sb_size */
NULL, /* sb_encode */
NULL, /* sb_decode */
sizeof(H5FD_hdfs_fapl_t), /* fapl_size */
- H5FD_hdfs_fapl_get, /* fapl_get */
- H5FD_hdfs_fapl_copy, /* fapl_copy */
- H5FD_hdfs_fapl_free, /* fapl_free */
+ H5FD__hdfs_fapl_get, /* fapl_get */
+ H5FD__hdfs_fapl_copy, /* fapl_copy */
+ H5FD__hdfs_fapl_free, /* fapl_free */
0, /* dxpl_size */
NULL, /* dxpl_copy */
NULL, /* dxpl_free */
- H5FD_hdfs_open, /* open */
- H5FD_hdfs_close, /* close */
- H5FD_hdfs_cmp, /* cmp */
- H5FD_hdfs_query, /* query */
+ H5FD__hdfs_open, /* open */
+ H5FD__hdfs_close, /* close */
+ H5FD__hdfs_cmp, /* cmp */
+ H5FD__hdfs_query, /* query */
NULL, /* get_type_map */
NULL, /* alloc */
NULL, /* free */
- H5FD_hdfs_get_eoa, /* get_eoa */
- H5FD_hdfs_set_eoa, /* set_eoa */
- H5FD_hdfs_get_eof, /* get_eof */
- H5FD_hdfs_get_handle, /* get_handle */
- H5FD_hdfs_read, /* read */
- H5FD_hdfs_write, /* write */
+ H5FD__hdfs_get_eoa, /* get_eoa */
+ H5FD__hdfs_set_eoa, /* set_eoa */
+ H5FD__hdfs_get_eof, /* get_eof */
+ H5FD__hdfs_get_handle, /* get_handle */
+ H5FD__hdfs_read, /* read */
+ H5FD__hdfs_write, /* write */
NULL, /* flush */
- H5FD_hdfs_truncate, /* truncate */
- H5FD_hdfs_lock, /* lock */
- H5FD_hdfs_unlock, /* unlock */
+ H5FD__hdfs_truncate, /* truncate */
+ H5FD__hdfs_lock, /* lock */
+ H5FD__hdfs_unlock, /* unlock */
H5FD_FLMAP_DICHOTOMY /* fl_map */
};
-#ifdef H5_HAVE_LIBHDFS
/* Declare a free list to manage the H5FD_hdfs_t struct */
H5FL_DEFINE_STATIC(H5FD_hdfs_t);
-#endif /* H5_HAVE_LIBHDFS */
/*-------------------------------------------------------------------------
@@ -536,10 +345,8 @@ H5FD__init_package(void)
FUNC_ENTER_STATIC
- if (H5FD_hdfs_init() < 0) {
- HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL,
- "unable to initialize hdfs VFD")
- }
+ if(H5FD_hdfs_init() < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize hdfs VFD")
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -563,29 +370,28 @@ hid_t
H5FD_hdfs_init(void)
{
hid_t ret_value = H5I_INVALID_HID; /* Return value */
+#if HDFS_STATS
unsigned int bin_i;
+#endif
FUNC_ENTER_NOAPI(FAIL)
#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_init() called.\n");
+ HDfprintf(stdout, "called %s.\n", FUNC);
#endif
- if (H5I_VFL != H5I_get_type(H5FD_HDFS_g)) {
- H5FD_HDFS_g = H5FD_register(
- &H5FD_hdfs_g,
- sizeof(H5FD_class_t),
- FALSE);
- }
+ if(H5I_VFL != H5I_get_type(H5FD_HDFS_g))
+ H5FD_HDFS_g = H5FD_register(&H5FD_hdfs_g, sizeof(H5FD_class_t), FALSE);
#if HDFS_STATS
/* pre-compute statsbin boundaries
*/
- for (bin_i = 0; bin_i < HDFS_STATS_BIN_COUNT; bin_i++) {
+ for(bin_i = 0; bin_i < HDFS_STATS_BIN_COUNT; bin_i++) {
unsigned long long value = 0;
+
HDFS_STATS_POW(bin_i, &value)
hdfs_stats_boundaries[bin_i] = value;
- }
+ } /* end for */
#endif
ret_value = H5FD_HDFS_g;
@@ -596,7 +402,7 @@ done:
/*---------------------------------------------------------------------------
- * Function: H5FD_hdfs_term
+ * Function: H5FD__hdfs_term
*
* Purpose: Shut down the VFD
*
@@ -608,73 +414,159 @@ done:
*---------------------------------------------------------------------------
*/
static herr_t
-H5FD_hdfs_term(void)
+H5FD__hdfs_term(void)
{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_term() called.\n");
+ HDfprintf(stdout, "called %s.\n", FUNC);
#endif
/* Reset VFL ID */
H5FD_HDFS_g = 0;
FUNC_LEAVE_NOAPI(SUCCEED)
-} /* end H5FD_hdfs_term() */
+} /* end H5FD__hdfs_term() */
-/*-------------------------------------------------------------------------
- * Function: H5Pset_fapl_hdfs
+/*--------------------------------------------------------------------------
+ * Function: H5FD__hdfs_handle_open
*
- * Purpose: Modify the file access property list to use the H5FD_HDFS
- * driver defined in this source file. All driver specfic
- * properties are passed in as a pointer to a suitably
- * initialized instance of H5FD_hdfs_fapl_t
+ * Purpose: Create a HDFS file handle, 'opening' the target file.
*
- * Return: SUCCEED/FAIL
+ * Return: Success: Pointer to HDFS container/handle of opened file.
+ * Failure: NULL
*
- * Programmer: John Mainzer
- * 9/10/17
+ * Programmer: Gerd Herber
+ * May 2018
*
- *-------------------------------------------------------------------------
+ *--------------------------------------------------------------------------
*/
-herr_t
-H5Pset_fapl_hdfs(hid_t fapl_id,
- H5FD_hdfs_fapl_t *fa)
+static hdfs_t *
+H5FD__hdfs_handle_open(const char *path, const char *namenode_name,
+ const int32_t namenode_port, const char *user_name,
+ const char *kerberos_ticket_cache, const int32_t stream_buffer_size)
{
- H5P_genplist_t *plist = NULL; /* Property list pointer */
- herr_t ret_value = FAIL;
-
- FUNC_ENTER_API(FAIL)
- H5TRACE2("e", "i*x", fapl_id, fa);
+ struct hdfsBuilder *builder = NULL;
+ hdfs_t *handle = NULL;
+ hdfs_t *ret_value = NULL;
- HDassert(fa != NULL);
+ FUNC_ENTER_STATIC
#if HDFS_DEBUG
- HDfprintf(stdout, "H5Pset_fapl_hdfs() called.\n");
+ HDfprintf(stdout, "called %s.\n", FUNC);
#endif
- plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS);
- if (plist == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, \
- "not a file access property list")
- }
+ if(path == NULL || path[0] == '\0')
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "path cannot be null")
+ if(namenode_name == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "namenode name cannot be null")
+ if(namenode_port < 0 || namenode_port > 65535)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "namenode port must be non-negative and <= 65535")
+ if(stream_buffer_size < 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "buffer size must non-negative")
- if (FAIL == H5FD_hdfs_validate_config(fa)) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "invalid hdfs config")
- }
+ handle = (hdfs_t *)H5MM_malloc(sizeof(hdfs_t));
+ if(handle == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, NULL, "could not malloc space for handle")
- ret_value = H5P_set_driver(plist, H5FD_HDFS, (void *)fa);
+ handle->magic = (unsigned long)HDFS_HDFST_MAGIC;
+ handle->filesystem = NULL; /* TODO: not a pointer; NULL may cause bug */
+ handle->fileinfo = NULL;
+ handle->file = NULL; /* TODO: not a pointer; NULL may cause bug */
+
+ builder = hdfsNewBuilder();
+ if(!builder)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "(hdfs) failed to create builder")
+ hdfsBuilderSetNameNode(builder, namenode_name);
+ hdfsBuilderSetNameNodePort(builder, (tPort)namenode_port);
+ if(user_name != NULL && user_name[0] != '\0')
+ hdfsBuilderSetUserName(builder, user_name);
+ if(kerberos_ticket_cache != NULL && kerberos_ticket_cache[0] != '\0')
+ hdfsBuilderSetKerbTicketCachePath(builder, kerberos_ticket_cache);
+
+ /* Call to `hdfsBuilderConnect` releases builder, regardless of success. */
+ handle->filesystem = hdfsBuilderConnect(builder);
+ if(!handle->filesystem)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "(hdfs) could not connect to default namenode")
+ handle->fileinfo = hdfsGetPathInfo(handle->filesystem, path);
+ if(!handle->fileinfo)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "hdfsGetPathInfo failed")
+ handle->file = hdfsOpenFile(handle->filesystem, path, O_RDONLY, stream_buffer_size, 0, 0);
+ if(!handle->file)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, NULL, "(hdfs) could not open")
+
+ ret_value = handle;
done:
- FUNC_LEAVE_API(ret_value)
+ if(ret_value == NULL && handle != NULL) {
+ /* error; clean up */
+ HDassert(handle->magic == HDFS_HDFST_MAGIC);
+ handle->magic++;
+ if(handle->file != NULL)
+ if(FAIL == (hdfsCloseFile(handle->filesystem, handle->file)))
+ HDONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, NULL, "unable to close hdfs file handle")
+ if(handle->fileinfo != NULL)
+ hdfsFreeFileInfo(handle->fileinfo, 1);
+ if(handle->filesystem != NULL)
+ if(FAIL == (hdfsDisconnect(handle->filesystem)))
+ HDONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, NULL, "unable to disconnect from hdfs")
+ H5MM_xfree(handle);
+ }
-} /* H5Pset_fapl_hdfs() */
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* H5FD__hdfs_handle_open() */
+
+
+/*--------------------------------------------------------------------------
+ * Function: H5FD__hdfs_handle_close
+ *
+ * Purpose: 'Close' an HDFS file container/handle, releasing underlying
+ * resources.
+ *
+ * Return: Success: `SUCCEED` (0)
+ * Failure: `FAIL` (-1)
+ *
+ * Programmer: Gerd Herber
+ * May 2018
+ *
+ *--------------------------------------------------------------------------
+ */
+static herr_t
+H5FD__hdfs_handle_close(hdfs_t *handle)
+{
+ herr_t ret_value = SUCCEED;
+
+ FUNC_ENTER_STATIC
+
+#if HDFS_DEBUG
+ HDfprintf(stdout, "called %s.\n", FUNC);
+#endif
+
+ if(handle == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle cannot be null")
+ if(handle->magic != HDFS_HDFST_MAGIC)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle has invalid magic")
+
+ handle->magic++;
+ if(handle->file != NULL)
+ if(FAIL == (hdfsCloseFile(handle->filesystem, handle->file)))
+ HDONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL, "unable to close hdfs file handle")
+ if(handle->fileinfo != NULL)
+ hdfsFreeFileInfo(handle->fileinfo, 1);
+ if(handle->filesystem != NULL)
+ if(FAIL == (hdfsDisconnect(handle->filesystem)))
+ HDONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL, "unable to disconnect hdfs file system")
+
+ H5MM_xfree(handle);
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* H5FD__hdfs_handle_close() */
/*-------------------------------------------------------------------------
- * Function: H5FD_hdfs_validate_config()
+ * Function: H5FD__hdfs_validate_config()
*
* Purpose: Test to see if the supplied instance of H5FD_hdfs_fapl_t
* contains internally consistant data. Return SUCCEED if so,
@@ -694,32 +586,67 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_hdfs_validate_config(const H5FD_hdfs_fapl_t * fa)
+H5FD__hdfs_validate_config(const H5FD_hdfs_fapl_t * fa)
{
herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
HDassert(fa != NULL);
- if ( fa->version != H5FD__CURR_HDFS_FAPL_T_VERSION ) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "Unknown H5FD_hdfs_fapl_t version");
- }
-
- if ( fa->namenode_port > 65535 ) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "Invalid namenode port number");
- }
- if ( fa->namenode_port < 0 ) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "Invalid namenode port number");
- }
+ if(fa->version != H5FD__CURR_HDFS_FAPL_T_VERSION)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Unknown H5FD_hdfs_fapl_t version");
+ if(fa->namenode_port > 65535)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Invalid namenode port number");
+ if(fa->namenode_port < 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Invalid namenode port number");
done:
FUNC_LEAVE_NOAPI(ret_value)
+} /* H5FD__hdfs_validate_config() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5Pset_fapl_hdfs
+ *
+ * Purpose: Modify the file access property list to use the H5FD_HDFS
+ * driver defined in this source file. All driver specfic
+ * properties are passed in as a pointer to a suitably
+ * initialized instance of H5FD_hdfs_fapl_t
+ *
+ * Return: SUCCEED/FAIL
+ *
+ * Programmer: John Mainzer
+ * 9/10/17
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5Pset_fapl_hdfs(hid_t fapl_id, H5FD_hdfs_fapl_t *fa)
+{
+ H5P_genplist_t *plist = NULL; /* Property list pointer */
+ herr_t ret_value = FAIL;
+
+ FUNC_ENTER_API(FAIL)
+ H5TRACE2("e", "i*x", fapl_id, fa);
+
+ HDassert(fa != NULL);
+
+#if HDFS_DEBUG
+ HDfprintf(stdout, "called %s.\n", FUNC);
+#endif
+
+ plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS);
+ if(plist == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list")
+ if(FAIL == H5FD__hdfs_validate_config(fa))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid hdfs config")
-} /* H5FD_hdfs_validate_config() */
+ ret_value = H5P_set_driver(plist, H5FD_HDFS, (void *)fa);
+
+done:
+ FUNC_LEAVE_API(ret_value)
+} /* H5Pset_fapl_hdfs() */
/*-------------------------------------------------------------------------
@@ -738,8 +665,7 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5Pget_fapl_hdfs(hid_t fapl_id,
- H5FD_hdfs_fapl_t *fa_out)
+H5Pget_fapl_hdfs(hid_t fapl_id, H5FD_hdfs_fapl_t *fa_out)
{
const H5FD_hdfs_fapl_t *fa = NULL;
H5P_genplist_t *plist = NULL;
@@ -749,28 +675,20 @@ H5Pget_fapl_hdfs(hid_t fapl_id,
H5TRACE2("e", "i*x", fapl_id, fa_out);
#if HDFS_DEBUG
- HDfprintf(stdout, "H5Pget_fapl_hdfs() called.\n");
+ HDfprintf(stdout, "called %s.\n", FUNC);
#endif
- if (fa_out == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "fa_out is NULL")
- }
+ if(fa_out == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "fa_out is NULL")
plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS);
- if (plist == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL,
- "not a file access list")
- }
- if (H5FD_HDFS != H5P_peek_driver(plist)) {
- HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL,
- "incorrect VFL driver")
- }
+ if(plist == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access list")
+ if(H5FD_HDFS != H5P_peek_driver(plist))
+ HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "incorrect VFL driver")
fa = (const H5FD_hdfs_fapl_t *)H5P_peek_driver_info(plist);
- if (fa == NULL) {
- HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL,
- "bad VFL driver info")
- }
+ if(fa == NULL)
+ HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "bad VFL driver info")
/* Copy the hdfs fapl data out */
HDmemcpy(fa_out, fa, sizeof(H5FD_hdfs_fapl_t));
@@ -781,7 +699,7 @@ done:
/*-------------------------------------------------------------------------
- * Function: H5FD_hdfs_fapl_get
+ * Function: H5FD__hdfs_fapl_get
*
* Purpose: Gets a file access property list which could be used to
* create an identical file.
@@ -796,19 +714,17 @@ done:
*-------------------------------------------------------------------------
*/
static void *
-H5FD_hdfs_fapl_get(H5FD_t *_file)
+H5FD__hdfs_fapl_get(H5FD_t *_file)
{
H5FD_hdfs_t *file = (H5FD_hdfs_t*)_file;
H5FD_hdfs_fapl_t *fa = NULL;
void *ret_value = NULL;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
fa = (H5FD_hdfs_fapl_t *)H5MM_calloc(sizeof(H5FD_hdfs_fapl_t));
- if (fa == NULL) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
- "memory allocation failed")
- }
+ if(fa == NULL)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "memory allocation failed")
/* Copy the fields of the structure */
HDmemcpy(fa, &(file->fa), sizeof(H5FD_hdfs_fapl_t));
@@ -816,17 +732,15 @@ H5FD_hdfs_fapl_get(H5FD_t *_file)
ret_value = fa;
done:
- if (ret_value == NULL && fa != NULL) {
+ if(ret_value == NULL && fa != NULL)
H5MM_xfree(fa); /* clean up on error */
- }
FUNC_LEAVE_NOAPI(ret_value)
-
-} /* H5FD_hdfs_fapl_get() */
+} /* H5FD__hdfs_fapl_get() */
/*-------------------------------------------------------------------------
- * Function: H5FD_hdfs_fapl_copy
+ * Function: H5FD__hdfs_fapl_copy
*
* Purpose: Copies the hdfs-specific file access properties.
*
@@ -840,35 +754,31 @@ done:
*-------------------------------------------------------------------------
*/
static void *
-H5FD_hdfs_fapl_copy(const void *_old_fa)
+H5FD__hdfs_fapl_copy(const void *_old_fa)
{
const H5FD_hdfs_fapl_t *old_fa = (const H5FD_hdfs_fapl_t*)_old_fa;
H5FD_hdfs_fapl_t *new_fa = NULL;
void *ret_value = NULL;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
new_fa = (H5FD_hdfs_fapl_t *)H5MM_malloc(sizeof(H5FD_hdfs_fapl_t));
- if (new_fa == NULL) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
- "memory allocation failed")
- }
+ if(new_fa == NULL)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "memory allocation failed")
HDmemcpy(new_fa, old_fa, sizeof(H5FD_hdfs_fapl_t));
ret_value = new_fa;
done:
- if (ret_value == NULL && new_fa != NULL) {
+ if(ret_value == NULL && new_fa != NULL)
H5MM_xfree(new_fa); /* clean up on error */
- }
FUNC_LEAVE_NOAPI(ret_value)
-
-} /* H5FD_hdfs_fapl_copy() */
+} /* H5FD__hdfs_fapl_copy() */
/*-------------------------------------------------------------------------
- * Function: H5FD_hdfs_fapl_free
+ * Function: H5FD__hdfs_fapl_free
*
* Purpose: Frees the hdfs-specific file access properties.
*
@@ -880,24 +790,24 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_hdfs_fapl_free(void *_fa)
+H5FD__hdfs_fapl_free(void *_fa)
{
H5FD_hdfs_fapl_t *fa = (H5FD_hdfs_fapl_t*)_fa;
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
HDassert(fa != NULL); /* sanity check */
H5MM_xfree(fa);
FUNC_LEAVE_NOAPI(SUCCEED)
+} /* H5FD__hdfs_fapl_free() */
-} /* H5FD_hdfs_fapl_free() */
#if HDFS_STATS
/*----------------------------------------------------------------------------
*
- * Function: hdfs_reset_stats()
+ * Function: hdfs__reset_stats()
*
* Purpose:
*
@@ -917,23 +827,21 @@ H5FD_hdfs_fapl_free(void *_fa)
*----------------------------------------------------------------------------
*/
static herr_t
-hdfs_reset_stats(H5FD_hdfs_t *file)
+hdfs__reset_stats(H5FD_hdfs_t *file)
{
unsigned i = 0;
herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
#if HDFS_DEBUG
- HDprintf("hdfs_reset_stats() called\n");
+ HDprintf("hdfs__reset_stats() called\n");
#endif
- if (file == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "file was null")
- }
+ if(file == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "file was null")
- for (i = 0; i <= HDFS_STATS_BIN_COUNT; i++) {
+ for(i = 0; i <= HDFS_STATS_BIN_COUNT; i++) {
file->raw[i].bytes = 0;
file->raw[i].count = 0;
file->raw[i].min = (unsigned long long)HDFS_STATS_STARTING_MIN;
@@ -948,13 +856,13 @@ hdfs_reset_stats(H5FD_hdfs_t *file)
done:
FUNC_LEAVE_NOAPI(ret_value);
-} /* hdfs_reset_stats */
+} /* hdfs__reset_stats */
#endif /* HDFS_STATS */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_hdfs_open()
+ * Function: H5FD__hdfs_open()
*
* Purpose:
*
@@ -975,133 +883,76 @@ done:
*
*-------------------------------------------------------------------------
*/
-#ifdef H5_HAVE_LIBHDFS
static H5FD_t *
-H5FD_hdfs_open(
- const char *path,
- unsigned flags,
- hid_t fapl_id,
- haddr_t maxaddr)
+H5FD__hdfs_open(const char *path, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
{
H5FD_t *ret_value = NULL;
H5FD_hdfs_t *file = NULL;
hdfs_t *handle = NULL;
H5FD_hdfs_fapl_t fa;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_open() called.\n");
+ HDfprintf(stdout, "called %s.\n", FUNC);
#endif /* HDFS_DEBUG */
/* Sanity check on file offsets */
HDcompile_assert(sizeof(HDoff_t) >= sizeof(size_t));
/* Check arguments */
- if (!path || !*path) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "invalid file name")
- }
- if (0 == maxaddr || HADDR_UNDEF == maxaddr) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL,
- "bogus maxaddr")
- }
- if (ADDR_OVERFLOW(maxaddr)) {
- HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL,
- "bogus maxaddr")
- }
- if (flags != H5F_ACC_RDONLY) {
- HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, NULL,
- "only Read-Only access allowed")
- }
- if (fapl_id == H5P_DEFAULT || fapl_id == H5P_FILE_ACCESS_DEFAULT) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "fapl cannot be H5P_DEFAULT")
- }
- if (FAIL == H5Pget_fapl_hdfs(fapl_id, &fa)) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "can't get property list")
- }
-
- handle = H5FD_hdfs_handle_open(
- path,
- fa.namenode_name,
- fa.namenode_port,
- fa.user_name,
- fa.kerberos_ticket_cache,
- fa.stream_buffer_size);
-
- if (handle == NULL) {
- HGOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, NULL,
- "could not open")
- }
+ if(!path || !*path)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name")
+ if(0 == maxaddr || HADDR_UNDEF == maxaddr)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr")
+ if(ADDR_OVERFLOW(maxaddr))
+ HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr")
+ if(flags != H5F_ACC_RDONLY)
+ HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, NULL, "only Read-Only access allowed")
+ if(fapl_id == H5P_DEFAULT || fapl_id == H5P_FILE_ACCESS_DEFAULT)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "fapl cannot be H5P_DEFAULT")
+ if(FAIL == H5Pget_fapl_hdfs(fapl_id, &fa))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "can't get property list")
+
+ handle = H5FD__hdfs_handle_open(path, fa.namenode_name, fa.namenode_port,
+ fa.user_name, fa.kerberos_ticket_cache, fa.stream_buffer_size);
+ if(handle == NULL)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, NULL, "could not open")
HDassert(handle->magic == HDFS_HDFST_MAGIC);
- /* create new file struct
- */
+ /* Create new file struct */
file = H5FL_CALLOC(H5FD_hdfs_t);
- if (file == NULL) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
- "unable to allocate file struct")
- }
+ if(file == NULL)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "unable to allocate file struct")
file->hdfs_handle = handle;
HDmemcpy(&(file->fa), &fa, sizeof(H5FD_hdfs_fapl_t));
#if HDFS_STATS
- if (FAIL == hdfs_reset_stats(file)) {
- HGOTO_ERROR(H5E_INTERNAL, H5E_UNINITIALIZED, NULL,
- "unable to reset file statistics")
- }
+ if(FAIL == hdfs__reset_stats(file))
+ HGOTO_ERROR(H5E_INTERNAL, H5E_UNINITIALIZED, NULL, "unable to reset file statistics")
#endif /* HDFS_STATS */
ret_value = (H5FD_t*)file;
done:
- if (ret_value == NULL) {
- if (handle != NULL) {
- if (FAIL == H5FD_hdfs_handle_close(handle)) {
- HDONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, NULL,
- "unable to close HDFS file handle")
- }
- }
- if (file != NULL) {
+ if(ret_value == NULL) {
+ if(handle != NULL)
+ if(FAIL == H5FD__hdfs_handle_close(handle))
+ HDONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, NULL, "unable to close HDFS file handle")
+ if(file != NULL)
file = H5FL_FREE(H5FD_hdfs_t, file);
- }
} /* end if null return value (error) */
FUNC_LEAVE_NOAPI(ret_value)
+} /* H5FD__hdfs_open() */
-} /* H5FD_hdfs_open() */
-
-#else /* H5_HAVE_LIBHDFS not defined */
-
-static H5FD_t *
-H5FD_hdfs_open(
- const char H5_ATTR_UNUSED *path,
- unsigned H5_ATTR_UNUSED flags,
- hid_t H5_ATTR_UNUSED fapl_id,
- haddr_t H5_ATTR_UNUSED maxaddr)
-{
- H5FD_t *ret_value = NULL;
-
- FUNC_ENTER_NOAPI_NOINIT
-
- HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, NULL,
- "Illegal open of unsupported virtual file (hdfs)");
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-
-} /* H5FD_hdfs_open() */
-
-#endif /* H5_HAVE_LIBHDFS */
#if HDFS_STATS
/*----------------------------------------------------------------------------
*
- * Function: hdfs_fprint_stats()
+ * Function: hdfs__fprint_stats()
*
* Purpose:
*
@@ -1154,9 +1005,7 @@ done:
*----------------------------------------------------------------------------
*/
static herr_t
-hdfs_fprint_stats(
- FILE *stream,
- const H5FD_hdfs_t *file)
+hdfs__fprint_stats(FILE *stream, const H5FD_hdfs_t *file)
{
herr_t ret_value = SUCCEED;
parsed_url_t *purl = NULL;
@@ -1175,49 +1024,43 @@ hdfs_fprint_stats(
unsigned suffix_i = 0;
const char suffixes[] = { ' ', 'K', 'M', 'G', 'T', 'P' };
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
- if (stream == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "file stream cannot be null" )
- }
- if (file == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "file cannot be null")
- }
- if (file->hdfs_handle == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "hdfs handle cannot be null")
- }
- if (file->hdfs_handle->magic != HDFS_HDFST_MAGIC) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "hdfs handle has invalid magic")
- }
+ if(stream == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "file stream cannot be null")
+ if(file == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "file cannot be null")
+ if(file->hdfs_handle == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "hdfs handle cannot be null")
+ if(file->hdfs_handle->magic != HDFS_HDFST_MAGIC)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "hdfs handle has invalid magic")
/*******************
* AGGREGATE STATS *
*******************/
- for (i = 0; i <= HDFS_STATS_BIN_COUNT; i++) {
+ for(i = 0; i <= HDFS_STATS_BIN_COUNT; i++) {
const hdfs_statsbin *r = &file->raw[i];
const hdfs_statsbin *m = &file->meta[i];
- if (m->min < min_meta) { min_meta = m->min; }
- if (r->min < min_raw) { min_raw = r->min; }
- if (m->max > max_meta) { max_meta = m->max; }
- if (r->max > max_raw) { max_raw = r->max; }
+ if(m->min < min_meta)
+ min_meta = m->min;
+ if(r->min < min_raw)
+ min_raw = r->min;
+ if(m->max > max_meta)
+ max_meta = m->max;
+ if(r->max > max_raw)
+ max_raw = r->max;
count_raw += r->count;
count_meta += m->count;
bytes_raw += r->bytes;
bytes_meta += m->bytes;
}
- if (count_raw > 0) {
+ if(count_raw > 0)
average_raw = (double)bytes_raw / (double)count_raw;
- }
- if (count_meta > 0) {
+ if(count_meta > 0)
average_meta = (double)bytes_meta / (double)count_meta;
- }
/******************
* PRINT OVERVIEW *
@@ -1228,9 +1071,8 @@ hdfs_fprint_stats(
HDfprintf(stream, "TOTAL BYTES: %llu (%llu meta, %llu raw)\n",
bytes_raw + bytes_meta, bytes_meta, bytes_raw);
- if (count_raw + count_meta == 0) {
+ if(count_raw + count_meta == 0)
goto done;
- }
/*************************
* PRINT AGGREGATE STATS *
@@ -1238,55 +1080,49 @@ hdfs_fprint_stats(
HDfprintf(stream, "SIZES meta raw\n");
HDfprintf(stream, " min ");
- if (count_meta == 0) {
+ if(count_meta == 0)
HDfprintf(stream, " 0.000 ");
- } else {
+ else {
re_dub = (double)min_meta;
- for (suffix_i = 0; re_dub >= 1024.0; suffix_i++) {
+ for(suffix_i = 0; re_dub >= 1024.0; suffix_i++)
re_dub /= 1024.0;
- }
HDassert(suffix_i < sizeof(suffixes));
HDfprintf(stream, "%8.3lf%c ", re_dub, suffixes[suffix_i]);
}
- if (count_raw == 0) {
+ if(count_raw == 0)
HDfprintf(stream, " 0.000 \n");
- } else {
+ else {
re_dub = (double)min_raw;
- for (suffix_i = 0; re_dub >= 1024.0; suffix_i++) {
+ for(suffix_i = 0; re_dub >= 1024.0; suffix_i++)
re_dub /= 1024.0;
- }
HDassert(suffix_i < sizeof(suffixes));
HDfprintf(stream, "%8.3lf%c\n", re_dub, suffixes[suffix_i]);
}
HDfprintf(stream, " avg ");
re_dub = (double)average_meta;
- for (suffix_i = 0; re_dub >= 1024.0; suffix_i++) {
+ for(suffix_i = 0; re_dub >= 1024.0; suffix_i++)
re_dub /= 1024.0;
- }
HDassert(suffix_i < sizeof(suffixes));
HDfprintf(stream, "%8.3lf%c ", re_dub, suffixes[suffix_i]);
re_dub = (double)average_raw;
- for (suffix_i = 0; re_dub >= 1024.0; suffix_i++) {
+ for(suffix_i = 0; re_dub >= 1024.0; suffix_i++)
re_dub /= 1024.0;
- }
HDassert(suffix_i < sizeof(suffixes));
HDfprintf(stream, "%8.3lf%c\n", re_dub, suffixes[suffix_i]);
HDfprintf(stream, " max ");
re_dub = (double)max_meta;
- for (suffix_i = 0; re_dub >= 1024.0; suffix_i++) {
+ for(suffix_i = 0; re_dub >= 1024.0; suffix_i++)
re_dub /= 1024.0;
- }
HDassert(suffix_i < sizeof(suffixes));
HDfprintf(stream, "%8.3lf%c ", re_dub, suffixes[suffix_i]);
re_dub = (double)max_raw;
- for (suffix_i = 0; re_dub >= 1024.0; suffix_i++) {
+ for(suffix_i = 0; re_dub >= 1024.0; suffix_i++)
re_dub /= 1024.0;
- }
HDassert(suffix_i < sizeof(suffixes));
HDfprintf(stream, "%8.3lf%c\n", re_dub, suffixes[suffix_i]);
@@ -1299,7 +1135,7 @@ hdfs_fprint_stats(
HDfprintf(stream,
" up-to meta raw meta raw meta raw\n");
- for (i = 0; i <= HDFS_STATS_BIN_COUNT; i++) {
+ for(i = 0; i <= HDFS_STATS_BIN_COUNT; i++) {
const hdfs_statsbin *m;
const hdfs_statsbin *r;
unsigned long long range_end = 0;
@@ -1314,55 +1150,47 @@ hdfs_fprint_stats(
m = &file->meta[i];
r = &file->raw[i];
- if (r->count == 0 && m->count == 0) {
+ if(r->count == 0 && m->count == 0)
continue;
- }
range_end = hdfs_stats_boundaries[i];
- if (i == HDFS_STATS_BIN_COUNT) {
+ if(i == HDFS_STATS_BIN_COUNT) {
range_end = hdfs_stats_boundaries[i-1];
HDfprintf(stream, ">");
- } else {
- HDfprintf(stream, " ");
}
+ else
+ HDfprintf(stream, " ");
bm_val = (double)m->bytes;
- for (suffix_i = 0; bm_val >= 1024.0; suffix_i++) {
+ for(suffix_i = 0; bm_val >= 1024.0; suffix_i++)
bm_val /= 1024.0;
- }
HDassert(suffix_i < sizeof(suffixes));
bm_suffix = suffixes[suffix_i];
br_val = (double)r->bytes;
- for (suffix_i = 0; br_val >= 1024.0; suffix_i++) {
+ for(suffix_i = 0; br_val >= 1024.0; suffix_i++)
br_val /= 1024.0;
- }
HDassert(suffix_i < sizeof(suffixes));
br_suffix = suffixes[suffix_i];
- if (m->count > 0) {
+ if(m->count > 0)
am_val = (double)(m->bytes) / (double)(m->count);
- }
- for (suffix_i = 0; am_val >= 1024.0; suffix_i++) {
+ for(suffix_i = 0; am_val >= 1024.0; suffix_i++)
am_val /= 1024.0;
- }
HDassert(suffix_i < sizeof(suffixes));
am_suffix = suffixes[suffix_i];
- if (r->count > 0) {
+ if(r->count > 0)
ar_val = (double)(r->bytes) / (double)(r->count);
- }
- for (suffix_i = 0; ar_val >= 1024.0; suffix_i++) {
+ for(suffix_i = 0; ar_val >= 1024.0; suffix_i++)
ar_val /= 1024.0;
- }
HDassert(suffix_i < sizeof(suffixes));
ar_suffix = suffixes[suffix_i];
re_dub = (double)range_end;
- for (suffix_i = 0; re_dub >= 1024.0; suffix_i++) {
+ for(suffix_i = 0; re_dub >= 1024.0; suffix_i++)
re_dub /= 1024.0;
- }
HDassert(suffix_i < sizeof(suffixes));
HDfprintf(
@@ -1375,18 +1203,18 @@ hdfs_fprint_stats(
br_val, br_suffix, /* rawdata bytes */
am_val, am_suffix, /* metadata average */
ar_val, ar_suffix); /* rawdata average */
- fflush(stream);
+ HDfflush(stream);
}
done:
FUNC_LEAVE_NOAPI(ret_value);
-} /* hdfs_fprint_stats */
+} /* hdfs__fprint_stats */
#endif /* HDFS_STATS */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_hdfs_close()
+ * Function: H5FD__hdfs_close()
*
* Purpose:
*
@@ -1401,73 +1229,45 @@ done:
*
*-------------------------------------------------------------------------
*/
-#ifdef H5_HAVE_LIBHDFS
-
static herr_t
-H5FD_hdfs_close(H5FD_t *_file)
+H5FD__hdfs_close(H5FD_t *_file)
{
herr_t ret_value = SUCCEED;
H5FD_hdfs_t *file = (H5FD_hdfs_t *)_file;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_close() called.\n");
+ HDfprintf(stdout, "called %s.\n", FUNC);
#endif
- /* Sanity checks
- */
+ /* Sanity checks */
HDassert(file != NULL);
HDassert(file->hdfs_handle != NULL);
HDassert(file->hdfs_handle->magic == HDFS_HDFST_MAGIC);
- /* Close the underlying request handle
- */
- if (file->hdfs_handle != NULL) {
- if (FAIL == H5FD_hdfs_handle_close(file->hdfs_handle)) {
- HGOTO_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL,
- "unable to close HDFS file handle")
- }
- }
+ /* Close the underlying request handle */
+ if(file->hdfs_handle != NULL)
+ if(FAIL == H5FD__hdfs_handle_close(file->hdfs_handle))
+ HGOTO_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL, "unable to close HDFS file handle")
#if HDFS_STATS
/* TODO: mechanism to re-target stats printout */
- if (FAIL == hdfs_fprint_stats(stdout, file)) {
- HGOTO_ERROR(H5E_INTERNAL, H5E_ERROR, FAIL,
- "problem while writing file statistics")
- }
+ if(FAIL == hdfs__fprint_stats(stdout, file))
+ HGOTO_ERROR(H5E_INTERNAL, H5E_ERROR, FAIL, "problem while writing file statistics")
#endif /* HDFS_STATS */
- /* Release the file info
- */
+ /* Release the file info */
file = H5FL_FREE(H5FD_hdfs_t, file);
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5FD_hdfs_close() */
-
-#else /* H5_HAVE_LIBHDFS not defined */
-
-static herr_t
-H5FD_hdfs_close(H5FD_t H5_ATTR_UNUSED *_file)
-{
- herr_t ret_value = SUCCEED;
-
- FUNC_ENTER_NOAPI_NOINIT
-
- HGOTO_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL,
- "Illegal close of unsupported Virtual File (hdfs)")
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5FD_hdfs_close() */
-
-#endif /* H5_HAVE_LIBHDFS */
+} /* end H5FD__hdfs_close() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_hdfs_cmp()
+ * Function: H5FD__hdfs_cmp()
*
* Purpose:
*
@@ -1483,12 +1283,8 @@ done:
*
*-------------------------------------------------------------------------
*/
-#ifdef H5_HAVE_LIBHDFS
-
static int
-H5FD_hdfs_cmp(
- const H5FD_t *_f1,
- const H5FD_t *_f2)
+H5FD__hdfs_cmp(const H5FD_t *_f1, const H5FD_t *_f2)
{
int ret_value = 0;
const H5FD_hdfs_t *f1 = (const H5FD_hdfs_t *)_f1;
@@ -1496,10 +1292,10 @@ H5FD_hdfs_cmp(
hdfsFileInfo *finfo1 = NULL;
hdfsFileInfo *finfo2 = NULL;
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_cmp() called.\n");
+ HDfprintf(stdout, "called %s.\n", FUNC);
#endif /* HDFS_DEBUG */
HDassert(f1->hdfs_handle != NULL);
@@ -1512,40 +1308,24 @@ H5FD_hdfs_cmp(
HDassert(finfo1 != NULL);
HDassert(finfo2 != NULL);
- if (finfo1->mKind != finfo2->mKind) { HGOTO_DONE(-1); }
- if (finfo1->mName != finfo2->mName) { HGOTO_DONE(-1); }
- if (finfo1->mLastMod != finfo2->mLastMod) { HGOTO_DONE(-1); }
- if (finfo1->mSize != finfo2->mSize) { HGOTO_DONE(-1); }
- if (finfo1->mReplication != finfo2->mReplication) { HGOTO_DONE(-1); }
- if (finfo1->mBlockSize != finfo2->mBlockSize) { HGOTO_DONE(-1); }
- if (strcmp(finfo1->mOwner, finfo2->mOwner)) { HGOTO_DONE(-1); }
- if (strcmp(finfo1->mGroup, finfo2->mGroup)) { HGOTO_DONE(-1); }
- if (finfo1->mPermissions != finfo2->mPermissions) { HGOTO_DONE(-1); }
- if (finfo1->mLastAccess != finfo2->mLastAccess) { HGOTO_DONE(-1); }
+ if(finfo1->mKind != finfo2->mKind) { HGOTO_DONE(-1); }
+ if(finfo1->mName != finfo2->mName) { HGOTO_DONE(-1); }
+ if(finfo1->mLastMod != finfo2->mLastMod) { HGOTO_DONE(-1); }
+ if(finfo1->mSize != finfo2->mSize) { HGOTO_DONE(-1); }
+ if(finfo1->mReplication != finfo2->mReplication) { HGOTO_DONE(-1); }
+ if(finfo1->mBlockSize != finfo2->mBlockSize) { HGOTO_DONE(-1); }
+ if(HDstrcmp(finfo1->mOwner, finfo2->mOwner)) { HGOTO_DONE(-1); }
+ if(HDstrcmp(finfo1->mGroup, finfo2->mGroup)) { HGOTO_DONE(-1); }
+ if(finfo1->mPermissions != finfo2->mPermissions) { HGOTO_DONE(-1); }
+ if(finfo1->mLastAccess != finfo2->mLastAccess) { HGOTO_DONE(-1); }
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* H5FD_hdfs_cmp() */
-
-#else /* H5_HAVE_LIBHDFS not defined */
-
-static int
-H5FD_hdfs_cmp(
- const H5FD_t H5_ATTR_UNUSED *_f1,
- const H5FD_t H5_ATTR_UNUSED *_f2)
-{
- int ret_value = 0;
-
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
- FUNC_LEAVE_NOAPI(ret_value)
-} /* H5FD_hdfs_cmp() */
-
-#endif /* H5_HAVE_LIBHDFS */
+} /* H5FD__hdfs_cmp() */
/*-------------------------------------------------------------------------
- * Function: H5FD_hdfs_query
+ * Function: H5FD__hdfs_query
*
* Purpose: Set the flags that this VFL driver is capable of supporting.
* (listed in H5FDpublic.h)
@@ -1564,28 +1344,26 @@ H5FD_hdfs_cmp(
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_hdfs_query(
- const H5FD_t H5_ATTR_UNUSED *_file,
- unsigned long *flags) /* out variable */
+H5FD__hdfs_query(const H5FD_t H5_ATTR_UNUSED *_file, unsigned long *flags)
{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_query() called.\n");
+ HDfprintf(stdout, "called %s.\n", FUNC);
#endif
- if (flags) {
+ if(flags) {
*flags = 0;
*flags |= H5FD_FEAT_DATA_SIEVE;
}
FUNC_LEAVE_NOAPI(SUCCEED)
-} /* H5FD_hdfs_query() */
+} /* H5FD__hdfs_query() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_hdfs_get_eoa()
+ * Function: H5FD__hdfs_get_eoa()
*
* Purpose:
*
@@ -1602,46 +1380,24 @@ H5FD_hdfs_query(
*
*-------------------------------------------------------------------------
*/
-#ifdef H5_HAVE_LIBHDFS
-
static haddr_t
-H5FD_hdfs_get_eoa(
- const H5FD_t *_file,
- H5FD_mem_t H5_ATTR_UNUSED type)
+H5FD__hdfs_get_eoa(const H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type)
{
const H5FD_hdfs_t *file = (const H5FD_hdfs_t *)_file;
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_get_eoa() called.\n");
+ HDfprintf(stdout, "called %s.\n", FUNC);
#endif
FUNC_LEAVE_NOAPI(file->eoa)
-} /* end H5FD_hdfs_get_eoa() */
-
-#else /* H5_HAVE_LIBHDFS not defined */
-
-static haddr_t
-H5FD_hdfs_get_eoa(
- const H5FD_t H5_ATTR_UNUSED *_file,
- H5FD_mem_t H5_ATTR_UNUSED type)
-{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
-#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_get_eoa() called.\n");
-#endif
-
- FUNC_LEAVE_NOAPI(0)
-} /* end H5FD_hdfs_get_eoa() */
-
-#endif /* H5_HAVE_LIBHDFS */
+} /* end H5FD__hdfs_get_eoa() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_hdfs_set_eoa()
+ * Function: H5FD__hdfs_set_eoa()
*
* Purpose:
*
@@ -1656,50 +1412,26 @@ H5FD_hdfs_get_eoa(
*
*-------------------------------------------------------------------------
*/
-#ifdef H5_HAVE_LIBHDFS
-
static herr_t
-H5FD_hdfs_set_eoa(
- H5FD_t *_file,
- H5FD_mem_t H5_ATTR_UNUSED type,
- haddr_t addr)
+H5FD__hdfs_set_eoa(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, haddr_t addr)
{
H5FD_hdfs_t *file = (H5FD_hdfs_t *)_file;
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_set_eoa() called.\n");
+ HDfprintf(stdout, "called %s.\n", FUNC);
#endif
file->eoa = addr;
FUNC_LEAVE_NOAPI(SUCCEED)
-} /* H5FD_hdfs_set_eoa() */
-
-#else /* H5_HAVE_LIBHDFS not defined */
-
-static herr_t
-H5FD_hdfs_set_eoa(
- H5FD_t H5_ATTR_UNUSED *_file,
- H5FD_mem_t H5_ATTR_UNUSED type,
- haddr_t H5_ATTR_UNUSED addr)
-{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
-#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_set_eoa() called.\n");
-#endif
-
- FUNC_LEAVE_NOAPI(FAIL)
-} /* H5FD_hdfs_set_eoa() */
-
-#endif /* H5_HAVE_LIBHDFS */
+} /* H5FD__hdfs_set_eoa() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_hdfs_get_eof()
+ * Function: H5FD__hdfs_get_eof()
*
* Purpose:
*
@@ -1715,49 +1447,27 @@ H5FD_hdfs_set_eoa(
*
*-------------------------------------------------------------------------
*/
-#ifdef H5_HAVE_LIBHDFS
-
static haddr_t
-H5FD_hdfs_get_eof(
- const H5FD_t *_file,
- H5FD_mem_t H5_ATTR_UNUSED type)
+H5FD__hdfs_get_eof(const H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type)
{
const H5FD_hdfs_t *file = (const H5FD_hdfs_t *)_file;
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_get_eof() called.\n");
+ HDfprintf(stdout, "called %s.\n", FUNC);
#endif
HDassert(file->hdfs_handle != NULL);
HDassert(file->hdfs_handle->magic == HDFS_HDFST_MAGIC);
FUNC_LEAVE_NOAPI((size_t) file->hdfs_handle->fileinfo->mSize)
-} /* end H5FD_hdfs_get_eof() */
-
-#else /* H5_HAVE_LIBHDFS not defined */
-
-static haddr_t
-H5FD_hdfs_get_eof(
- const H5FD_t H5_ATTR_UNUSED *_file,
- H5FD_mem_t H5_ATTR_UNUSED type)
-{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
-#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_get_eof() called.\n");
-#endif
-
- FUNC_LEAVE_NOAPI((size_t)0)
-} /* end H5FD_hdfs_get_eof() */
-
-#endif /* H5_HAVE_LIBHDFS */
+} /* end H5FD__hdfs_get_eof() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_hdfs_get_handle()
+ * Function: H5FD__hdfs_get_handle()
*
* Purpose:
*
@@ -1772,63 +1482,31 @@ H5FD_hdfs_get_eof(
*
*-------------------------------------------------------------------------
*/
-#ifdef H5_HAVE_LIBHDFS
-
static herr_t
-H5FD_hdfs_get_handle(
- H5FD_t *_file,
- hid_t H5_ATTR_UNUSED fapl,
- void **file_handle)
+H5FD__hdfs_get_handle(H5FD_t *_file, hid_t H5_ATTR_UNUSED fapl, void **file_handle)
{
herr_t ret_value = SUCCEED;
H5FD_hdfs_t *file = (H5FD_hdfs_t *)_file;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_get_handle() called.\n");
+ HDfprintf(stdout, "called %s.\n", FUNC);
#endif /* HDFS_DEBUG */
- if (!file_handle) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "file handle not valid")
- }
+ if(!file_handle)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "file handle not valid")
*file_handle = file->hdfs_handle;
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5FD_hdfs_get_handle() */
-
-#else /* H5_HAVE_LIBHDFS not defined */
-
-static herr_t
-H5FD_hdfs_get_handle(
- H5FD_t H5_ATTR_UNUSED *_file,
- hid_t H5_ATTR_UNUSED fapl,
- void H5_ATTR_UNUSED **file_handle)
-{
- herr_t ret_value = SUCCEED;
-
- FUNC_ENTER_NOAPI_NOINIT
-
-#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_get_handle() called.\n");
-#endif /* HDFS_DEBUG */
-
- HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL,
- "Illegal get-handle of unsupported virtual file (hdfs)");
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5FD_hdfs_get_handle() */
-
-#endif /* H5_HAVE_LIBHDFS */
+} /* end H5FD__hdfs_get_handle() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_hdfs_read()
+ * Function: H5FD__hdfs_read()
*
* Purpose:
*
@@ -1848,16 +1526,9 @@ done:
*
*-------------------------------------------------------------------------
*/
-#ifdef H5_HAVE_LIBHDFS
-
static herr_t
-H5FD_hdfs_read(
- H5FD_t *_file,
- H5FD_mem_t H5_ATTR_UNUSED type,
- hid_t H5_ATTR_UNUSED dxpl_id,
- haddr_t addr, /* start offset */
- size_t size, /* length of read */
- void *buf) /* out */
+H5FD__hdfs_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type,
+ hid_t H5_ATTR_UNUSED dxpl_id, haddr_t addr, size_t size, void *buf)
{
herr_t ret_value = SUCCEED;
H5FD_hdfs_t *file = (H5FD_hdfs_t *)_file;
@@ -1868,10 +1539,10 @@ H5FD_hdfs_read(
unsigned bin_i = 0;
#endif /* HDFS_STATS */
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_read() called.\n");
+ HDfprintf(stdout, "called %s.\n", FUNC);
#endif /* HDFS_DEBUG */
HDassert(file != NULL);
@@ -1881,44 +1552,33 @@ H5FD_hdfs_read(
filesize = (size_t) file->hdfs_handle->fileinfo->mSize;
- if ((addr > filesize) || ((addr + size) > filesize)) {
- HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL,
- "range exceeds file address")
- }
+ if((addr > filesize) || ((addr + size) > filesize))
+ HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "range exceeds file address")
- if (FAIL == hdfsPread(
- file->hdfs_handle->filesystem,
- file->hdfs_handle->file,
- (tOffset)addr,
- buf,
- (tSize)size))
- {
- HGOTO_ERROR(H5E_VFL, H5E_READERROR, FAIL,
- "unable to execute read")
- }
+ if(FAIL == hdfsPread(file->hdfs_handle->filesystem, file->hdfs_handle->file,
+ (tOffset)addr, buf, (tSize)size))
+ HGOTO_ERROR(H5E_VFL, H5E_READERROR, FAIL, "unable to execute read")
#if HDFS_STATS
- /* Find which "bin" this read fits in. Can be "overflow" bin.
- */
- for (bin_i = 0; bin_i < HDFS_STATS_BIN_COUNT; bin_i++) {
- if ((unsigned long long)size < hdfs_stats_boundaries[bin_i]) {
+ /* Find which "bin" this read fits in. Can be "overflow" bin. */
+ for(bin_i = 0; bin_i < HDFS_STATS_BIN_COUNT; bin_i++)
+ if((unsigned long long)size < hdfs_stats_boundaries[bin_i])
break;
- }
- }
bin = (type == H5FD_MEM_DRAW)
? &file->raw[bin_i]
: &file->meta[bin_i];
- /* Store collected stats in appropriate bin
- */
- if (bin->count == 0) {
+ /* Store collected stats in appropriate bin */
+ if(bin->count == 0) {
bin->min = size;
bin->max = size;
}
else {
- if (size < bin->min) { bin->min = size; }
- if (size > bin->max) { bin->max = size; }
+ if(size < bin->min)
+ bin->min = size;
+ if(size > bin->max)
+ bin->max = size;
}
bin->count++;
bin->bytes += (unsigned long long)size;
@@ -1927,40 +1587,12 @@ H5FD_hdfs_read(
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5FD_hdfs_read() */
-
-#else /* H5_HAVE_LIBHDFS not defined */
-
-static herr_t
-H5FD_hdfs_read(
- H5FD_t H5_ATTR_UNUSED *_file,
- H5FD_mem_t H5_ATTR_UNUSED type,
- hid_t H5_ATTR_UNUSED dxpl_id,
- haddr_t H5_ATTR_UNUSED addr,
- size_t H5_ATTR_UNUSED size,
- void H5_ATTR_UNUSED *buf)
-{
- herr_t ret_value = SUCCEED;
-
- FUNC_ENTER_NOAPI_NOINIT
-
-#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_read() called.\n");
-#endif /* HDFS_DEBUG */
-
- HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL,
- "Illegal get-handle of unsupported virtual file (hdfs)");
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5FD_hdfs_read() */
-
-#endif /* H5_HAVE_LIBHDFS */
+} /* end H5FD__hdfs_read() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_hdfs_write()
+ * Function: H5FD__hdfs_write()
*
* Purpose:
*
@@ -1977,33 +1609,28 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_hdfs_write(
- H5FD_t H5_ATTR_UNUSED *_file,
- H5FD_mem_t H5_ATTR_UNUSED type,
- hid_t H5_ATTR_UNUSED dxpl_id,
- haddr_t H5_ATTR_UNUSED addr,
- size_t H5_ATTR_UNUSED size,
- const void H5_ATTR_UNUSED *buf)
+H5FD__hdfs_write(H5FD_t H5_ATTR_UNUSED *_file, H5FD_mem_t H5_ATTR_UNUSED type,
+ hid_t H5_ATTR_UNUSED dxpl_id, haddr_t H5_ATTR_UNUSED addr, size_t H5_ATTR_UNUSED size,
+ const void H5_ATTR_UNUSED *buf)
{
herr_t ret_value = FAIL;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_write() called.\n");
+ HDfprintf(stdout, "called %s.\n", FUNC);
#endif
- HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL,
- "cannot write to read-only file.")
+ HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL, "cannot write to read-only file")
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* H5FD_hdfs_write() */
+} /* H5FD__hdfs_write() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_hdfs_truncate()
+ * Function: H5FD__hdfs_truncate()
*
* Purpose:
*
@@ -2022,30 +1649,27 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_hdfs_truncate(
- H5FD_t H5_ATTR_UNUSED *_file,
- hid_t H5_ATTR_UNUSED dxpl_id,
- hbool_t H5_ATTR_UNUSED closing)
+H5FD__hdfs_truncate(H5FD_t H5_ATTR_UNUSED *_file, hid_t H5_ATTR_UNUSED dxpl_id,
+ hbool_t H5_ATTR_UNUSED closing)
{
herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
#if HDFS_DEBUG
- HDfprintf(stdout, "H5FD_hdfs_truncate() called.\n");
+ HDfprintf(stdout, "called %s.\n", FUNC);
#endif
- HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL,
- "cannot truncate read-only file.")
+ HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL, "cannot truncate read-only file")
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5FD_hdfs_truncate() */
+} /* end H5FD__hdfs_truncate() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_hdfs_lock()
+ * Function: H5FD__hdfs_lock()
*
* Purpose:
*
@@ -2065,18 +1689,19 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_hdfs_lock(
+H5FD__hdfs_lock(
H5FD_t H5_ATTR_UNUSED *_file,
hbool_t H5_ATTR_UNUSED rw)
{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
+
FUNC_LEAVE_NOAPI(SUCCEED)
-} /* end H5FD_hdfs_lock() */
+} /* end H5FD__hdfs_lock() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_hdfs_unlock()
+ * Function: H5FD__hdfs_unlock()
*
* Purpose:
*
@@ -2093,9 +1718,11 @@ H5FD_hdfs_lock(
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_hdfs_unlock(H5FD_t H5_ATTR_UNUSED *_file)
+H5FD__hdfs_unlock(H5FD_t H5_ATTR_UNUSED *_file)
{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
+
FUNC_LEAVE_NOAPI(SUCCEED)
-} /* end H5FD_hdfs_unlock() */
+} /* end H5FD__hdfs_unlock() */
+#endif /* H5_HAVE_LIBHDFS */
diff --git a/src/H5FDhdfs.h b/src/H5FDhdfs.h
index e172103..d67ab9e 100644
--- a/src/H5FDhdfs.h
+++ b/src/H5FDhdfs.h
@@ -22,8 +22,13 @@
#ifndef H5FDhdfs_H
#define H5FDhdfs_H
-#define H5FD_HDFS (H5FD_hdfs_init())
+#ifdef H5_HAVE_LIBHDFS
+#define H5FD_HDFS (H5FD_hdfs_init())
+#else /* H5_HAVE_LIBHDFS */
+#define H5FD_HDFS (-1)
+#endif /* H5_HAVE_LIBHDFS */
+#ifdef H5_HAVE_LIBHDFS
#ifdef __cplusplus
extern "C" {
#endif
@@ -114,6 +119,7 @@ H5_DLL herr_t H5Pset_fapl_hdfs(hid_t fapl_id, H5FD_hdfs_fapl_t *fa);
#ifdef __cplusplus
}
#endif
+#endif /* H5_HAVE_LIBHDFS */
#endif /* ifndef H5FDhdfs_H */
diff --git a/src/H5FDros3.c b/src/H5FDros3.c
index a1328ec..c024716 100644
--- a/src/H5FDros3.c
+++ b/src/H5FDros3.c
@@ -212,66 +212,67 @@ typedef struct H5FD_ros3_t {
* Only included if it may be used -- ROS3 VFD is enabled.
*
*/
-#define MAXADDR (((haddr_t)1<<(8*sizeof(HDoff_t)-1))-1)
+#define MAXADDR (((haddr_t)1 << (8 * sizeof(HDoff_t) - 1)) - 1)
#define ADDR_OVERFLOW(A) (HADDR_UNDEF==(A) || ((A) & ~(haddr_t)MAXADDR))
/* Prototypes */
-static herr_t H5FD_ros3_term(void);
-static void *H5FD_ros3_fapl_get(H5FD_t *_file);
-static void *H5FD_ros3_fapl_copy(const void *_old_fa);
-static herr_t H5FD_ros3_fapl_free(void *_fa);
-static H5FD_t *H5FD_ros3_open(const char *name, unsigned flags, hid_t fapl_id,
+static herr_t H5FD__ros3_term(void);
+static void *H5FD__ros3_fapl_get(H5FD_t *_file);
+static void *H5FD__ros3_fapl_copy(const void *_old_fa);
+static herr_t H5FD__ros3_fapl_free(void *_fa);
+static H5FD_t *H5FD__ros3_open(const char *name, unsigned flags, hid_t fapl_id,
haddr_t maxaddr);
-static herr_t H5FD_ros3_close(H5FD_t *_file);
-static int H5FD_ros3_cmp(const H5FD_t *_f1, const H5FD_t *_f2);
-static herr_t H5FD_ros3_query(const H5FD_t *_f1, unsigned long *flags);
-static haddr_t H5FD_ros3_get_eoa(const H5FD_t *_file, H5FD_mem_t type);
-static herr_t H5FD_ros3_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t addr);
-static haddr_t H5FD_ros3_get_eof(const H5FD_t *_file, H5FD_mem_t type);
-static herr_t H5FD_ros3_get_handle(H5FD_t *_file, hid_t fapl,
+static herr_t H5FD__ros3_close(H5FD_t *_file);
+static int H5FD__ros3_cmp(const H5FD_t *_f1, const H5FD_t *_f2);
+static herr_t H5FD__ros3_query(const H5FD_t *_f1, unsigned long *flags);
+static haddr_t H5FD__ros3_get_eoa(const H5FD_t *_file, H5FD_mem_t type);
+static herr_t H5FD__ros3_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t addr);
+static haddr_t H5FD__ros3_get_eof(const H5FD_t *_file, H5FD_mem_t type);
+static herr_t H5FD__ros3_get_handle(H5FD_t *_file, hid_t fapl,
void** file_handle);
-static herr_t H5FD_ros3_read(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id,
+static herr_t H5FD__ros3_read(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id,
haddr_t addr, size_t size, void *buf);
-static herr_t H5FD_ros3_write(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id,
+static herr_t H5FD__ros3_write(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id,
haddr_t addr, size_t size, const void *buf);
-static herr_t H5FD_ros3_truncate(H5FD_t *_file, hid_t dxpl_id,
+static herr_t H5FD__ros3_truncate(H5FD_t *_file, hid_t dxpl_id,
hbool_t closing);
-static herr_t H5FD_ros3_lock(H5FD_t *_file, hbool_t rw);
-static herr_t H5FD_ros3_unlock(H5FD_t *_file);
-static herr_t H5FD_ros3_validate_config(const H5FD_ros3_fapl_t * fa);
+static herr_t H5FD__ros3_lock(H5FD_t *_file, hbool_t rw);
+static herr_t H5FD__ros3_unlock(H5FD_t *_file);
+
+static herr_t H5FD__ros3_validate_config(const H5FD_ros3_fapl_t * fa);
static const H5FD_class_t H5FD_ros3_g = {
"ros3", /* name */
MAXADDR, /* maxaddr */
H5F_CLOSE_WEAK, /* fc_degree */
- H5FD_ros3_term, /* terminate */
+ H5FD__ros3_term, /* terminate */
NULL, /* sb_size */
NULL, /* sb_encode */
NULL, /* sb_decode */
sizeof(H5FD_ros3_fapl_t), /* fapl_size */
- H5FD_ros3_fapl_get, /* fapl_get */
- H5FD_ros3_fapl_copy, /* fapl_copy */
- H5FD_ros3_fapl_free, /* fapl_free */
+ H5FD__ros3_fapl_get, /* fapl_get */
+ H5FD__ros3_fapl_copy, /* fapl_copy */
+ H5FD__ros3_fapl_free, /* fapl_free */
0, /* dxpl_size */
NULL, /* dxpl_copy */
NULL, /* dxpl_free */
- H5FD_ros3_open, /* open */
- H5FD_ros3_close, /* close */
- H5FD_ros3_cmp, /* cmp */
- H5FD_ros3_query, /* query */
+ H5FD__ros3_open, /* open */
+ H5FD__ros3_close, /* close */
+ H5FD__ros3_cmp, /* cmp */
+ H5FD__ros3_query, /* query */
NULL, /* get_type_map */
NULL, /* alloc */
NULL, /* free */
- H5FD_ros3_get_eoa, /* get_eoa */
- H5FD_ros3_set_eoa, /* set_eoa */
- H5FD_ros3_get_eof, /* get_eof */
- H5FD_ros3_get_handle, /* get_handle */
- H5FD_ros3_read, /* read */
- H5FD_ros3_write, /* write */
+ H5FD__ros3_get_eoa, /* get_eoa */
+ H5FD__ros3_set_eoa, /* set_eoa */
+ H5FD__ros3_get_eof, /* get_eof */
+ H5FD__ros3_get_handle, /* get_handle */
+ H5FD__ros3_read, /* read */
+ H5FD__ros3_write, /* write */
NULL, /* flush */
- H5FD_ros3_truncate, /* truncate */
- H5FD_ros3_lock, /* lock */
- H5FD_ros3_unlock, /* unlock */
+ H5FD__ros3_truncate, /* truncate */
+ H5FD__ros3_lock, /* lock */
+ H5FD__ros3_unlock, /* unlock */
H5FD_FLMAP_DICHOTOMY /* fl_map */
};
@@ -297,10 +298,8 @@ H5FD__init_package(void)
FUNC_ENTER_STATIC
- if (H5FD_ros3_init() < 0) {
- HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL,
- "unable to initialize ros3 VFD")
- }
+ if(H5FD_ros3_init() < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize ros3 VFD")
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -357,7 +356,7 @@ done:
/*---------------------------------------------------------------------------
- * Function: H5FD_ros3_term
+ * Function: H5FD__ros3_term
*
* Purpose: Shut down the VFD
*
@@ -368,20 +367,19 @@ done:
*---------------------------------------------------------------------------
*/
static herr_t
-H5FD_ros3_term(void)
+H5FD__ros3_term(void)
{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
#if ROS3_DEBUG
- HDfprintf(stdout, "H5FD_ros3_term() called.\n");
+ HDfprintf(stdout, "H5FD__ros3_term() called.\n");
#endif
/* Reset VFL ID */
H5FD_ROS3_g = 0;
FUNC_LEAVE_NOAPI(SUCCEED)
-
-} /* end H5FD_ros3_term() */
+} /* end H5FD__ros3_term() */
/*-------------------------------------------------------------------------
@@ -400,8 +398,7 @@ H5FD_ros3_term(void)
*-------------------------------------------------------------------------
*/
herr_t
-H5Pset_fapl_ros3(hid_t fapl_id,
- H5FD_ros3_fapl_t *fa)
+H5Pset_fapl_ros3(hid_t fapl_id, H5FD_ros3_fapl_t *fa)
{
H5P_genplist_t *plist = NULL; /* Property list pointer */
herr_t ret_value = FAIL;
@@ -416,25 +413,21 @@ H5Pset_fapl_ros3(hid_t fapl_id,
#endif
plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS);
- if (plist == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, \
- "not a file access property list")
- }
+ if(plist == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list")
- if (FAIL == H5FD_ros3_validate_config(fa)) {
+ if(FAIL == H5FD__ros3_validate_config(fa))
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid ros3 config")
- }
ret_value = H5P_set_driver(plist, H5FD_ROS3, (void *)fa);
done:
FUNC_LEAVE_API(ret_value)
-
} /* end H5Pset_fapl_ros3() */
/*-------------------------------------------------------------------------
- * Function: H5FD_ros3_validate_config()
+ * Function: H5FD__ros3_validate_config()
*
* Purpose: Test to see if the supplied instance of H5FD_ros3_fapl_t
* contains internally consistant data. Return SUCCEED if so,
@@ -454,34 +447,25 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_ros3_validate_config(const H5FD_ros3_fapl_t * fa)
+H5FD__ros3_validate_config(const H5FD_ros3_fapl_t * fa)
{
herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
HDassert(fa != NULL);
- if ( fa->version != H5FD_CURR_ROS3_FAPL_T_VERSION ) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "Unknown H5FD_ros3_fapl_t version");
- }
+ if(fa->version != H5FD_CURR_ROS3_FAPL_T_VERSION)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Unknown H5FD_ros3_fapl_t version");
- /* if set to authenticate, region and id cannot be empty strings
- */
- if (fa->authenticate == TRUE) {
- if ((fa->aws_region[0] == '\0') ||
- (fa->secret_id[0] == '\0'))
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "Inconsistent authentication information");
- }
- }
+ /* if set to authenticate, region and id cannot be empty strings */
+ if(fa->authenticate == TRUE)
+ if((fa->aws_region[0] == '\0') || (fa->secret_id[0] == '\0'))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Inconsistent authentication information");
done:
FUNC_LEAVE_NOAPI(ret_value)
-
-} /* end H5FD_ros3_validate_config() */
+} /* end H5FD__ros3_validate_config() */
/*-------------------------------------------------------------------------
@@ -500,8 +484,7 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5Pget_fapl_ros3(hid_t fapl_id,
- H5FD_ros3_fapl_t *fa_out)
+H5Pget_fapl_ros3(hid_t fapl_id, H5FD_ros3_fapl_t *fa_out)
{
const H5FD_ros3_fapl_t *fa = NULL;
H5P_genplist_t *plist = NULL;
@@ -514,23 +497,19 @@ H5Pget_fapl_ros3(hid_t fapl_id,
HDfprintf(stdout, "H5Pget_fapl_ros3() called.\n");
#endif
- if (fa_out == NULL) {
+ if(fa_out == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "fa_out is NULL")
- }
plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS);
- if (plist == NULL) {
+ if(plist == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access list")
- }
- if (H5FD_ROS3 != H5P_peek_driver(plist)) {
+ if(H5FD_ROS3 != H5P_peek_driver(plist))
HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "incorrect VFL driver")
- }
fa = (const H5FD_ros3_fapl_t *)H5P_peek_driver_info(plist);
- if (fa == NULL) {
+ if(fa == NULL)
HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "bad VFL driver info")
- }
/* Copy the ros3 fapl data out */
HDmemcpy(fa_out, fa, sizeof(H5FD_ros3_fapl_t));
@@ -541,7 +520,7 @@ done:
/*-------------------------------------------------------------------------
- * Function: H5FD_ros3_fapl_get
+ * Function: H5FD__ros3_fapl_get
*
* Purpose: Gets a file access property list which could be used to
* create an identical file.
@@ -556,19 +535,17 @@ done:
*-------------------------------------------------------------------------
*/
static void *
-H5FD_ros3_fapl_get(H5FD_t *_file)
+H5FD__ros3_fapl_get(H5FD_t *_file)
{
H5FD_ros3_t *file = (H5FD_ros3_t*)_file;
H5FD_ros3_fapl_t *fa = NULL;
void *ret_value = NULL;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
fa = (H5FD_ros3_fapl_t *)H5MM_calloc(sizeof(H5FD_ros3_fapl_t));
- if (fa == NULL) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
- "memory allocation failed")
- }
+ if(fa == NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
/* Copy the fields of the structure */
HDmemcpy(fa, &(file->fa), sizeof(H5FD_ros3_fapl_t));
@@ -577,18 +554,16 @@ H5FD_ros3_fapl_get(H5FD_t *_file)
ret_value = fa;
done:
- if (ret_value == NULL) {
- if (fa != NULL) {
+ if(ret_value == NULL)
+ if(fa != NULL)
H5MM_xfree(fa);
- }
- }
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5FD_ros3_fapl_get() */
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5FD__ros3_fapl_get() */
/*-------------------------------------------------------------------------
- * Function: H5FD_ros3_fapl_copy
+ * Function: H5FD__ros3_fapl_copy
*
* Purpose: Copies the ros3-specific file access properties.
*
@@ -602,36 +577,32 @@ done:
*-------------------------------------------------------------------------
*/
static void *
-H5FD_ros3_fapl_copy(const void *_old_fa)
+H5FD__ros3_fapl_copy(const void *_old_fa)
{
const H5FD_ros3_fapl_t *old_fa = (const H5FD_ros3_fapl_t*)_old_fa;
H5FD_ros3_fapl_t *new_fa = NULL;
void *ret_value = NULL;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
new_fa = (H5FD_ros3_fapl_t *)H5MM_malloc(sizeof(H5FD_ros3_fapl_t));
- if (new_fa == NULL) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
- "memory allocation failed");
- }
+ if(new_fa == NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
HDmemcpy(new_fa, old_fa, sizeof(H5FD_ros3_fapl_t));
ret_value = new_fa;
done:
- if (ret_value == NULL) {
- if (new_fa != NULL) {
+ if(ret_value == NULL)
+ if(new_fa != NULL)
H5MM_xfree(new_fa);
- }
- }
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5FD_ros3_fapl_copy() */
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5FD__ros3_fapl_copy() */
/*-------------------------------------------------------------------------
- * Function: H5FD_ros3_fapl_free
+ * Function: H5FD__ros3_fapl_free
*
* Purpose: Frees the ros3-specific file access properties.
*
@@ -643,19 +614,18 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_ros3_fapl_free(void *_fa)
+H5FD__ros3_fapl_free(void *_fa)
{
H5FD_ros3_fapl_t *fa = (H5FD_ros3_fapl_t*)_fa;
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
HDassert(fa != NULL); /* sanity check */
H5MM_xfree(fa);
FUNC_LEAVE_NOAPI(SUCCEED)
-
-} /* end H5FD_ros3_fapl_free() */
+} /* end H5FD__ros3_fapl_free() */
#if ROS3_STATS
/*----------------------------------------------------------------------------
@@ -685,18 +655,16 @@ ros3_reset_stats(H5FD_ros3_t *file)
unsigned i = 0;
herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
#if ROS3_DEBUG
HDprintf("ros3_reset_stats() called\n");
#endif
- if (file == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "file was null");
- }
+ if(file == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "file was null");
- for (i = 0; i <= ROS3_STATS_BIN_COUNT; i++) {
+ for(i = 0; i <= ROS3_STATS_BIN_COUNT; i++) {
file->raw[i].bytes = 0;
file->raw[i].count = 0;
file->raw[i].min = (unsigned long long)ROS3_STATS_STARTING_MIN;
@@ -716,7 +684,7 @@ done:
/*-------------------------------------------------------------------------
*
- * Function: H5FD_ros3_open()
+ * Function: H5FD__ros3_open()
*
* Purpose:
*
@@ -746,11 +714,7 @@ done:
*-------------------------------------------------------------------------
*/
static H5FD_t *
-H5FD_ros3_open(
- const char *url,
- unsigned flags,
- hid_t fapl_id,
- haddr_t maxaddr)
+H5FD__ros3_open(const char *url, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
{
H5FD_ros3_t *file = NULL;
struct tm *now = NULL;
@@ -760,117 +724,89 @@ H5FD_ros3_open(
H5FD_ros3_fapl_t fa;
H5FD_t *ret_value = NULL;
-
-
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
#if ROS3_DEBUG
- HDfprintf(stdout, "H5FD_ros3_open() called.\n");
+ HDfprintf(stdout, "H5FD__ros3_open() called.\n");
#endif
/* Sanity check on file offsets */
HDcompile_assert(sizeof(HDoff_t) >= sizeof(size_t));
/* Check arguments */
- if (!url || !*url)
+ if(!url || !*url)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name")
- if (0 == maxaddr || HADDR_UNDEF == maxaddr)
+ if(0 == maxaddr || HADDR_UNDEF == maxaddr)
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr")
- if (ADDR_OVERFLOW(maxaddr))
+ if(ADDR_OVERFLOW(maxaddr))
HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr")
- if (flags != H5F_ACC_RDONLY)
- HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, NULL,
- "only Read-Only access allowed")
+ if(flags != H5F_ACC_RDONLY)
+ HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, NULL, "only Read-Only access allowed")
- if (FAIL == H5Pget_fapl_ros3(fapl_id, &fa)) {
+ if(FAIL == H5Pget_fapl_ros3(fapl_id, &fa))
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "can't get property list")
- }
- if (CURLE_OK != curl_global_init(CURL_GLOBAL_DEFAULT)) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "unable to initialize curl global (placeholder flags)")
- }
+ if(CURLE_OK != curl_global_init(CURL_GLOBAL_DEFAULT))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "unable to initialize curl global (placeholder flags)")
/* open file; procedure depends on whether or not the fapl instructs to
* authenticate requests or not.
*/
- if (fa.authenticate == TRUE) {
+ if(fa.authenticate == TRUE) {
/* compute signing key (part of AWS/S3 REST API)
* can be re-used by user/key for 7 days after creation.
* find way to re-use/share
*/
now = gmnow();
HDassert( now != NULL );
- if (ISO8601NOW(iso8601now, now) != (ISO8601_SIZE - 1)) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "problem while writing iso8601 timestamp")
- }
- if (FAIL == H5FD_s3comms_signing_key(signing_key,
- (const char *)fa.secret_key,
- (const char *)fa.aws_region,
- (const char *)iso8601now) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "problem while computing signing key")
- }
-
- handle = H5FD_s3comms_s3r_open(
- url,
- (const char *)fa.aws_region,
- (const char *)fa.secret_id,
- (const unsigned char *)signing_key);
- } else {
+ if(ISO8601NOW(iso8601now, now) != (ISO8601_SIZE - 1))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "problem while writing iso8601 timestamp")
+ if(FAIL == H5FD_s3comms_signing_key(signing_key, (const char *)fa.secret_key,
+ (const char *)fa.aws_region, (const char *)iso8601now))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "problem while computing signing key")
+
+ handle = H5FD_s3comms_s3r_open( url, (const char *)fa.aws_region,
+ (const char *)fa.secret_id, (const unsigned char *)signing_key);
+ }
+ else
handle = H5FD_s3comms_s3r_open(url, NULL, NULL, NULL);
- } /* if/else should authenticate */
- if (handle == NULL) {
+ if(handle == NULL)
/* If we want to check CURL's say on the matter in a controlled
* fashion, this is the place to do it, but would need to make a
* few minor changes to s3comms `s3r_t` and `s3r_read()`.
*/
HGOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, NULL, "could not open");
- }
- /* create new file struct
- */
+ /* create new file struct */
file = H5FL_CALLOC(H5FD_ros3_t);
- if (file == NULL) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
- "unable to allocate file struct")
- }
+ if(file == NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate file struct")
file->s3r_handle = handle;
HDmemcpy(&(file->fa), &fa, sizeof(H5FD_ros3_fapl_t));
#if ROS3_STATS
- if (FAIL == ros3_reset_stats(file)) {
- HGOTO_ERROR(H5E_INTERNAL, H5E_UNINITIALIZED, NULL,
- "unable to reset file statistics")
- }
+ if(FAIL == ros3_reset_stats(file))
+ HGOTO_ERROR(H5E_INTERNAL, H5E_UNINITIALIZED, NULL, "unable to reset file statistics")
#endif /* ROS3_STATS */
ret_value = (H5FD_t*)file;
done:
- if (ret_value == NULL) {
- if (handle != NULL) {
- if (FAIL == H5FD_s3comms_s3r_close(handle)) {
- HDONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, NULL,
- "unable to close s3 file handle")
- }
- }
- if (file != NULL) {
+ if(ret_value == NULL) {
+ if(handle != NULL)
+ if(FAIL == H5FD_s3comms_s3r_close(handle))
+ HDONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, NULL, "unable to close s3 file handle")
+ if(file != NULL)
file = H5FL_FREE(H5FD_ros3_t, file);
- }
curl_global_cleanup(); /* early cleanup because open failed */
} /* end if null return value (error) */
FUNC_LEAVE_NOAPI(ret_value)
-
-} /* end H5FD_ros3_open() */
+} /* end H5FD__ros3_open() */
#if ROS3_STATS
-
/*----------------------------------------------------------------------------
*
* Function: ros3_fprint_stats()
@@ -926,8 +862,7 @@ done:
*----------------------------------------------------------------------------
*/
static herr_t
-ros3_fprint_stats(FILE *stream,
- const H5FD_ros3_t *file)
+ros3_fprint_stats(FILE *stream, const H5FD_ros3_t *file)
{
herr_t ret_value = SUCCEED;
parsed_url_t *purl = NULL;
@@ -946,26 +881,16 @@ ros3_fprint_stats(FILE *stream,
unsigned suffix_i = 0;
const char suffixes[] = { ' ', 'K', 'M', 'G', 'T', 'P' };
+ FUNC_ENTER_STATIC
-
- FUNC_ENTER_NOAPI_NOINIT
-
- if (stream == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "file stream cannot be null" );
- }
- if (file == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "file cannot be null");
- }
- if (file->s3r_handle == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "s3 request handle cannot be null");
- }
- if (file->s3r_handle->purl == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "parsed url structure cannot be null");
- }
+ if(stream == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "file stream cannot be null" );
+ if(file == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "file cannot be null");
+ if(file->s3r_handle == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "s3 request handle cannot be null");
+ if(file->s3r_handle->purl == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "parsed url structure cannot be null");
purl = file->s3r_handle->purl;
/******************
@@ -973,9 +898,9 @@ ros3_fprint_stats(FILE *stream,
******************/
HDfprintf(stream, "stats for %s://%s", purl->scheme, purl->host);
- if (purl->port != NULL && purl->port[0] != '\0')
+ if(purl->port != NULL && purl->port[0] != '\0')
HDfprintf(stream, ":%s", purl->port);
- if (purl->query != NULL && purl->query[0] != '\0') {
+ if(purl->query != NULL && purl->query[0] != '\0') {
if (purl->path != NULL && purl->path[0] != '\0')
HDfprintf(stream, "/%s", purl->path);
else
@@ -990,23 +915,27 @@ ros3_fprint_stats(FILE *stream,
* AGGREGATE STATS *
*******************/
- for (i = 0; i <= ROS3_STATS_BIN_COUNT; i++) {
+ for(i = 0; i <= ROS3_STATS_BIN_COUNT; i++) {
const ros3_statsbin *r = &file->raw[i];
const ros3_statsbin *m = &file->meta[i];
- if (m->min < min_meta) min_meta = m->min;
- if (r->min < min_raw) min_raw = r->min;
- if (m->max > max_meta) max_meta = m->max;
- if (r->max > max_raw) max_raw = r->max;
+ if(m->min < min_meta)
+ min_meta = m->min;
+ if(r->min < min_raw)
+ min_raw = r->min;
+ if(m->max > max_meta)
+ max_meta = m->max;
+ if(r->max > max_raw)
+ max_raw = r->max;
count_raw += r->count;
count_meta += m->count;
bytes_raw += r->bytes;
bytes_meta += m->bytes;
}
- if (count_raw > 0)
+ if(count_raw > 0)
average_raw = (double)bytes_raw / (double)count_raw;
- if (count_meta > 0)
+ if(count_meta > 0)
average_meta = (double)bytes_meta / (double)count_meta;
/******************
@@ -1018,7 +947,7 @@ ros3_fprint_stats(FILE *stream,
HDfprintf(stream, "TOTAL BYTES: %llu (%llu meta, %llu raw)\n",
bytes_raw + bytes_meta, bytes_meta, bytes_raw);
- if (count_raw + count_meta == 0)
+ if(count_raw + count_meta == 0)
goto done;
/*************************
@@ -1027,21 +956,21 @@ ros3_fprint_stats(FILE *stream,
HDfprintf(stream, "SIZES meta raw\n");
HDfprintf(stream, " min ");
- if (count_meta == 0) {
+ if(count_meta == 0)
HDfprintf(stream, " 0.000 ");
- } else {
+ else {
re_dub = (double)min_meta;
- for (suffix_i = 0; re_dub >= 1024.0; suffix_i++)
+ for(suffix_i = 0; re_dub >= 1024.0; suffix_i++)
re_dub /= 1024.0;
HDassert(suffix_i < sizeof(suffixes));
HDfprintf(stream, "%8.3lf%c ", re_dub, suffixes[suffix_i]);
}
- if (count_raw == 0) {
+ if(count_raw == 0)
HDfprintf(stream, " 0.000 \n");
- } else {
+ else {
re_dub = (double)min_raw;
- for (suffix_i = 0; re_dub >= 1024.0; suffix_i++)
+ for(suffix_i = 0; re_dub >= 1024.0; suffix_i++)
re_dub /= 1024.0;
HDassert(suffix_i < sizeof(suffixes));
HDfprintf(stream, "%8.3lf%c\n", re_dub, suffixes[suffix_i]);
@@ -1049,26 +978,26 @@ ros3_fprint_stats(FILE *stream,
HDfprintf(stream, " avg ");
re_dub = (double)average_meta;
- for (suffix_i = 0; re_dub >= 1024.0; suffix_i++)
+ for(suffix_i = 0; re_dub >= 1024.0; suffix_i++)
re_dub /= 1024.0;
HDassert(suffix_i < sizeof(suffixes));
HDfprintf(stream, "%8.3lf%c ", re_dub, suffixes[suffix_i]);
re_dub = (double)average_raw;
- for (suffix_i = 0; re_dub >= 1024.0; suffix_i++)
+ for(suffix_i = 0; re_dub >= 1024.0; suffix_i++)
re_dub /= 1024.0;
HDassert(suffix_i < sizeof(suffixes));
HDfprintf(stream, "%8.3lf%c\n", re_dub, suffixes[suffix_i]);
HDfprintf(stream, " max ");
re_dub = (double)max_meta;
- for (suffix_i = 0; re_dub >= 1024.0; suffix_i++)
+ for(suffix_i = 0; re_dub >= 1024.0; suffix_i++)
re_dub /= 1024.0;
HDassert(suffix_i < sizeof(suffixes));
HDfprintf(stream, "%8.3lf%c ", re_dub, suffixes[suffix_i]);
re_dub = (double)max_raw;
- for (suffix_i = 0; re_dub >= 1024.0; suffix_i++)
+ for(suffix_i = 0; re_dub >= 1024.0; suffix_i++)
re_dub /= 1024.0;
HDassert(suffix_i < sizeof(suffixes));
HDfprintf(stream, "%8.3lf%c\n", re_dub, suffixes[suffix_i]);
@@ -1082,7 +1011,7 @@ ros3_fprint_stats(FILE *stream,
HDfprintf(stream,
" up-to meta raw meta raw meta raw\n");
- for (i = 0; i <= ROS3_STATS_BIN_COUNT; i++) {
+ for(i = 0; i <= ROS3_STATS_BIN_COUNT; i++) {
const ros3_statsbin *m;
const ros3_statsbin *r;
unsigned long long range_end = 0;
@@ -1097,46 +1026,46 @@ ros3_fprint_stats(FILE *stream,
m = &file->meta[i];
r = &file->raw[i];
- if (r->count == 0 && m->count == 0)
+ if(r->count == 0 && m->count == 0)
continue;
range_end = ros3_stats_boundaries[i];
- if (i == ROS3_STATS_BIN_COUNT) {
+ if(i == ROS3_STATS_BIN_COUNT) {
range_end = ros3_stats_boundaries[i-1];
HDfprintf(stream, ">");
- } else {
- HDfprintf(stream, " ");
}
+ else
+ HDfprintf(stream, " ");
bm_val = (double)m->bytes;
- for (suffix_i = 0; bm_val >= 1024.0; suffix_i++)
+ for(suffix_i = 0; bm_val >= 1024.0; suffix_i++)
bm_val /= 1024.0;
HDassert(suffix_i < sizeof(suffixes));
bm_suffix = suffixes[suffix_i];
br_val = (double)r->bytes;
- for (suffix_i = 0; br_val >= 1024.0; suffix_i++)
+ for(suffix_i = 0; br_val >= 1024.0; suffix_i++)
br_val /= 1024.0;
HDassert(suffix_i < sizeof(suffixes));
br_suffix = suffixes[suffix_i];
- if (m->count > 0)
+ if(m->count > 0)
am_val = (double)(m->bytes) / (double)(m->count);
- for (suffix_i = 0; am_val >= 1024.0; suffix_i++)
+ for(suffix_i = 0; am_val >= 1024.0; suffix_i++)
am_val /= 1024.0;
HDassert(suffix_i < sizeof(suffixes));
am_suffix = suffixes[suffix_i];
- if (r->count > 0)
+ if(r->count > 0)
ar_val = (double)(r->bytes) / (double)(r->count);
- for (suffix_i = 0; ar_val >= 1024.0; suffix_i++)
+ for(suffix_i = 0; ar_val >= 1024.0; suffix_i++)
ar_val /= 1024.0;
HDassert(suffix_i < sizeof(suffixes));
ar_suffix = suffixes[suffix_i];
re_dub = (double)range_end;
- for (suffix_i = 0; re_dub >= 1024.0; suffix_i++)
+ for(suffix_i = 0; re_dub >= 1024.0; suffix_i++)
re_dub /= 1024.0;
HDassert(suffix_i < sizeof(suffixes));
@@ -1150,7 +1079,7 @@ ros3_fprint_stats(FILE *stream,
am_val, am_suffix, /* metadata average */
ar_val, ar_suffix); /* rawdata average */
- fflush(stream);
+ HDfflush(stream);
}
done:
@@ -1162,7 +1091,7 @@ done:
/*-------------------------------------------------------------------------
*
- * Function: H5FD_ros3_close()
+ * Function: H5FD__ros3_close()
*
* Purpose:
*
@@ -1178,52 +1107,45 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_ros3_close(H5FD_t H5_ATTR_UNUSED *_file)
+H5FD__ros3_close(H5FD_t H5_ATTR_UNUSED *_file)
{
H5FD_ros3_t *file = (H5FD_ros3_t *)_file;
herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
#if ROS3_DEBUG
- HDfprintf(stdout, "H5FD_ros3_close() called.\n");
+ HDfprintf(stdout, "H5FD__ros3_close() called.\n");
#endif
- /* Sanity checks
- */
+ /* Sanity checks */
HDassert(file != NULL);
HDassert(file->s3r_handle != NULL);
/* Close the underlying request handle
*/
- if (FAIL == H5FD_s3comms_s3r_close(file->s3r_handle)) {
- HGOTO_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL,
- "unable to close S3 request handle")
- }
+ if(FAIL == H5FD_s3comms_s3r_close(file->s3r_handle))
+ HGOTO_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL, "unable to close S3 request handle")
#if ROS3_STATS
/* TODO: mechanism to re-target stats printout */
- if (ros3_fprint_stats(stdout, file) == FAIL) {
- HGOTO_ERROR(H5E_INTERNAL, H5E_ERROR, FAIL,
- "problem while writing file statistics")
- }
+ if(ros3_fprint_stats(stdout, file) == FAIL)
+ HGOTO_ERROR(H5E_INTERNAL, H5E_ERROR, FAIL, "problem while writing file statistics")
#endif /* ROS3_STATS */
- /* Release the file info
- */
+ /* Release the file info */
file = H5FL_FREE(H5FD_ros3_t, file);
done:
curl_global_cleanup(); /* cleanup to answer init on open */
FUNC_LEAVE_NOAPI(ret_value)
-
-} /* end H5FD_ros3_close() */
+} /* end H5FD__ros3_close() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_ros3_cmp()
+ * Function: H5FD__ros3_cmp()
*
* Purpose:
*
@@ -1252,9 +1174,7 @@ done:
*-------------------------------------------------------------------------
*/
static int
-H5FD_ros3_cmp(
- const H5FD_t *_f1,
- const H5FD_t *_f2)
+H5FD__ros3_cmp(const H5FD_t *_f1, const H5FD_t *_f2)
{
const H5FD_ros3_t *f1 = (const H5FD_ros3_t *)_f1;
const H5FD_ros3_t *f2 = (const H5FD_ros3_t *)_f2;
@@ -1262,10 +1182,10 @@ H5FD_ros3_cmp(
const parsed_url_t *purl2 = NULL;
int ret_value = 0;
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
#if ROS3_DEBUG
- HDfprintf(stdout, "H5FD_ros3_cmp() called.\n");
+ HDfprintf(stdout, "H5FD__ros3_cmp() called.\n");
#endif
HDassert(f1->s3r_handle != NULL);
@@ -1281,113 +1201,80 @@ H5FD_ros3_cmp(
HDassert(purl2->host != NULL);
/* URL: SCHEME */
- if (HDstrcmp(purl1->scheme, purl2->scheme)) {
- HGOTO_DONE(-1);
- }
+ if(HDstrcmp(purl1->scheme, purl2->scheme))
+ HGOTO_DONE(-1)
/* URL: HOST */
- if (HDstrcmp(purl1->host, purl2->host)) {
- HGOTO_DONE(-1);
- }
+ if(HDstrcmp(purl1->host, purl2->host))
+ HGOTO_DONE(-1)
/* URL: PORT */
- if (purl1->port && purl2->port) {
- if (HDstrcmp(purl1->port, purl2->port)) {
- HGOTO_DONE(-1);
- }
- }
- else
- if (purl1->port) {
- HGOTO_DONE(-1);
- }
- else
- if (purl2->port) {
- HGOTO_DONE(-1);
+ if(purl1->port && purl2->port) {
+ if(HDstrcmp(purl1->port, purl2->port))
+ HGOTO_DONE(-1)
}
+ else if(purl1->port)
+ HGOTO_DONE(-1)
+ else if(purl2->port)
+ HGOTO_DONE(-1)
/* URL: PATH */
- if (purl1->path && purl2->path) {
- if (HDstrcmp(purl1->path, purl2->path)) {
- HGOTO_DONE(-1);
- }
- }
- else
- if (purl1->path && !purl2->path) {
- HGOTO_DONE(-1);
- }
- else
- if (purl2->path && !purl1->path) {
- HGOTO_DONE(-1);
+ if(purl1->path && purl2->path) {
+ if(HDstrcmp(purl1->path, purl2->path))
+ HGOTO_DONE(-1)
}
+ else if(purl1->path && !purl2->path)
+ HGOTO_DONE(-1)
+ else if(purl2->path && !purl1->path)
+ HGOTO_DONE(-1)
/* URL: QUERY */
- if (purl1->query && purl2->query) {
- if (HDstrcmp(purl1->query, purl2->query)) {
- HGOTO_DONE(-1);
- }
- }
- else
- if (purl1->query && !purl2->query) {
- HGOTO_DONE(-1);
- }
- else
- if (purl2->query && !purl1->query) {
- HGOTO_DONE(-1);
+ if(purl1->query && purl2->query) {
+ if(HDstrcmp(purl1->query, purl2->query))
+ HGOTO_DONE(-1)
}
+ else if(purl1->query && !purl2->query)
+ HGOTO_DONE(-1)
+ else if(purl2->query && !purl1->query)
+ HGOTO_DONE(-1)
/* FAPL: AWS_REGION */
- if (f1->fa.aws_region[0] != '\0' && f2->fa.aws_region[0] != '\0') {
- if (HDstrcmp(f1->fa.aws_region, f2->fa.aws_region)) {
- HGOTO_DONE(-1);
- }
- }
- else
- if (f1->fa.aws_region[0] != '\0') {
- HGOTO_DONE(-1);
- }
- else
- if (f2->fa.aws_region[0] != '\0') {
- HGOTO_DONE(-1);
+ if(f1->fa.aws_region[0] != '\0' && f2->fa.aws_region[0] != '\0') {
+ if(HDstrcmp(f1->fa.aws_region, f2->fa.aws_region))
+ HGOTO_DONE(-1)
}
+ else if(f1->fa.aws_region[0] != '\0')
+ HGOTO_DONE(-1)
+ else if(f2->fa.aws_region[0] != '\0')
+ HGOTO_DONE(-1)
/* FAPL: SECRET_ID */
- if (f1->fa.secret_id[0] != '\0' && f2->fa.secret_id[0] != '\0') {
- if (HDstrcmp(f1->fa.secret_id, f2->fa.secret_id)) {
- HGOTO_DONE(-1);
- }
- }
- else
- if (f1->fa.secret_id[0] != '\0') {
- HGOTO_DONE(-1);
- }
- else
- if (f2->fa.secret_id[0] != '\0') {
- HGOTO_DONE(-1);
+ if(f1->fa.secret_id[0] != '\0' && f2->fa.secret_id[0] != '\0') {
+ if(HDstrcmp(f1->fa.secret_id, f2->fa.secret_id))
+ HGOTO_DONE(-1)
}
+ else if(f1->fa.secret_id[0] != '\0')
+ HGOTO_DONE(-1)
+ else if(f2->fa.secret_id[0] != '\0')
+ HGOTO_DONE(-1)
/* FAPL: SECRET_KEY */
- if (f1->fa.secret_key[0] != '\0' && f2->fa.secret_key[0] != '\0') {
- if (HDstrcmp(f1->fa.secret_key, f2->fa.secret_key)) {
- HGOTO_DONE(-1);
- }
- }
- else
- if (f1->fa.secret_key[0] != '\0') {
- HGOTO_DONE(-1);
- }
- else
- if (f2->fa.secret_key[0] != '\0') {
- HGOTO_DONE(-1);
+ if(f1->fa.secret_key[0] != '\0' && f2->fa.secret_key[0] != '\0') {
+ if(HDstrcmp(f1->fa.secret_key, f2->fa.secret_key))
+ HGOTO_DONE(-1)
}
+ else if(f1->fa.secret_key[0] != '\0')
+ HGOTO_DONE(-1)
+ else if(f2->fa.secret_key[0] != '\0')
+ HGOTO_DONE(-1)
done:
FUNC_LEAVE_NOAPI(ret_value)
-
-} /* H5FD_ros3_cmp() */
+} /* H5FD__ros3_cmp() */
/*-------------------------------------------------------------------------
- * Function: H5FD_ros3_query
+ * Function: H5FD__ros3_query
*
* Purpose: Set the flags that this VFL driver is capable of supporting.
* (listed in H5FDpublic.h)
@@ -1406,30 +1293,28 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_ros3_query(const H5FD_t H5_ATTR_UNUSED *_file,
- unsigned long *flags /* out */)
+H5FD__ros3_query(const H5FD_t H5_ATTR_UNUSED *_file, unsigned long *flags)
{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
#if ROS3_DEBUG
- HDfprintf(stdout, "H5FD_ros3_query() called.\n");
+ HDfprintf(stdout, "H5FD__ros3_query() called.\n");
#endif
/* Set the VFL feature flags that this driver supports */
- if (flags) {
+ if(flags) {
*flags = 0;
/* OK to perform data sieving for faster raw data reads & writes */
*flags |= H5FD_FEAT_DATA_SIEVE;
} /* end if */
FUNC_LEAVE_NOAPI(SUCCEED)
-
-} /* H5FD_ros3_query() */
+} /* H5FD__ros3_query() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_ros3_get_eoa()
+ * Function: H5FD__ros3_get_eoa()
*
* Purpose:
*
@@ -1447,25 +1332,23 @@ H5FD_ros3_query(const H5FD_t H5_ATTR_UNUSED *_file,
*-------------------------------------------------------------------------
*/
static haddr_t
-H5FD_ros3_get_eoa(const H5FD_t *_file,
- H5FD_mem_t H5_ATTR_UNUSED type)
+H5FD__ros3_get_eoa(const H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type)
{
const H5FD_ros3_t *file = (const H5FD_ros3_t *)_file;
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
#if ROS3_DEBUG
- HDfprintf(stdout, "H5FD_ros3_get_eoa() called.\n");
+ HDfprintf(stdout, "H5FD__ros3_get_eoa() called.\n");
#endif
FUNC_LEAVE_NOAPI(file->eoa)
-
-} /* end H5FD_ros3_get_eoa() */
+} /* end H5FD__ros3_get_eoa() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_ros3_set_eoa()
+ * Function: H5FD__ros3_set_eoa()
*
* Purpose:
*
@@ -1481,28 +1364,25 @@ H5FD_ros3_get_eoa(const H5FD_t *_file,
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_ros3_set_eoa(H5FD_t *_file,
- H5FD_mem_t H5_ATTR_UNUSED type,
- haddr_t addr)
+H5FD__ros3_set_eoa(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, haddr_t addr)
{
H5FD_ros3_t *file = (H5FD_ros3_t *)_file;
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
#if ROS3_DEBUG
- HDfprintf(stdout, "H5FD_ros3_set_eoa() called.\n");
+ HDfprintf(stdout, "H5FD__ros3_set_eoa() called.\n");
#endif
file->eoa = addr;
FUNC_LEAVE_NOAPI(SUCCEED)
-
-} /* H5FD_ros3_set_eoa() */
+} /* H5FD__ros3_set_eoa() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_ros3_get_eof()
+ * Function: H5FD__ros3_get_eof()
*
* Purpose:
*
@@ -1519,25 +1399,23 @@ H5FD_ros3_set_eoa(H5FD_t *_file,
*-------------------------------------------------------------------------
*/
static haddr_t
-H5FD_ros3_get_eof(const H5FD_t *_file,
- H5FD_mem_t H5_ATTR_UNUSED type)
+H5FD__ros3_get_eof(const H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type)
{
const H5FD_ros3_t *file = (const H5FD_ros3_t *)_file;
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_STATIC_NOERR
#if ROS3_DEBUG
- HDfprintf(stdout, "H5FD_ros3_get_eof() called.\n");
+ HDfprintf(stdout, "H5FD__ros3_get_eof() called.\n");
#endif
FUNC_LEAVE_NOAPI(H5FD_s3comms_s3r_get_filesize(file->s3r_handle))
-
-} /* end H5FD_ros3_get_eof() */
+} /* end H5FD__ros3_get_eof() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_ros3_get_handle()
+ * Function: H5FD__ros3_get_handle()
*
* Purpose:
*
@@ -1553,34 +1431,31 @@ H5FD_ros3_get_eof(const H5FD_t *_file,
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_ros3_get_handle(H5FD_t *_file,
- hid_t H5_ATTR_UNUSED fapl,
- void **file_handle)
+H5FD__ros3_get_handle(H5FD_t *_file, hid_t H5_ATTR_UNUSED fapl,
+ void **file_handle)
{
H5FD_ros3_t *file = (H5FD_ros3_t *)_file;
herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
#if ROS3_DEBUG
- HDfprintf(stdout, "H5FD_ros3_get_handle() called.\n");
+ HDfprintf(stdout, "H5FD__ros3_get_handle() called.\n");
#endif
- if (!file_handle) {
+ if(!file_handle)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "file handle not valid")
- }
*file_handle = file->s3r_handle;
done:
FUNC_LEAVE_NOAPI(ret_value)
-
-} /* end H5FD_ros3_get_handle() */
+} /* end H5FD__ros3_get_handle() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_ros3_read()
+ * Function: H5FD__ros3_read()
*
* Purpose
*
@@ -1601,12 +1476,9 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_ros3_read(H5FD_t *_file,
- H5FD_mem_t H5_ATTR_UNUSED type,
- hid_t H5_ATTR_UNUSED dxpl_id,
- haddr_t addr, /* start offset */
- size_t size, /* length of read */
- void *buf) /* out */
+H5FD__ros3_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type,
+ hid_t H5_ATTR_UNUSED dxpl_id, haddr_t addr, size_t size,
+ void *buf)
{
H5FD_ros3_t *file = (H5FD_ros3_t *)_file;
size_t filesize = 0;
@@ -1618,10 +1490,10 @@ H5FD_ros3_read(H5FD_t *_file,
#endif /* ROS3_STATS */
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
#if ROS3_DEBUG
- HDfprintf(stdout, "H5FD_ros3_read() called.\n");
+ HDfprintf(stdout, "H5FD__ros3_read() called.\n");
#endif
HDassert(file != NULL);
@@ -1630,40 +1502,32 @@ H5FD_ros3_read(H5FD_t *_file,
filesize = H5FD_s3comms_s3r_get_filesize(file->s3r_handle);
- if ((addr > filesize) || ((addr + size) > filesize)) {
+ if((addr > filesize) || ((addr + size) > filesize))
HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "range exceeds file address")
- }
- if (H5FD_s3comms_s3r_read(file->s3r_handle, addr, size, buf) == FAIL) {
+ if(H5FD_s3comms_s3r_read(file->s3r_handle, addr, size, buf) == FAIL)
HGOTO_ERROR(H5E_VFL, H5E_READERROR, FAIL, "unable to execute read")
- }
#if ROS3_STATS
- /* Find which "bin" this read fits in. Can be "overflow" bin.
- */
- for (bin_i = 0; bin_i < ROS3_STATS_BIN_COUNT; bin_i++) {
- if ((unsigned long long)size < ros3_stats_boundaries[bin_i]) {
+ /* Find which "bin" this read fits in. Can be "overflow" bin. */
+ for(bin_i = 0; bin_i < ROS3_STATS_BIN_COUNT; bin_i++)
+ if((unsigned long long)size < ros3_stats_boundaries[bin_i])
break;
- }
- }
bin = (type == H5FD_MEM_DRAW)
? &file->raw[bin_i]
: &file->meta[bin_i];
- /* Store collected stats in appropriate bin
- */
- if (bin->count == 0) {
+ /* Store collected stats in appropriate bin */
+ if(bin->count == 0) {
bin->min = size;
bin->max = size;
}
else {
- if (size < bin->min) {
+ if(size < bin->min)
bin->min = size;
- }
- if (size > bin->max) {
+ if(size > bin->max)
bin->max = size;
- }
}
bin->count++;
bin->bytes += (unsigned long long)size;
@@ -1672,13 +1536,12 @@ H5FD_ros3_read(H5FD_t *_file,
done:
FUNC_LEAVE_NOAPI(ret_value)
-
-} /* end H5FD_ros3_read() */
+} /* end H5FD__ros3_read() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_ros3_write()
+ * Function: H5FD__ros3_write()
*
* Purpose:
*
@@ -1695,33 +1558,28 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_ros3_write(H5FD_t H5_ATTR_UNUSED *_file,
- H5FD_mem_t H5_ATTR_UNUSED type,
- hid_t H5_ATTR_UNUSED dxpl_id,
- haddr_t H5_ATTR_UNUSED addr,
- size_t H5_ATTR_UNUSED size,
- const void H5_ATTR_UNUSED *buf)
+H5FD__ros3_write(H5FD_t H5_ATTR_UNUSED *_file, H5FD_mem_t H5_ATTR_UNUSED type,
+ hid_t H5_ATTR_UNUSED dxpl_id, haddr_t H5_ATTR_UNUSED addr,
+ size_t H5_ATTR_UNUSED size, const void H5_ATTR_UNUSED *buf)
{
herr_t ret_value = FAIL;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
#if ROS3_DEBUG
- HDfprintf(stdout, "H5FD_ros3_write() called.\n");
+ HDfprintf(stdout, "H5FD__ros3_write() called.\n");
#endif
- HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL,
- "cannot write to read-only file.")
+ HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL, "cannot write to read-only file.")
done:
FUNC_LEAVE_NOAPI(ret_value)
-
-} /* H5FD_ros3_write() */
+} /* H5FD__ros3_write() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_ros3_truncate()
+ * Function: H5FD__ros3_truncate()
*
* Purpose:
*
@@ -1740,30 +1598,27 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_ros3_truncate(H5FD_t H5_ATTR_UNUSED *_file,
- hid_t H5_ATTR_UNUSED dxpl_id,
- hbool_t H5_ATTR_UNUSED closing)
+H5FD__ros3_truncate(H5FD_t H5_ATTR_UNUSED *_file, hid_t H5_ATTR_UNUSED dxpl_id,
+ hbool_t H5_ATTR_UNUSED closing)
{
herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
#if ROS3_DEBUG
- HDfprintf(stdout, "H5FD_ros3_truncate() called.\n");
+ HDfprintf(stdout, "H5FD__ros3_truncate() called.\n");
#endif
- HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL,
- "cannot truncate read-only file.")
+ HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL, "cannot truncate read-only file.")
done:
FUNC_LEAVE_NOAPI(ret_value)
-
-} /* end H5FD_ros3_truncate() */
+} /* end H5FD__ros3_truncate() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_ros3_lock()
+ * Function: H5FD__ros3_lock()
*
* Purpose:
*
@@ -1783,18 +1638,18 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_ros3_lock(H5FD_t H5_ATTR_UNUSED *_file,
+H5FD__ros3_lock(H5FD_t H5_ATTR_UNUSED *_file,
hbool_t H5_ATTR_UNUSED rw)
{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
- FUNC_LEAVE_NOAPI(SUCCEED)
+ FUNC_ENTER_STATIC_NOERR
-} /* end H5FD_ros3_lock() */
+ FUNC_LEAVE_NOAPI(SUCCEED)
+} /* end H5FD__ros3_lock() */
/*-------------------------------------------------------------------------
*
- * Function: H5FD_ros3_unlock()
+ * Function: H5FD__ros3_unlock()
*
* Purpose:
*
@@ -1811,12 +1666,12 @@ H5FD_ros3_lock(H5FD_t H5_ATTR_UNUSED *_file,
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_ros3_unlock(H5FD_t H5_ATTR_UNUSED *_file)
+H5FD__ros3_unlock(H5FD_t H5_ATTR_UNUSED *_file)
{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
- FUNC_LEAVE_NOAPI(SUCCEED)
+ FUNC_ENTER_STATIC_NOERR
-} /* end H5FD_ros3_unlock() */
+ FUNC_LEAVE_NOAPI(SUCCEED)
+} /* end H5FD__ros3_unlock() */
#endif /* H5_HAVE_ROS3_VFD */
diff --git a/src/H5FDs3comms.c b/src/H5FDs3comms.c
index d9d4c88..4c762d1 100644
--- a/src/H5FDs3comms.c
+++ b/src/H5FDs3comms.c
@@ -148,9 +148,8 @@ curlwritecallback(char *ptr,
size_t product = (size * nmemb);
size_t written = 0;
- if (sds->magic != S3COMMS_CALLBACK_DATASTRUCT_MAGIC) {
+ if(sds->magic != S3COMMS_CALLBACK_DATASTRUCT_MAGIC)
return written;
- }
if (size > 0) {
HDmemcpy(&(sds->data[sds->size]), ptr, product);
@@ -159,7 +158,6 @@ curlwritecallback(char *ptr,
}
return written;
-
} /* end curlwritecallback() */
@@ -236,22 +234,19 @@ H5FD_s3comms_hrb_node_set(
FUNC_ENTER_NOAPI_NOINIT
#if S3COMMS_DEBUG
- HDfprintf(stdout, "called H5FD_s3comms_hrb_node_set.\n");
+ HDfprintf(stdout, "called H5FD_s3comms_hrb_node_set.");
HDprintf("NAME: %s\n", name);
HDprintf("VALUE: %s\n", value);
HDprintf("LIST:\n->");
- for (node_ptr = (*L); node_ptr != NULL; node_ptr = node_ptr->next) {
+ for(node_ptr = (*L); node_ptr != NULL; node_ptr = node_ptr->next)
HDfprintf(stdout, "{%s}\n->", node_ptr->cat);
- }
HDprintf("(null)\n");
- fflush(stdout);
+ HDfflush(stdout);
node_ptr = NULL;
#endif
- if (name == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to operate on null name.\n");
- }
+ if(name == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to operate on null name");
namelen = HDstrlen(name);
/***********************
@@ -261,20 +256,17 @@ H5FD_s3comms_hrb_node_set(
/* copy and lowercase name
*/
lowername = (char *)H5MM_malloc(sizeof(char) * (namelen + 1));
- if (lowername == NULL) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "cannot make space for lowercase name copy.\n");
- }
- for (i = 0; i < namelen; i++) {
- lowername[i] = (char)tolower((int)name[i]);
- }
+ if(lowername == NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "cannot make space for lowercase name copy.");
+ for(i = 0; i < namelen; i++)
+ lowername[i] = (char)HDtolower((int)name[i]);
lowername[namelen] = 0;
/* If value supplied, copy name, value, and concatenated "name: value".
* If NULL, we will be removing a node or doing nothing, so no need for
* copies
*/
- if (value != NULL) {
+ if(value != NULL) {
int ret = 0;
size_t valuelen = HDstrlen(value);
size_t catlen = namelen + valuelen + 2; /* +2 from ": " */
@@ -282,38 +274,28 @@ H5FD_s3comms_hrb_node_set(
namecpy = (char *)H5MM_malloc(sizeof(char) * (namelen + 1));
- if (namecpy == NULL) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "cannot make space for name copy.\n");
- }
+ if(namecpy == NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "cannot make space for name copy.");
HDmemcpy(namecpy, name, (namelen + 1));
valuecpy = (char *)H5MM_malloc(sizeof(char) * (valuelen + 1));
- if (valuecpy == NULL) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "cannot make space for value copy.\n");
- }
+ if(valuecpy == NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "cannot make space for value copy.");
HDmemcpy(valuecpy, value, (valuelen + 1));
nvcat = (char *)H5MM_malloc(sizeof(char) * catwrite);
- if (nvcat == NULL) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "cannot make space for concatenated string.\n");
- }
+ if(nvcat == NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "cannot make space for concatenated string.");
ret = HDsnprintf(nvcat, catwrite, "%s: %s", name, value);
- if (ret < 0 || (size_t)ret > catlen) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "cannot concatenate `%s: %s", name, value);
- }
+ if(ret < 0 || (size_t)ret > catlen)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "cannot concatenate `%s: %s", name, value);
HDassert( catlen == HDstrlen(nvcat) );
/* create new_node, should we need it
*/
new_node = (hrb_node_t *)H5MM_malloc(sizeof(hrb_node_t));
- if (new_node == NULL) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "cannot make space for new set.\n");
- }
+ if(new_node == NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "cannot make space for new set.");
new_node->magic = S3COMMS_HRB_NODE_MAGIC;
new_node->name = NULL;
@@ -327,14 +309,12 @@ H5FD_s3comms_hrb_node_set(
* ACT ON LIST *
***************/
- if (*L == NULL) {
- if (value == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "trying to remove node from empty list");
- }
+ if(*L == NULL) {
+ if(value == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "trying to remove node from empty list")
else {
#if S3COMMS_DEBUG
-HDprintf("CREATE NEW\n"); fflush(stdout);
+HDprintf("CREATE NEW\n"); HDfflush(stdout);
#endif
/*******************
* CREATE NEW LIST *
@@ -358,13 +338,13 @@ HDprintf("CREATE NEW\n"); fflush(stdout);
/* Check whether to modify/remove first node in list
*/
- if (strcmp(lowername, node_ptr->lowername) == 0) {
+ if(HDstrcmp(lowername, node_ptr->lowername) == 0) {
is_looking = FALSE;
if (value == NULL) {
#if S3COMMS_DEBUG
-HDprintf("REMOVE HEAD\n"); fflush(stdout);
+HDprintf("REMOVE HEAD\n"); HDfflush(stdout);
#endif
/***************
* REMOVE HEAD *
@@ -373,41 +353,41 @@ HDprintf("REMOVE HEAD\n"); fflush(stdout);
*L = node_ptr->next;
#if S3COMMS_DEBUG
-HDprintf("FREEING CAT (node)\n"); fflush(stdout);
+HDprintf("FREEING CAT (node)\n"); HDfflush(stdout);
#endif
H5MM_xfree(node_ptr->cat);
#if S3COMMS_DEBUG
-HDprintf("FREEING LOWERNAME (node)\n"); fflush(stdout);
+HDprintf("FREEING LOWERNAME (node)\n"); HDfflush(stdout);
#endif
H5MM_xfree(node_ptr->lowername);
#if S3COMMS_DEBUG
-HDprintf("FREEING NAME (node)\n"); fflush(stdout);
+HDprintf("FREEING NAME (node)\n"); HDfflush(stdout);
#endif
H5MM_xfree(node_ptr->name);
#if S3COMMS_DEBUG
-HDprintf("FREEING VALUE (node)\n"); fflush(stdout);
+HDprintf("FREEING VALUE (node)\n"); HDfflush(stdout);
#endif
H5MM_xfree(node_ptr->value);
#if S3COMMS_DEBUG
HDprintf("MAGIC OK? %s\n",
(node_ptr->magic == S3COMMS_HRB_NODE_MAGIC) ? "YES" : "NO");
-fflush(stdout);
+HDfflush(stdout);
#endif
HDassert( node_ptr->magic == S3COMMS_HRB_NODE_MAGIC );
node_ptr->magic += 1ul;
#if S3COMMS_DEBUG
-HDprintf("FREEING POINTER\n"); fflush(stdout);
+HDprintf("FREEING POINTER\n"); HDfflush(stdout);
#endif
H5MM_xfree(node_ptr);
#if S3COMMS_DEBUG
-HDprintf("FREEING WORKING LOWERNAME\n"); fflush(stdout);
+HDprintf("FREEING WORKING LOWERNAME\n"); HDfflush(stdout);
#endif
H5MM_xfree(lowername); lowername = NULL;
}
else {
#if S3COMMS_DEBUG
-HDprintf("MODIFY HEAD\n"); fflush(stdout);
+HDprintf("MODIFY HEAD\n"); HDfflush(stdout);
#endif
/***************
* MODIFY HEAD *
@@ -429,17 +409,15 @@ HDprintf("MODIFY HEAD\n"); fflush(stdout);
}
}
else
- if (strcmp(lowername, node_ptr->lowername) < 0) {
+ if (HDstrcmp(lowername, node_ptr->lowername) < 0) {
is_looking = FALSE;
- if (value == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "trying to remove a node 'before' head");
- }
+ if(value == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "trying to remove a node 'before' head")
else {
#if S3COMMS_DEBUG
-HDprintf("PREPEND NEW HEAD\n"); fflush(stdout);
+HDprintf("PREPEND NEW HEAD\n"); HDfflush(stdout);
#endif
/*******************
* INSERT NEW HEAD *
@@ -458,24 +436,22 @@ HDprintf("PREPEND NEW HEAD\n"); fflush(stdout);
* SEARCH LIST *
***************/
- while (is_looking) {
- if (node_ptr->next == NULL) {
+ while(is_looking) {
+ if(node_ptr->next == NULL) {
is_looking = FALSE;
- if (value == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "trying to remove absent node");
- }
+ if(value == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "trying to remove absent node")
else {
#if S3COMMS_DEBUG
-HDprintf("APPEND A NODE\n"); fflush(stdout);
+HDprintf("APPEND A NODE\n"); HDfflush(stdout);
#endif
/*******************
* APPEND NEW NODE *
*******************/
- HDassert( strcmp(lowername, node_ptr->lowername) > 0 );
+ HDassert( HDstrcmp(lowername, node_ptr->lowername) > 0 );
new_node->name = namecpy;
new_node->value = valuecpy;
new_node->lowername = lowername;
@@ -484,23 +460,21 @@ HDprintf("APPEND A NODE\n"); fflush(stdout);
}
}
else
- if (strcmp(lowername, node_ptr->next->lowername) < 0) {
+ if(HDstrcmp(lowername, node_ptr->next->lowername) < 0) {
is_looking = FALSE;
- if (value == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "trying to remove absent node");
- }
+ if(value == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "trying to remove absent node")
else {
#if S3COMMS_DEBUG
-HDprintf("INSERT A NODE\n"); fflush(stdout);
+HDprintf("INSERT A NODE\n"); HDfflush(stdout);
#endif
/*******************
* INSERT NEW NODE *
*******************/
- HDassert( strcmp(lowername, node_ptr->lowername) > 0 );
+ HDassert( HDstrcmp(lowername, node_ptr->lowername) > 0 );
new_node->name = namecpy;
new_node->value = valuecpy;
new_node->lowername = lowername;
@@ -510,11 +484,11 @@ HDprintf("INSERT A NODE\n"); fflush(stdout);
}
}
else
- if (strcmp(lowername, node_ptr->next->lowername) == 0) {
+ if(HDstrcmp(lowername, node_ptr->next->lowername) == 0) {
is_looking = FALSE;
- if (value == NULL) {
+ if(value == NULL) {
/*****************
* REMOVE A NODE *
*****************/
@@ -523,7 +497,7 @@ HDprintf("INSERT A NODE\n"); fflush(stdout);
node_ptr->next = tmp->next;
#if S3COMMS_DEBUG
-HDprintf("REMOVE A NODE\n"); fflush(stdout);
+HDprintf("REMOVE A NODE\n"); HDfflush(stdout);
#endif
H5MM_xfree(tmp->cat);
H5MM_xfree(tmp->lowername);
@@ -539,7 +513,7 @@ HDprintf("REMOVE A NODE\n"); fflush(stdout);
}
else {
#if S3COMMS_DEBUG
-HDprintf("MODIFY A NODE\n"); fflush(stdout);
+HDprintf("MODIFY A NODE\n"); HDfflush(stdout);
#endif
/*****************
* MODIFY A NODE *
@@ -572,14 +546,17 @@ HDprintf("MODIFY A NODE\n"); fflush(stdout);
} /* end while is_looking */
done:
- if (ret_value == FAIL) {
- /* clean up
- */
- if (nvcat != NULL) { H5MM_xfree(nvcat); }
- if (namecpy != NULL) { H5MM_xfree(namecpy); }
- if (lowername != NULL) { H5MM_xfree(lowername); }
- if (valuecpy != NULL) { H5MM_xfree(valuecpy); }
- if (new_node != NULL) {
+ if(ret_value == FAIL) {
+ /* clean up */
+ if(nvcat != NULL)
+ H5MM_xfree(nvcat);
+ if(namecpy != NULL)
+ H5MM_xfree(namecpy);
+ if(lowername != NULL)
+ H5MM_xfree(lowername);
+ if(valuecpy != NULL)
+ H5MM_xfree(valuecpy);
+ if(new_node != NULL) {
HDassert( new_node->magic == S3COMMS_HRB_NODE_MAGIC );
new_node->magic += 1ul;
H5MM_xfree(new_node);
@@ -638,12 +615,10 @@ H5FD_s3comms_hrb_destroy(hrb_t **_buf)
HDfprintf(stdout, "called H5FD_s3comms_hrb_destroy.\n");
#endif
- if (_buf != NULL && *_buf != NULL) {
+ if(_buf != NULL && *_buf != NULL) {
buf = *_buf;
- if (buf->magic != S3COMMS_HRB_MAGIC) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "pointer's magic does not match.\n");
- }
+ if(buf->magic != S3COMMS_HRB_MAGIC)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "pointer's magic does not match.");
H5MM_xfree(buf->verb);
H5MM_xfree(buf->version);
@@ -707,53 +682,38 @@ H5FD_s3comms_hrb_init_request(const char *_verb,
HDfprintf(stdout, "called H5FD_s3comms_hrb_init_request.\n");
#endif
- if (_resource == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "resource string cannot be null.\n");
- }
+ if(_resource == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "resource string cannot be null.");
- /* populate valid NULLs with defaults
- */
- if (_verb == NULL) {
+ /* populate valid NULLs with defaults */
+ if(_verb == NULL)
_verb = "GET";
- }
-
- if (_http_version == NULL) {
+ if(_http_version == NULL)
_http_version = "HTTP/1.1";
- }
- /* malloc space for and prepare structure
- */
+ /* malloc space for and prepare structure */
request = (hrb_t *)H5MM_malloc(sizeof(hrb_t));
- if (request == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, NULL,
- "no space for request structure");
- }
+ if(request == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, NULL, "no space for request structure");
request->magic = S3COMMS_HRB_MAGIC;
request->body = NULL;
request->body_len = 0;
request->first_header = NULL;
-
- /* malloc and copy strings for the structure
- */
+ /* malloc and copy strings for the structure */
reslen = HDstrlen(_resource);
if (_resource[0] == '/') {
res = (char *)H5MM_malloc(sizeof(char) * (reslen+1));
- if (res == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, NULL,
- "no space for resource string");
- }
+ if(res == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, NULL, "no space for resource string");
HDmemcpy(res, _resource, (reslen+1));
}
else {
res = (char *)H5MM_malloc(sizeof(char) * (reslen+2));
- if (res == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, NULL,
- "no space for resource string");
- }
+ if(res == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, NULL, "no space for resource string");
*res = '/';
HDmemcpy((&res[1]), _resource, (reslen+1));
HDassert( (reslen+1) == HDstrlen(res) );
@@ -761,24 +721,18 @@ H5FD_s3comms_hrb_init_request(const char *_verb,
verblen = HDstrlen(_verb) + 1;
verb = (char *)H5MM_malloc(sizeof(char) * verblen);
- if (verb == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "no space for verb string");
- }
+ if(verb == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "no space for verb string");
HDstrncpy(verb, _verb, verblen);
vrsnlen = HDstrlen(_http_version) + 1;
vrsn = (char *)H5MM_malloc(sizeof(char) * vrsnlen);
- if (vrsn == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "no space for http-version string");
- }
+ if(vrsn == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "no space for http-version string");
HDstrncpy(vrsn, _http_version, vrsnlen);
-
- /* place new copies into structure
- */
+ /* place new copies into structure */
request->resource = res;
request->verb = verb;
request->version = vrsn;
@@ -786,13 +740,16 @@ H5FD_s3comms_hrb_init_request(const char *_verb,
ret_value = request;
done:
- /* if there is an error, clean up after ourselves
- */
+ /* if there is an error, clean up after ourselves */
if (ret_value == NULL) {
- if (request != NULL) H5MM_xfree(request);
- if (vrsn != NULL) H5MM_xfree(vrsn);
- if (verb != NULL) H5MM_xfree(verb);
- if (res != NULL) H5MM_xfree(res);
+ if(request != NULL)
+ H5MM_xfree(request);
+ if(vrsn != NULL)
+ H5MM_xfree(vrsn);
+ if(verb != NULL)
+ H5MM_xfree(verb);
+ if(res != NULL)
+ H5MM_xfree(res);
}
FUNC_LEAVE_NOAPI(ret_value)
@@ -836,14 +793,10 @@ H5FD_s3comms_s3r_close(s3r_t *handle)
HDfprintf(stdout, "called H5FD_s3comms_s3r_close.\n");
#endif
- if (handle == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle cannot be null.\n");
- }
- if (handle->magic != S3COMMS_S3R_MAGIC) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle has invalid magic.\n");
- }
+ if(handle == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle cannot be null.");
+ if(handle->magic != S3COMMS_S3R_MAGIC)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle has invalid magic.");
curl_easy_cleanup(handle->curlhandle);
@@ -854,10 +807,8 @@ H5FD_s3comms_s3r_close(s3r_t *handle)
HDassert( handle->httpverb != NULL );
H5MM_xfree(handle->httpverb);
- if (FAIL == H5FD_s3comms_free_purl(handle->purl)) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to release parsed url structure")
- }
+ if(FAIL == H5FD_s3comms_free_purl(handle->purl))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to release parsed url structure")
H5MM_xfree(handle);
@@ -893,9 +844,8 @@ H5FD_s3comms_s3r_get_filesize(s3r_t *handle)
FUNC_ENTER_NOAPI_NOINIT_NOERR
- if (handle != NULL) {
+ if(handle != NULL)
ret_value = handle->filesize;
- }
FUNC_LEAVE_NOAPI(ret_value)
} /* H5FD_s3comms_s3r_get_filesize */
@@ -953,58 +903,33 @@ H5FD_s3comms_s3r_getsize(s3r_t *handle)
HDfprintf(stdout, "called H5FD_s3comms_s3r_getsize.\n");
#endif
- if (handle == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle cannot be null.\n");
- }
- if (handle->magic != S3COMMS_S3R_MAGIC) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle has invalid magic.\n");
- }
- if (handle->curlhandle == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle has bad (null) curlhandle.\n")
- }
+ if(handle == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle cannot be null.");
+ if(handle->magic != S3COMMS_S3R_MAGIC)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle has invalid magic.");
+ if(handle->curlhandle == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle has bad (null) curlhandle.")
/********************
* PREPARE FOR HEAD *
********************/
curlh = handle->curlhandle;
+ if(CURLE_OK != curl_easy_setopt(curlh, CURLOPT_NOBODY, 1L))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "error while setting CURL option (CURLOPT_NOBODY).");
- if ( CURLE_OK !=
- curl_easy_setopt(curlh,
- CURLOPT_NOBODY,
- 1L) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "error while setting CURL option (CURLOPT_NOBODY). "
- "(placeholder flags)");
- }
-
- if ( CURLE_OK !=
- curl_easy_setopt(curlh,
- CURLOPT_HEADERDATA,
- &sds) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "error while setting CURL option (CURLOPT_HEADERDATA). "
- "(placeholder flags)");
- }
+ if(CURLE_OK != curl_easy_setopt(curlh, CURLOPT_HEADERDATA, &sds))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "error while setting CURL option (CURLOPT_HEADERDATA).");
HDassert( handle->httpverb == NULL );
handle->httpverb = (char *)H5MM_malloc(sizeof(char) * 16);
- if (handle->httpverb == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL,
- "unable to allocate space for S3 request HTTP verb");
- }
+ if(handle->httpverb == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL, "unable to allocate space for S3 request HTTP verb");
HDmemcpy(handle->httpverb, "HEAD", 5);
headerresponse = (char *)H5MM_malloc(sizeof(char) * CURL_MAX_HTTP_HEADER);
- if (headerresponse == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL,
- "unable to allocate space for curl header response");
- }
+ if(headerresponse == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL, "unable to allocate space for curl header response");
sds.data = headerresponse;
/*******************
@@ -1015,65 +940,43 @@ H5FD_s3comms_s3r_getsize(s3r_t *handle)
* but, with a NULL destination and NOBODY and HEADERDATA supplied above,
* only http metadata will be sent by server and recorded by s3comms
*/
- if (FAIL ==
- H5FD_s3comms_s3r_read(handle, 0, 0, NULL) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "problem in reading during getsize.\n");
- }
+ if(FAIL == H5FD_s3comms_s3r_read(handle, 0, 0, NULL))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem in reading during getsize.");
- if (sds.size > CURL_MAX_HTTP_HEADER) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "HTTP metadata buffer overrun\n");
- } else if (sds.size == 0) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "No HTTP metadata\n");
+ if(sds.size > CURL_MAX_HTTP_HEADER)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "HTTP metadata buffer overrun")
+ else if (sds.size == 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "No HTTP metadata")
#if S3COMMS_DEBUG
- } else {
+ else
HDfprintf(stderr, "GETSIZE: OK\n");
#endif
- }
/******************
* PARSE RESPONSE *
******************/
- start = strstr(headerresponse,
- "\r\nContent-Length: ");
- if (start == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "could not find \"Content-Length\" in response.\n");
- }
+ start = HDstrstr(headerresponse, "\r\nContent-Length: ");
+ if(start == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "could not find \"Content-Length\" in response.");
- /* move "start" to beginning of value in line; find end of line
- */
+ /* move "start" to beginning of value in line; find end of line */
start = start + HDstrlen("\r\nContent-Length: ");
- end = strstr(start, "\r\n");
- if (end == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "could not find end of content length line");
- }
+ end = HDstrstr(start, "\r\n");
+ if(end == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "could not find end of content length line");
/* place null terminator at end of numbers
*/
*end = '\0';
- content_length = strtoumax((const char *)start,
- NULL,
- 0);
-
- if (UINTMAX_MAX > SIZE_MAX && content_length > SIZE_MAX) {
- HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "content_length overflows size_t\n");
- }
+ content_length = HDstrtoumax((const char *)start, NULL, 0);
+ if(UINTMAX_MAX > SIZE_MAX && content_length > SIZE_MAX)
+ HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "content_length overflows size_t");
- if (content_length == 0 ||
- errno == ERANGE) /* errno set by strtoumax*/
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "could not convert found \"Content-Length\" response (\"%s\")",
- start); /* range is null-terminated, remember */
- }
+ if(content_length == 0 || errno == ERANGE) /* errno set by HDstrtoumax*/
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "could not convert found \"Content-Length\" response (\"%s\")", start); /* range is null-terminated, remember */
handle->filesize = (size_t)content_length;
@@ -1081,32 +984,17 @@ H5FD_s3comms_s3r_getsize(s3r_t *handle)
* UNDO HEAD SETTINGS *
**********************/
- if ( CURLE_OK !=
- curl_easy_setopt(curlh,
- CURLOPT_NOBODY,
- NULL) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "error while setting CURL option (CURLOPT_NOBODY). "
- "(placeholder flags)");
- }
+ if(CURLE_OK != curl_easy_setopt(curlh, CURLOPT_NOBODY, NULL))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "error while setting CURL option (CURLOPT_NOBODY).");
- if ( CURLE_OK !=
- curl_easy_setopt(curlh,
- CURLOPT_HEADERDATA,
- NULL) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "error while setting CURL option (CURLOPT_HEADERDATA). "
- "(placeholder flags)");
- }
+ if(CURLE_OK != curl_easy_setopt(curlh, CURLOPT_HEADERDATA, NULL))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "error while setting CURL option (CURLOPT_HEADERDATA).");
done:
H5MM_xfree(headerresponse);
sds.magic += 1; /* set to bad magic */
FUNC_LEAVE_NOAPI(ret_value);
-
} /* H5FD_s3comms_s3r_getsize */
@@ -1167,26 +1055,19 @@ H5FD_s3comms_s3r_open(const char *url,
HDfprintf(stdout, "called H5FD_s3comms_s3r_open.\n");
#endif
+ if(url == NULL || url[0] == '\0')
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "url cannot be null.");
-
- if (url == NULL || url[0] == '\0') {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "url cannot be null.\n");
- }
-
- if (FAIL == H5FD_s3comms_parse_url(url, &purl)) {
+ if(FAIL == H5FD_s3comms_parse_url(url, &purl))
/* probably a malformed url, but could be internal error */
- HGOTO_ERROR(H5E_ARGS, H5E_CANTCREATE, NULL,
- "unable to create parsed url structure");
- }
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTCREATE, NULL, "unable to create parsed url structure");
+
HDassert( purl != NULL ); /* if above passes, this must be true */
HDassert( purl->magic == S3COMMS_PARSED_URL_MAGIC );
handle = (s3r_t *)H5MM_malloc(sizeof(s3r_t));
- if (handle == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, NULL,
- "could not malloc space for handle.\n");
- }
+ if(handle == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, NULL, "could not malloc space for handle.");
handle->magic = S3COMMS_S3R_MAGIC;
handle->purl = purl;
@@ -1200,50 +1081,35 @@ H5FD_s3comms_s3r_open(const char *url,
* RECORD AUTHENTICATION INFORMATION *
*************************************/
- if ((region != NULL && *region != '\0') ||
- (id != NULL && *id != '\0') ||
- (signing_key != NULL))
- {
- /* if one exists, all three must exist
- */
- if (region == NULL || region[0] == '\0') {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "region cannot be null.\n");
- }
- if (id == NULL || id[0] == '\0') {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "secret id cannot be null.\n");
- }
- if (signing_key == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "signing key cannot be null.\n");
- }
+ if((region != NULL && *region != '\0') ||
+ (id != NULL && *id != '\0') ||
+ (signing_key != NULL)) {
- /* copy strings
- */
+ /* if one exists, all three must exist */
+ if(region == NULL || region[0] == '\0')
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "region cannot be null.");
+ if(id == NULL || id[0] == '\0')
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "secret id cannot be null.");
+ if(signing_key == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "signing key cannot be null.");
+
+ /* copy strings */
tmplen = HDstrlen(region) + 1;
handle->region = (char *)H5MM_malloc(sizeof(char) * tmplen);
- if (handle->region == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "could not malloc space for handle region copy.\n");
- }
+ if(handle->region == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "could not malloc space for handle region copy.");
HDmemcpy(handle->region, region, tmplen);
tmplen = HDstrlen(id) + 1;
handle->secret_id = (char *)H5MM_malloc(sizeof(char) * tmplen);
- if (handle->secret_id == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "could not malloc space for handle ID copy.\n");
- }
+ if(handle->secret_id == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "could not malloc space for handle ID copy.");
HDmemcpy(handle->secret_id, id, tmplen);
tmplen = SHA256_DIGEST_LENGTH;
- handle->signing_key =
- (unsigned char *)H5MM_malloc(sizeof(unsigned char) * tmplen);
- if (handle->signing_key == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "could not malloc space for handle key copy.\n");
- }
+ handle->signing_key = (unsigned char *)H5MM_malloc(sizeof(unsigned char) * tmplen);
+ if(handle->signing_key == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "could not malloc space for handle key copy.");
HDmemcpy(handle->signing_key, signing_key, tmplen);
} /* if authentication information provided */
@@ -1252,61 +1118,23 @@ H5FD_s3comms_s3r_open(const char *url,
************************/
curlh = curl_easy_init();
+ if(curlh == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "problem creating curl easy handle!");
- if (curlh == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "problem creating curl easy handle!\n");
- }
+ if(CURLE_OK != curl_easy_setopt(curlh, CURLOPT_HTTPGET, 1L))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "error while setting CURL option (CURLOPT_HTTPGET).");
- if ( CURLE_OK !=
- curl_easy_setopt(curlh,
- CURLOPT_HTTPGET,
- 1L) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "error while setting CURL option (CURLOPT_HTTPGET). "
- "(placeholder flags)");
- }
-
- if ( CURLE_OK !=
- curl_easy_setopt(curlh,
- CURLOPT_HTTP_VERSION,
- CURL_HTTP_VERSION_1_1) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "error while setting CURL option (CURLOPT_HTTP_VERSION). "
- "(placeholder flags)");
- }
+ if(CURLE_OK != curl_easy_setopt(curlh, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "error while setting CURL option (CURLOPT_HTTP_VERSION).");
- if ( CURLE_OK !=
- curl_easy_setopt(curlh,
- CURLOPT_FAILONERROR,
- 1L) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "error while setting CURL option (CURLOPT_FAILONERROR). "
- "(placeholder flags)");
- }
+ if(CURLE_OK != curl_easy_setopt(curlh, CURLOPT_FAILONERROR, 1L))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "error while setting CURL option (CURLOPT_FAILONERROR).");
- if ( CURLE_OK !=
- curl_easy_setopt(curlh,
- CURLOPT_WRITEFUNCTION,
- curlwritecallback) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "error while setting CURL option (CURLOPT_WRITEFUNCTION). "
- "(placeholder flags)");
- }
+ if(CURLE_OK != curl_easy_setopt(curlh, CURLOPT_WRITEFUNCTION, curlwritecallback))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "error while setting CURL option (CURLOPT_WRITEFUNCTION).");
- if ( CURLE_OK !=
- curl_easy_setopt(curlh,
- CURLOPT_URL,
- url) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "error while setting CURL option (CURLOPT_URL). "
- "(placeholder flags)");
- }
+ if(CURLE_OK != curl_easy_setopt(curlh, CURLOPT_URL, url))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "error while setting CURL option (CURLOPT_URL).");
#if S3COMMS_CURL_VERBOSITY > 1
/* CURL will print (to stdout) information for each operation
@@ -1322,12 +1150,8 @@ H5FD_s3comms_s3r_open(const char *url,
* GET FILE SIZE *
*******************/
- if (FAIL ==
- H5FD_s3comms_s3r_getsize(handle) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "problem in H5FD_s3comms_s3r_getsize.\n");
- }
+ if(FAIL == H5FD_s3comms_s3r_getsize(handle))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "problem in H5FD_s3comms_s3r_getsize.");
/*********************
* FINAL PREPARATION *
@@ -1339,27 +1163,22 @@ H5FD_s3comms_s3r_open(const char *url,
ret_value = handle;
done:
- if (ret_value == NULL) {
- if (curlh != NULL) {
+ if(ret_value == NULL) {
+ if(curlh != NULL)
curl_easy_cleanup(curlh);
- }
- if (FAIL == H5FD_s3comms_free_purl(purl)) {
- HDONE_ERROR(H5E_ARGS, H5E_BADVALUE, NULL,
- "unable to free parsed url structure")
- }
- if (handle != NULL) {
+ if(FAIL == H5FD_s3comms_free_purl(purl))
+ HDONE_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "unable to free parsed url structure")
+ if(handle != NULL) {
H5MM_xfree(handle->region);
H5MM_xfree(handle->secret_id);
H5MM_xfree(handle->signing_key);
- if (handle->httpverb != NULL) {
+ if(handle->httpverb != NULL)
H5MM_xfree(handle->httpverb);
- }
H5MM_xfree(handle);
}
}
FUNC_LEAVE_NOAPI(ret_value)
-
} /* H5FD_s3comms_s3r_open */
@@ -1433,27 +1252,17 @@ H5FD_s3comms_s3r_read(s3r_t *handle,
* ABSOLUTELY NECESSARY SANITY-CHECKS *
**************************************/
- if (handle == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle cannot be null.\n");
- }
- if (handle->magic != S3COMMS_S3R_MAGIC) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle has invalid magic.\n");
- }
- if (handle->curlhandle == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle has bad (null) curlhandle.\n")
- }
- if (handle->purl == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle has bad (null) url.\n")
- }
+ if(handle == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle cannot be null.");
+ if(handle->magic != S3COMMS_S3R_MAGIC)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle has invalid magic.");
+ if(handle->curlhandle == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle has bad (null) curlhandle.")
+ if(handle->purl == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle has bad (null) url.")
HDassert( handle->purl->magic == S3COMMS_PARSED_URL_MAGIC );
- if (offset > handle->filesize || (len + offset) > handle->filesize) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to read past EoF")
- }
+ if(offset > handle->filesize || (len + offset) > handle->filesize)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to read past EoF")
curlh = handle->curlhandle;
@@ -1461,26 +1270,16 @@ H5FD_s3comms_s3r_read(s3r_t *handle,
* PREPARE WRITEDATA *
*********************/
- if (dest != NULL) {
- sds = (struct s3r_datastruct *)H5MM_malloc(
- sizeof(struct s3r_datastruct));
- if (sds == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL,
- "could not malloc destination datastructure.\n");
- }
+ if(dest != NULL) {
+ sds = (struct s3r_datastruct *)H5MM_malloc(sizeof(struct s3r_datastruct));
+ if(sds == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL, "could not malloc destination datastructure.");
sds->magic = S3COMMS_CALLBACK_DATASTRUCT_MAGIC;
sds->data = (char *)dest;
sds->size = 0;
- if (CURLE_OK !=
- curl_easy_setopt(curlh,
- CURLOPT_WRITEDATA,
- sds) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_UNINITIALIZED, FAIL,
- "error while setting CURL option (CURLOPT_WRITEDATA). "
- "(placeholder flags)");
- }
+ if(CURLE_OK != curl_easy_setopt(curlh, CURLOPT_WRITEDATA, sds))
+ HGOTO_ERROR(H5E_ARGS, H5E_UNINITIALIZED, FAIL, "error while setting CURL option (CURLOPT_WRITEDATA).");
}
/*********************
@@ -1488,34 +1287,22 @@ H5FD_s3comms_s3r_read(s3r_t *handle,
*********************/
if (len > 0) {
- rangebytesstr = (char *)H5MM_malloc(sizeof(char) * \
- (S3COMMS_MAX_RANGE_STRING_SIZE+1) );
- if (rangebytesstr == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL,
- "could not malloc range format string.\n");
- }
- ret = HDsnprintf(rangebytesstr,
- (S3COMMS_MAX_RANGE_STRING_SIZE),
+ rangebytesstr = (char *)H5MM_malloc(sizeof(char) * (S3COMMS_MAX_RANGE_STRING_SIZE+1) );
+ if(rangebytesstr == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL, "could not malloc range format string.");
+ ret = HDsnprintf(rangebytesstr, (S3COMMS_MAX_RANGE_STRING_SIZE),
"bytes="H5_PRINTF_HADDR_FMT"-"H5_PRINTF_HADDR_FMT,
- offset,
- offset + len - 1);
- if (ret <= 0 || ret >= S3COMMS_MAX_RANGE_STRING_SIZE)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to format HTTP Range value");
- } else if (offset > 0) {
- rangebytesstr = (char *)H5MM_malloc(sizeof(char) * \
- (S3COMMS_MAX_RANGE_STRING_SIZE+1));
- if (rangebytesstr == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL,
- "could not malloc range format string.\n");
- }
- ret = HDsnprintf(rangebytesstr,
- (S3COMMS_MAX_RANGE_STRING_SIZE),
- "bytes="H5_PRINTF_HADDR_FMT"-",
- offset);
- if (ret <= 0 || ret >= S3COMMS_MAX_RANGE_STRING_SIZE)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to format HTTP Range value");
+ offset, offset + len - 1);
+ if(ret <= 0 || ret >= S3COMMS_MAX_RANGE_STRING_SIZE)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to format HTTP Range value");
+ } else if(offset > 0) {
+ rangebytesstr = (char *)H5MM_malloc(sizeof(char) * (S3COMMS_MAX_RANGE_STRING_SIZE+1));
+ if(rangebytesstr == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL, "could not malloc range format string.");
+ ret = HDsnprintf(rangebytesstr, (S3COMMS_MAX_RANGE_STRING_SIZE),
+ "bytes="H5_PRINTF_HADDR_FMT"-", offset);
+ if(ret <= 0 || ret >= S3COMMS_MAX_RANGE_STRING_SIZE)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to format HTTP Range value");
}
/*******************
@@ -1523,26 +1310,18 @@ H5FD_s3comms_s3r_read(s3r_t *handle,
*******************/
if (handle->signing_key == NULL) {
- /* Do not authenticate.
- */
- if (rangebytesstr != NULL) {
- /* Pass in range directly
- */
+ /* Do not authenticate. */
+ if(rangebytesstr != NULL) {
+ /* Pass in range directly */
char *bytesrange_ptr = NULL; /* pointer past "bytes=" portion */
- bytesrange_ptr = strchr(rangebytesstr, '=');
+ bytesrange_ptr = HDstrchr(rangebytesstr, '=');
HDassert( bytesrange_ptr != NULL );
bytesrange_ptr++; /* move to first char past '=' */
HDassert( *bytesrange_ptr != '\0' );
- if (CURLE_OK !=
- curl_easy_setopt(curlh,
- CURLOPT_RANGE,
- bytesrange_ptr) )
- {
- HGOTO_ERROR(H5E_VFL, H5E_UNINITIALIZED, FAIL,
- "error while setting CURL option (CURLOPT_RANGE). ");
- }
+ if(CURLE_OK != curl_easy_setopt(curlh, CURLOPT_RANGE, bytesrange_ptr))
+ HGOTO_ERROR(H5E_VFL, H5E_UNINITIALIZED, FAIL, "error while setting CURL option (CURLOPT_RANGE). ");
}
} else {
/* authenticate request
@@ -1575,30 +1354,18 @@ H5FD_s3comms_s3r_read(s3r_t *handle,
/**** VERIFY INFORMATION EXISTS ****/
- if (handle->region == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle must have non-null region.\n");
- }
- if (handle->secret_id == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle must have non-null secret_id.\n");
- }
- if (handle->signing_key == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle must have non-null signing_key.\n");
- }
- if (handle->httpverb == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle must have non-null httpverb.\n");
- }
- if (handle->purl->host == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle must have non-null host.\n");
- }
- if (handle->purl->path == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "handle must have non-null resource.\n");
- }
+ if(handle->region == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle must have non-null region.");
+ if(handle->secret_id == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle must have non-null secret_id.");
+ if(handle->signing_key == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle must have non-null signing_key.");
+ if(handle->httpverb == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle must have non-null httpverb.");
+ if(handle->purl->host == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle must have non-null host.");
+ if(handle->purl->path == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "handle must have non-null resource.");
/**** CREATE HTTP REQUEST STRUCTURE (hrb_t) ****/
@@ -1606,198 +1373,93 @@ H5FD_s3comms_s3r_read(s3r_t *handle,
(const char *)handle->httpverb,
(const char *)handle->purl->path,
"HTTP/1.1");
- if (request == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "could not allocate hrb_t request.\n");
- }
+ if(request == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "could not allocate hrb_t request.");
HDassert( request->magic == S3COMMS_HRB_MAGIC );
now = gmnow();
- if (ISO8601NOW(iso8601now, now) != (ISO8601_SIZE - 1)) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "could not format ISO8601 time.\n");
- }
+ if(ISO8601NOW(iso8601now, now) != (ISO8601_SIZE - 1))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "could not format ISO8601 time.");
- if (FAIL ==
- H5FD_s3comms_hrb_node_set(
- &headers,
- "x-amz-date",
- (const char *)iso8601now) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to set x-amz-date header")
- }
- if (headers == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "problem building headers list. "
- "(placeholder flags)\n");
- }
+ if(FAIL == H5FD_s3comms_hrb_node_set( &headers, "x-amz-date", (const char *)iso8601now))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to set x-amz-date header")
+ if(headers == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem building headers list.");
HDassert( headers->magic == S3COMMS_HRB_NODE_MAGIC );
- if (FAIL ==
- H5FD_s3comms_hrb_node_set(
- &headers,
- "x-amz-content-sha256",
- (const char *)EMPTY_SHA256) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to set x-amz-content-sha256 header")
- }
- if (headers == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "problem building headers list. "
- "(placeholder flags)\n");
- }
+ if(FAIL == H5FD_s3comms_hrb_node_set(&headers, "x-amz-content-sha256", (const char *)EMPTY_SHA256))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to set x-amz-content-sha256 header")
+ if(headers == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem building headers list.");
HDassert( headers->magic == S3COMMS_HRB_NODE_MAGIC );
- if (rangebytesstr != NULL) {
- if (FAIL ==
- H5FD_s3comms_hrb_node_set(
- &headers,
- "Range",
- (const char *)rangebytesstr) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to set range header")
- }
- if (headers == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "problem building headers list. "
- "(placeholder flags)\n");
- }
+ if(rangebytesstr != NULL) {
+ if(FAIL == H5FD_s3comms_hrb_node_set( &headers, "Range", rangebytesstr))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to set range header")
+ if(headers == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem building headers list.");
HDassert( headers->magic == S3COMMS_HRB_NODE_MAGIC );
}
- if (FAIL ==
- H5FD_s3comms_hrb_node_set(
- &headers,
- "Host",
- (const char *)handle->purl->host) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to set host header")
- }
- if (headers == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "problem building headers list. "
- "(placeholder flags)\n");
- }
+ if(FAIL == H5FD_s3comms_hrb_node_set(&headers, "Host", handle->purl->host))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to set host header")
+ if(headers == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem building headers list.");
HDassert( headers->magic == S3COMMS_HRB_NODE_MAGIC );
request->first_header = headers;
/**** COMPUTE AUTHORIZATION ****/
- if (FAIL == /* buffer1 -> canonical request */
- H5FD_s3comms_aws_canonical_request(
- buffer1,
- 512,
- signed_headers,
- 48,
- request) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "(placeholder flags)\n");
- }
- if ( FAIL == /* buffer2->string-to-sign */
- H5FD_s3comms_tostringtosign(buffer2,
- buffer1,
- iso8601now,
- handle->region) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "(placeholder flags)\n");
- }
- if (FAIL == /* buffer1 -> signature */
- H5FD_s3comms_HMAC_SHA256(handle->signing_key,
- SHA256_DIGEST_LENGTH,
- buffer2,
- HDstrlen(buffer2),
- buffer1) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "(placeholder flags)\n");
- }
+ /* buffer1 -> canonical request */
+ if(FAIL == H5FD_s3comms_aws_canonical_request(buffer1, 512, signed_headers, 48, request))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bad canonical request");
+ /* buffer2->string-to-sign */
+ if(FAIL == H5FD_s3comms_tostringtosign(buffer2, buffer1, iso8601now, handle->region))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bad string-to-sign");
+ /* buffer1 -> signature */
+ if(FAIL == H5FD_s3comms_HMAC_SHA256(handle->signing_key, SHA256_DIGEST_LENGTH, buffer2, HDstrlen(buffer2), buffer1))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bad signature");
iso8601now[8] = 0; /* trim to yyyyMMDD */
- ret = S3COMMS_FORMAT_CREDENTIAL(buffer2,
- handle->secret_id,
- iso8601now,
- handle->region,
- "s3");
- if (ret == 0 || ret >= S3COMMS_MAX_CREDENTIAL_SIZE)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to format aws4 credential string");
-
- ret = HDsnprintf(
- authorization,
- 512,
+ ret = S3COMMS_FORMAT_CREDENTIAL(buffer2, handle->secret_id, iso8601now, handle->region, "s3");
+ if(ret == 0 || ret >= S3COMMS_MAX_CREDENTIAL_SIZE)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to format aws4 credential string");
+
+ ret = HDsnprintf( authorization, 512,
"AWS4-HMAC-SHA256 Credential=%s,SignedHeaders=%s,Signature=%s",
- buffer2,
- signed_headers,
- buffer1);
- if (ret <= 0 || ret >= 512) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to format aws4 authorization string");
- }
+ buffer2, signed_headers, buffer1);
+ if(ret <= 0 || ret >= 512)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to format aws4 authorization string");
- /* append authorization header to http request buffer
- */
- if (H5FD_s3comms_hrb_node_set(
- &headers,
- "Authorization",
- (const char *)authorization)
- == FAIL)
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to set Authorization header")
- }
- if (headers == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "problem building headers list. "
- "(placeholder flags)\n");
- }
+ /* append authorization header to http request buffer */
+ if(H5FD_s3comms_hrb_node_set(&headers, "Authorization", (const char *)authorization) == FAIL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to set Authorization header")
+ if(headers == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem building headers list.");
- /* update hrb's "first header" pointer
- */
+ /* update hrb's "first header" pointer */
request->first_header = headers;
/**** SET CURLHANDLE HTTP HEADERS FROM GENERATED DATA ****/
node = request->first_header;
- while (node != NULL) {
+ while(node != NULL) {
HDassert( node->magic == S3COMMS_HRB_NODE_MAGIC );
- curlheaders = curl_slist_append(curlheaders,
- (const char *)node->cat);
- if (curlheaders == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "could not append header to curl slist. "
- "(placeholder flags)\n");
- }
+ curlheaders = curl_slist_append(curlheaders, (const char *)node->cat);
+ if(curlheaders == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "could not append header to curl slist.");
node = node->next;
}
- /* sanity-check
- */
- if (curlheaders == NULL) {
+ /* sanity-check */
+ if(curlheaders == NULL)
/* above loop was probably never run */
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "curlheaders was never populated.\n");
- }
-
- /* finally, set http headers in curl handle
- */
- if (curl_easy_setopt(
- curlh,
- CURLOPT_HTTPHEADER,
- curlheaders)
- != CURLE_OK)
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "error while setting CURL option "
- "(CURLOPT_HTTPHEADER). (placeholder flags)");
- }
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "curlheaders was never populated.");
+ /* finally, set http headers in curl handle */
+ if(curl_easy_setopt(curlh, CURLOPT_HTTPHEADER, curlheaders) != CURLE_OK)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "error while setting CURL option (CURLOPT_HTTPHEADER).");
} /* end if should authenticate (info provided) */
/*******************
@@ -1813,107 +1475,79 @@ H5FD_s3comms_s3r_read(s3r_t *handle,
char curlerrbuf[CURL_ERROR_SIZE];
curlerrbuf[0] = '\0';
- if (CURLE_OK !=
- curl_easy_setopt(curlh, CURLOPT_ERRORBUFFER, curlerrbuf) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "problem setting error buffer")
- }
+ if(CURLE_OK != curl_easy_setopt(curlh, CURLOPT_ERRORBUFFER, curlerrbuf))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem setting error buffer")
p_status = curl_easy_perform(curlh);
- if (p_status != CURLE_OK) {
- if (CURLE_OK !=
- curl_easy_getinfo(curlh, CURLINFO_RESPONSE_CODE, &httpcode) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "problem getting response code")
- }
+ if(p_status != CURLE_OK) {
+ if(CURLE_OK != curl_easy_getinfo(curlh, CURLINFO_RESPONSE_CODE, &httpcode))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem getting response code")
HDfprintf(stderr, "CURL ERROR CODE: %d\nHTTP CODE: %d\n",
p_status, httpcode);
HDfprintf(stderr, "%s\n", curl_easy_strerror(p_status));
- HGOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, FAIL,
- "problem while performing request.\n");
- }
- if (CURLE_OK !=
- curl_easy_setopt(curlh, CURLOPT_ERRORBUFFER, NULL) )
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "problem unsetting error buffer")
+ HGOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, FAIL, "problem while performing request.");
}
+ if(CURLE_OK != curl_easy_setopt(curlh, CURLOPT_ERRORBUFFER, NULL))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem unsetting error buffer")
} /* verbose error reporting */
#else
p_status = curl_easy_perform(curlh);
- if (p_status != CURLE_OK) {
- HGOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, FAIL,
- "curl cannot perform request\n")
- }
+ if(p_status != CURLE_OK)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, FAIL, "curl cannot perform request")
#endif
#if S3COMMS_DEBUG
- if (dest != NULL) {
+ if(dest != NULL) {
HDfprintf(stderr, "len: %d\n", (int)len);
HDfprintf(stderr, "CHECKING FOR BUFFER OVERFLOW\n");
- if (sds == NULL) {
+ if(sds == NULL)
HDfprintf(stderr, "sds is NULL!\n");
- }
else {
HDfprintf(stderr, "sds: 0x%lx\n", (long long)sds);
HDfprintf(stderr, "sds->size: %d\n", (int)sds->size);
- if (len > sds->size) {
+ if(len > sds->size)
HDfprintf(stderr, "buffer overwrite\n");
- }
}
}
- else {
+ else
HDfprintf(stderr, "performed on entire file\n");
- }
#endif
done:
/* clean any malloc'd resources
*/
- if (curlheaders != NULL) {
+ if(curlheaders != NULL) {
curl_slist_free_all(curlheaders);
curlheaders = NULL;
}
- if (rangebytesstr != NULL) {
+ if(rangebytesstr != NULL) {
H5MM_xfree(rangebytesstr);
rangebytesstr = NULL;
}
- if (sds != NULL) {
+ if(sds != NULL) {
H5MM_xfree(sds);
sds = NULL;
}
- if (request != NULL) {
- while (headers != NULL)
- if (FAIL ==
- H5FD_s3comms_hrb_node_set(&headers, headers->name, NULL))
- {
- HDONE_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "cannot release header node")
- }
+ if(request != NULL) {
+ while(headers != NULL)
+ if(FAIL == H5FD_s3comms_hrb_node_set(&headers, headers->name, NULL))
+ HDONE_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "cannot release header node")
HDassert( NULL == headers );
- if (FAIL == H5FD_s3comms_hrb_destroy(&request)) {
- HDONE_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "cannot release header request structure")
- }
+ if(FAIL == H5FD_s3comms_hrb_destroy(&request))
+ HDONE_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "cannot release header request structure")
HDassert( NULL == request );
}
- if (curlh != NULL) {
+ if(curlh != NULL) {
/* clear any Range */
- if (CURLE_OK != curl_easy_setopt(curlh, CURLOPT_RANGE, NULL) ) {
- HDONE_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "cannot unset CURLOPT_RANGE")
- }
+ if(CURLE_OK != curl_easy_setopt(curlh, CURLOPT_RANGE, NULL))
+ HDONE_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "cannot unset CURLOPT_RANGE")
/* clear headers */
- if (CURLE_OK != curl_easy_setopt(curlh, CURLOPT_HTTPHEADER, NULL) ) {
- HDONE_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "cannot unset CURLOPT_HTTPHEADER")
- }
+ if(CURLE_OK != curl_easy_setopt(curlh, CURLOPT_HTTPHEADER, NULL))
+ HDONE_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "cannot unset CURLOPT_HTTPHEADER")
}
FUNC_LEAVE_NOAPI(ret_value);
@@ -1951,9 +1585,8 @@ gmnow(void)
struct tm *ret_value = NULL;
/* Doctor assert, checks against error in time() */
- if ( (time_t)(-1) != time(now_ptr) ) {
- ret_value = gmtime(now_ptr);
- }
+ if((time_t)(-1) != HDtime(now_ptr))
+ ret_value = HDgmtime(now_ptr);
HDassert( ret_value != NULL );
@@ -2035,102 +1668,66 @@ H5FD_s3comms_aws_canonical_request(
HDfprintf(stdout, "called H5FD_s3comms_aws_canonical_request.\n");
#endif
- if (http_request == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "hrb object cannot be null.\n");
- }
+ if(http_request == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "hrb object cannot be null.");
HDassert( http_request->magic == S3COMMS_HRB_MAGIC );
- if (canonical_request_dest == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "canonical request destination cannot be null.\n");
- }
+ if(canonical_request_dest == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "canonical request destination cannot be null.");
- if (signed_headers_dest == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "signed headers destination cannot be null.\n");
- }
+ if(signed_headers_dest == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "signed headers destination cannot be null.");
- /* HTTP verb, resource path, and query string lines
- */
+ /* HTTP verb, resource path, and query string lines */
cr_len = (HDstrlen(http_request->verb) +
HDstrlen(http_request->resource) +
HDstrlen(query_params) +
(size_t)3); /* three newline chars */
- if (cr_len >= cr_size) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "not enough space in canonical request");
- }
- ret = HDsnprintf( /* TODO: compiler warning */
- canonical_request_dest,
- (cr_size-1),
+ if(cr_len >= cr_size)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not enough space in canonical request");
+ /* TODO: compiler warning */
+ ret = HDsnprintf(canonical_request_dest, (cr_size - 1),
"%s\n%s\n%s\n",
- http_request->verb,
- http_request->resource,
- query_params);
- if (ret < 0 || (size_t)ret >= cr_size) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to compose canonical request first line");
- }
+ http_request->verb, http_request->resource, query_params);
+ if(ret < 0 || (size_t)ret >= cr_size)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to compose canonical request first line");
- /* write in canonical headers, building signed headers concurrently
- */
+ /* write in canonical headers, building signed headers concurrently */
node = http_request->first_header; /* assumed sorted */
- while (node != NULL) {
+ while(node != NULL) {
HDassert(node->magic == S3COMMS_HRB_NODE_MAGIC);
- ret = HDsnprintf(
- tmpstr,
- 256,
- "%s:%s\n",
- node->lowername,
- node->value);
- if (ret < 0 || ret >= 256) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to concatenate HTTP header %s:%s",
- node->lowername,
- node->value);
- }
+ ret = HDsnprintf( tmpstr, 256, "%s:%s\n", node->lowername, node->value);
+ if(ret < 0 || ret >= 256)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to concatenate HTTP header %s:%s", node->lowername, node->value);
cr_len += HDstrlen(tmpstr);
- if (cr_len + 1 > cr_size) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "not enough space in canonical request");
- }
- strcat(canonical_request_dest, tmpstr);
-
- ret = HDsnprintf(
- tmpstr,
- 256,
- "%s;",
- node->lowername);
- if (ret < 0 || ret >= 256) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to append semicolon to lowername %s",
- node->lowername);
- }
+ if(cr_len + 1 > cr_size)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not enough space in canonical request");
+ HDstrcat(canonical_request_dest, tmpstr);
+
+ ret = HDsnprintf( tmpstr, 256, "%s;", node->lowername);
+ if(ret < 0 || ret >= 256)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to append semicolon to lowername %s", node->lowername);
sh_len += HDstrlen(tmpstr);
- if (sh_len + 1 > sh_size) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "not enough space in signed headers");
- }
- strcat(signed_headers_dest, tmpstr);
+ if(sh_len + 1 > sh_size)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not enough space in signed headers");
+ HDstrcat(signed_headers_dest, tmpstr);
node = node->next;
} /* end while node is not NULL */
- /* remove tailing ';' from signed headers sequence
- */
+ /* remove trailing ';' from signed headers sequence */
signed_headers_dest[HDstrlen(signed_headers_dest) - 1] = '\0';
/* append signed headers and payload hash
* NOTE: at present, no HTTP body is handled, per the nature of
* requests/range-gets
*/
- strcat(canonical_request_dest, "\n");
- strcat(canonical_request_dest, signed_headers_dest);
- strcat(canonical_request_dest, "\n");
- strcat(canonical_request_dest, EMPTY_SHA256);
+ HDstrcat(canonical_request_dest, "\n");
+ HDstrcat(canonical_request_dest, signed_headers_dest);
+ HDstrcat(canonical_request_dest, "\n");
+ HDstrcat(canonical_request_dest, EMPTY_SHA256);
done:
FUNC_LEAVE_NOAPI(ret_value);
@@ -2184,30 +1781,20 @@ H5FD_s3comms_bytes_to_hex(
HDfprintf(stdout, "called H5FD_s3comms_bytes_to_hex.\n");
#endif
- if (dest == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "hex destination cannot be null.\n")
- }
- if (msg == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "bytes sequence cannot be null.\n")
- }
+ if(dest == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "hex destination cannot be null.")
+ if(msg == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bytes sequence cannot be null.")
for (i = 0; i < msg_len; i++) {
- int chars_written = HDsnprintf(&(dest[i * 2]),
- 3, /* 'X', 'X', '\n' */
- (lowercase == TRUE) ? "%02x" : "%02X",
- msg[i]);
- if (chars_written != 2) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "problem while writing hex chars for %c",
- msg[i]);
- }
+ int chars_written = HDsnprintf(&(dest[i * 2]), 3, /* 'X', 'X', '\n' */
+ (lowercase == TRUE) ? "%02x" : "%02X", msg[i]);
+ if(chars_written != 2)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem while writing hex chars for %c", msg[i]);
}
done:
FUNC_LEAVE_NOAPI(ret_value);
-
} /* end H5FD_s3comms_bytes_to_hex() */
@@ -2239,13 +1826,18 @@ H5FD_s3comms_free_purl(parsed_url_t *purl)
HDprintf("called H5FD_s3comms_free_purl.\n");
#endif
- if (purl != NULL) {
+ if(purl != NULL) {
HDassert( purl->magic == S3COMMS_PARSED_URL_MAGIC );
- if (purl->scheme != NULL) { H5MM_xfree(purl->scheme); }
- if (purl->host != NULL) { H5MM_xfree(purl->host); }
- if (purl->port != NULL) { H5MM_xfree(purl->port); }
- if (purl->path != NULL) { H5MM_xfree(purl->path); }
- if (purl->query != NULL) { H5MM_xfree(purl->query); }
+ if(purl->scheme != NULL)
+ H5MM_xfree(purl->scheme);
+ if(purl->host != NULL)
+ H5MM_xfree(purl->host);
+ if(purl->port != NULL)
+ H5MM_xfree(purl->port);
+ if(purl->path != NULL)
+ H5MM_xfree(purl->path);
+ if(purl->query != NULL)
+ H5MM_xfree(purl->query);
purl->magic += 1ul;
H5MM_xfree(purl);
}
@@ -2302,29 +1894,14 @@ H5FD_s3comms_HMAC_SHA256(
HDfprintf(stdout, "called H5FD_s3comms_HMAC_SHA256.\n");
#endif
- if (dest == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "destination cannot be null.");
- }
+ if(dest == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "destination cannot be null.");
- HMAC(EVP_sha256(),
- key,
- (int)key_len,
- (const unsigned char *)msg,
- msg_len,
- md,
- &md_len);
-
- if (H5FD_s3comms_bytes_to_hex(
- dest,
- (const unsigned char *)md,
- (size_t)md_len,
- true)
- == FAIL)
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "could not convert to hex string.");
- }
+ HMAC(EVP_sha256(), key, (int)key_len, (const unsigned char *)msg,
+ msg_len, md, &md_len);
+
+ if(H5FD_s3comms_bytes_to_hex(dest, (const unsigned char *)md, (size_t)md_len, true) == FAIL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "could not convert to hex string.");
done:
FUNC_LEAVE_NOAPI(ret_value);
@@ -2407,93 +1984,73 @@ H5FD__s3comms_load_aws_creds_from_file(
int found_setting = 0;
char *line_buffer = &(buffer[0]);
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
#if S3COMMS_DEBUG
HDfprintf(stdout, "called load_aws_creds_from_file.\n");
#endif
/* format target line for start of profile */
- if (32 < HDsnprintf(profile_line, 32, "[%s]", profile_name)) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTCOPY, FAIL,
- "unable to format profile label")
- }
+ if(32 < HDsnprintf(profile_line, 32, "[%s]", profile_name))
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTCOPY, FAIL, "unable to format profile label")
/* look for start of profile */
do {
/* clear buffer */
- for (buffer_i=0; buffer_i < 128; buffer_i++) {
+ for(buffer_i=0; buffer_i < 128; buffer_i++)
buffer[buffer_i] = 0;
- }
line_buffer = fgets(line_buffer, 128, file);
- if (line_buffer == NULL) { /* reached end of file */
+ if(line_buffer == NULL) /* reached end of file */
goto done;
- }
- } while (strncmp(line_buffer, profile_line, HDstrlen(profile_line)));
+ } while (HDstrncmp(line_buffer, profile_line, HDstrlen(profile_line)));
/* extract credentials from lines */
do {
/* clear buffer */
- for (buffer_i=0; buffer_i < 128; buffer_i++) {
+ for(buffer_i=0; buffer_i < 128; buffer_i++)
buffer[buffer_i] = 0;
- }
/* collect a line from file */
line_buffer = fgets(line_buffer, 128, file);
- if (line_buffer == NULL) {
+ if(line_buffer == NULL)
goto done; /* end of file */
- }
/* loop over names to see if line looks like assignment */
- for (setting_i = 0; setting_i < setting_count; setting_i++) {
+ for(setting_i = 0; setting_i < setting_count; setting_i++) {
size_t setting_name_len = 0;
const char *setting_name = NULL;
char line_prefix[128];
setting_name = setting_names[setting_i];
setting_name_len = HDstrlen(setting_name);
- if (HDsnprintf(line_prefix, 128, "%s=", setting_name) < 0) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTCOPY, FAIL,
- "unable to format line prefix")
- }
+ if(HDsnprintf(line_prefix, 128, "%s=", setting_name) < 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTCOPY, FAIL, "unable to format line prefix")
/* found a matching name? */
- if (!HDstrncmp(line_buffer, line_prefix, setting_name_len + 1)) {
+ if(!HDstrncmp(line_buffer, line_prefix, setting_name_len + 1)) {
found_setting = 1;
/* skip NULL destination buffer */
- if (setting_pointers[setting_i] == NULL) {
+ if(setting_pointers[setting_i] == NULL)
break;
- }
/* advance to end of name in string */
do {
line_buffer++;
} while (*line_buffer != 0 && *line_buffer != '=');
- if (*line_buffer == 0 || *(line_buffer+1) == 0) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "incomplete assignment in file")
- }
+ if(*line_buffer == 0 || *(line_buffer+1) == 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "incomplete assignment in file")
line_buffer++; /* was pointing at '='; advance */
/* copy line buffer into out pointer */
- if (HDstrncpy(
- setting_pointers[setting_i],
- (const char *)line_buffer,
- HDstrlen(line_buffer))
- == NULL)
- {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTCOPY, FAIL,
- "unable to copy line into pointer")
- }
+ HDstrncpy(setting_pointers[setting_i], (const char *)line_buffer, HDstrlen(line_buffer));
/* "trim" tailing whitespace by replacing with null terminator*/
buffer_i = 0;
- while (!isspace(setting_pointers[setting_i][buffer_i])) {
+ while(!HDisspace(setting_pointers[setting_i][buffer_i]))
buffer_i++;
- }
setting_pointers[setting_i][buffer_i] = '\0';
break; /* have read setting; don't compare with others */
@@ -2561,76 +2118,46 @@ H5FD_s3comms_load_aws_profile(const char *profile_name,
#else
ret = HDsnprintf(awspath, 117, "%s/.aws/", getenv("HOME")) ;
#endif
- if (ret < 0 || (size_t)ret >= 117) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTCOPY, FAIL,
- "unable to format home-aws path")
- }
+ if(ret < 0 || (size_t)ret >= 117)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTCOPY, FAIL, "unable to format home-aws path")
ret = HDsnprintf(filepath, 128, "%s%s", awspath, "credentials");
- if (ret < 0 || (size_t)ret >= 128) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTCOPY, FAIL,
- "unable to format credentials path")
- }
-
- credfile = fopen(filepath, "r");
- if (credfile != NULL) {
- if (H5FD__s3comms_load_aws_creds_from_file(
- credfile,
- profile_name,
- key_id_out,
- secret_access_key_out,
- aws_region_out)
- == FAIL)
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to load from aws credentials")
- }
- if (fclose(credfile) == EOF) {
- HGOTO_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL,
- "unable to close credentials file")
- }
+ if(ret < 0 || (size_t)ret >= 128)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTCOPY, FAIL, "unable to format credentials path")
+
+ credfile = HDfopen(filepath, "r");
+ if(credfile != NULL) {
+ if(H5FD__s3comms_load_aws_creds_from_file(credfile, profile_name, key_id_out,
+ secret_access_key_out, aws_region_out) == FAIL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to load from aws credentials")
+ if(HDfclose(credfile) == EOF)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "unable to close credentials file")
credfile = NULL;
} /* end if credential file opened */
ret = HDsnprintf(filepath, 128, "%s%s", awspath, "config");
- if (ret < 0 || (size_t)ret >= 128) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTCOPY, FAIL,
- "unable to format config path")
- }
- credfile = fopen(filepath, "r");
- if (credfile != NULL) {
- if (H5FD__s3comms_load_aws_creds_from_file(
- credfile,
- profile_name,
+ if(ret < 0 || (size_t)ret >= 128)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTCOPY, FAIL, "unable to format config path")
+ credfile = HDfopen(filepath, "r");
+ if(credfile != NULL) {
+ if(H5FD__s3comms_load_aws_creds_from_file( credfile, profile_name,
(*key_id_out == 0) ? key_id_out : NULL,
(*secret_access_key_out == 0) ? secret_access_key_out : NULL,
- (*aws_region_out == 0) ? aws_region_out : NULL)
- == FAIL)
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to load from aws config")
- }
- if (fclose(credfile) == EOF) {
- HGOTO_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL,
- "unable to close config file")
- }
+ (*aws_region_out == 0) ? aws_region_out : NULL) == FAIL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to load from aws config")
+ if(HDfclose(credfile) == EOF)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "unable to close config file")
credfile = NULL;
} /* end if credential file opened */
/* fail if not all three settings were loaded */
- if (*key_id_out == 0 ||
- *secret_access_key_out == 0 ||
- *aws_region_out == 0)
- {
+ if(*key_id_out == 0 || *secret_access_key_out == 0 || *aws_region_out == 0)
ret_value = FAIL;
- }
done:
- if (credfile != NULL) {
- if (fclose(credfile) == EOF) {
- HDONE_ERROR(H5E_ARGS, H5E_ARGS, FAIL,
- "problem error-closing aws configuration file")
- }
- }
+ if(credfile != NULL)
+ if(HDfclose(credfile) == EOF)
+ HDONE_ERROR(H5E_ARGS, H5E_ARGS, FAIL, "problem error-closing aws configuration file")
+
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5FD_s3comms_load_aws_profile() */
@@ -2675,16 +2202,14 @@ H5FD_s3comms_nlowercase(
HDfprintf(stdout, "called H5FD_s3comms_nlowercase.\n");
#endif
- if (dest == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "destination cannot be null.\n");
- }
+ if(dest == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "destination cannot be null.");
- if (len > 0) {
+ if(len > 0) {
HDmemcpy(dest, s, len);
do {
len--;
- dest[len] = (char)tolower( (int)dest[len] );
+ dest[len] = (char)HDtolower((int)dest[len]);
} while (len > 0);
}
@@ -2743,18 +2268,14 @@ H5FD_s3comms_parse_url(
HDprintf("called H5FD_s3comms_parse_url.\n");
#endif
- if (str == NULL || *str == '\0') {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "invalid url string");
- }
+ if(str == NULL || *str == '\0')
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid url string");
urllen = (long int)HDstrlen(str);
purl = (parsed_url_t *)H5MM_malloc(sizeof(parsed_url_t));
- if (purl == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL,
- "can't allocate space for parsed_url_t");
- }
+ if(purl == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL, "can't allocate space for parsed_url_t");
purl->magic = S3COMMS_PARSED_URL_MAGIC;
purl->scheme = NULL;
purl->host = NULL;
@@ -2767,38 +2288,27 @@ H5FD_s3comms_parse_url(
***************/
tmpstr = HDstrchr(curstr, ':');
- if (tmpstr == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "invalid SCHEME construction: probably not URL");
- }
+ if(tmpstr == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid SCHEME construction: probably not URL");
len = tmpstr - curstr;
HDassert( (0 <= len) && (len < urllen) );
- /* check for restrictions
- */
- for (i = 0; i < len; i++) {
+ /* check for restrictions */
+ for(i = 0; i < len; i++) {
/* scheme = [a-zA-Z+-.]+ (terminated by ":") */
- if (!isalpha(curstr[i]) &&
- '+' != curstr[i] &&
- '-' != curstr[i] &&
- '.' != curstr[i])
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "invalid SCHEME construction");
- }
+ if(!HDisalpha(curstr[i]) && '+' != curstr[i] && '-' != curstr[i] &&
+ '.' != curstr[i])
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid SCHEME construction");
}
- /* copy lowercased scheme to structure
- */
+
+ /* copy lowercased scheme to structure */
purl->scheme = (char *)H5MM_malloc(sizeof(char) * (size_t)(len + 1));
- if (purl->scheme == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL,
- "can't allocate space for SCHEME");
- }
- (void)HDstrncpy(purl->scheme, curstr, (size_t)len);
+ if(purl->scheme == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL, "can't allocate space for SCHEME");
+ HDstrncpy(purl->scheme, curstr, (size_t)len);
purl->scheme[len] = '\0';
- for ( i = 0; i < len; i++ ) {
- purl->scheme[i] = (char)tolower(purl->scheme[i]);
- }
+ for(i = 0; i < len; i++ )
+ purl->scheme[i] = (char)HDtolower(purl->scheme[i]);
/* Skip "://" */
tmpstr += 3;
@@ -2808,84 +2318,59 @@ H5FD_s3comms_parse_url(
* READ HOST *
*************/
- if (*curstr == '[') {
+ if(*curstr == '[') {
/* IPv6 */
- while (']' != *tmpstr) {
- if (tmpstr == 0) { /* end of string reached! */
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "reached end of URL: incomplete IPv6 HOST");
- }
+ while(']' != *tmpstr) {
+ /* end of string reached! */
+ if(tmpstr == 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "reached end of URL: incomplete IPv6 HOST");
tmpstr++;
}
tmpstr++;
} /* end if (IPv6) */
else {
- while (0 != *tmpstr) {
- if (':' == *tmpstr ||
- '/' == *tmpstr ||
- '?' == *tmpstr)
- {
+ while(0 != *tmpstr) {
+ if(':' == *tmpstr || '/' == *tmpstr || '?' == *tmpstr)
break;
- }
tmpstr++;
}
} /* end else (IPv4) */
len = tmpstr - curstr;
- if (len == 0) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "HOST substring cannot be empty");
- }
- else
- if (len > urllen) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "problem with length of HOST substring");
- }
+ if(len == 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "HOST substring cannot be empty")
+ else if(len > urllen)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem with length of HOST substring");
- /* copy host
- */
+ /* copy host */
purl->host = (char *)H5MM_malloc(sizeof(char) * (size_t)(len + 1));
- if (purl->host == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL,
- "can't allocate space for HOST");
- }
- (void)HDstrncpy(purl->host, curstr, (size_t)len);
+ if(purl->host == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL, "can't allocate space for HOST");
+ HDstrncpy(purl->host, curstr, (size_t)len);
purl->host[len] = 0;
/*************
* READ PORT *
*************/
- if (':' == *tmpstr) {
+ if(':' == *tmpstr) {
tmpstr += 1; /* advance past ':' */
curstr = tmpstr;
- while ((0 != *tmpstr) && ('/' != *tmpstr) && ('?' != *tmpstr)) {
+ while((0 != *tmpstr) && ('/' != *tmpstr) && ('?' != *tmpstr))
tmpstr++;
- }
len = tmpstr - curstr;
- if (len == 0) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "PORT element cannot be empty");
- }
- else
- if (len > urllen) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "problem with length of PORT substring");
- }
- for (i = 0; i < len; i ++) {
- if (!isdigit(curstr[i])) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "PORT is not a decimal string");
- }
- }
-
- /* copy port
- */
+ if(len == 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "PORT element cannot be empty")
+ else if(len > urllen)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem with length of PORT substring");
+ for(i = 0; i < len; i ++)
+ if(!HDisdigit(curstr[i]))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "PORT is not a decimal string");
+
+ /* copy port */
purl->port = (char *)H5MM_malloc(sizeof(char) * (size_t)(len + 1));
- if (purl->port == NULL) { /* cannot malloc */
- HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL,
- "can't allocate space for PORT");
- }
- (void)HDstrncpy(purl->port, curstr, (size_t)len);
+ if(purl->port == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL, "can't allocate space for PORT");
+ HDstrncpy(purl->port, curstr, (size_t)len);
purl->port[len] = 0;
} /* end if PORT element */
@@ -2893,28 +2378,22 @@ H5FD_s3comms_parse_url(
* READ PATH *
*************/
- if ('/' == *tmpstr) {
+ if('/' == *tmpstr) {
/* advance past '/' */
tmpstr += 1;
curstr = tmpstr;
- /* seek end of PATH
- */
- while ((0 != *tmpstr) && ('?' != *tmpstr)) {
+ /* seek end of PATH */
+ while((0 != *tmpstr) && ('?' != *tmpstr))
tmpstr++;
- }
len = tmpstr - curstr;
- if (len > urllen) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "problem with length of PATH substring");
- }
- if (len > 0) {
+ if(len > urllen)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem with length of PATH substring");
+ if(len > 0) {
purl->path = (char *)H5MM_malloc(sizeof(char) * (size_t)(len + 1));
- if (purl->path == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL,
- "can't allocate space for PATH");
- } /* cannot malloc path pointer */
- (void)HDstrncpy(purl->path, curstr, (size_t)len);
+ if(purl->path == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL, "can't allocate space for PATH");
+ HDstrncpy(purl->path, curstr, (size_t)len);
purl->path[len] = 0;
}
} /* end if PATH element */
@@ -2923,26 +2402,20 @@ H5FD_s3comms_parse_url(
* READ QUERY *
**************/
- if ('?' == *tmpstr) {
+ if('?' == *tmpstr) {
tmpstr += 1;
curstr = tmpstr;
- while (0 != *tmpstr) {
+ while(0 != *tmpstr)
tmpstr++;
- }
len = tmpstr - curstr;
- if (len == 0) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "QUERY cannot be empty");
- } else if (len > urllen) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "problem with length of QUERY substring");
- }
+ if(len == 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "QUERY cannot be empty")
+ else if(len > urllen)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem with length of QUERY substring");
purl->query = (char *)H5MM_malloc(sizeof(char) * (size_t)(len + 1));
- if (purl->query == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL,
- "can't allocate space for QUERY");
- } /* cannot malloc path pointer */
- (void)HDstrncpy(purl->query, curstr, (size_t)len);
+ if(purl->query == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTALLOC, FAIL, "can't allocate space for QUERY");
+ HDstrncpy(purl->query, curstr, (size_t)len);
purl->query[len] = 0;
} /* end if QUERY exists */
@@ -2950,9 +2423,9 @@ H5FD_s3comms_parse_url(
ret_value = SUCCEED;
done:
- if (ret_value == FAIL) {
+ if(ret_value == FAIL)
H5FD_s3comms_free_purl(purl);
- }
+
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5FD_s3comms_parse_url() */
@@ -3016,9 +2489,8 @@ H5FD_s3comms_percent_encode_char(
HDfprintf(stdout, "called H5FD_s3comms_percent_encode_char.\n");
#endif
- if (repr == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no destination `repr`.\n")
- }
+ if(repr == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no destination `repr`.")
#if S3COMMS_DEBUG
H5FD_s3comms_bytes_to_hex((char *)hex, s, 1, FALSE);
@@ -3026,7 +2498,7 @@ H5FD_s3comms_percent_encode_char(
HDfprintf(stdout, " CHAR-HEX: \"%s\"\n", hex);
#endif
- if (c <= (unsigned char)0x7f) {
+ if(c <= (unsigned char)0x7f) {
/* character represented in a single "byte"
* and single percent-code
*/
@@ -3035,11 +2507,8 @@ H5FD_s3comms_percent_encode_char(
#endif
*repr_len = 3;
chars_written = HDsnprintf(repr, 4, "%%%02X", c);
- if (chars_written < 0) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "cannot write char %c",
- c);
- }
+ if(chars_written < 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "cannot write char %c", c);
} /* end if single-byte unicode char */
else {
/* multi-byte, multi-percent representation
@@ -3092,16 +2561,9 @@ H5FD_s3comms_percent_encode_char(
acc += (stack_size > 2) ? 0x20 : 0; /* 0x00100000 */
acc += (stack_size > 3) ? 0x10 : 0; /* 0x00010000 */
stack_size--;
- chars_written = HDsnprintf(
- repr,
- 4,
- "%%%02X",
- (unsigned char)(acc + stack[stack_size]));
- if (chars_written < 0) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "cannot write char %c",
- c);
- }
+ chars_written = HDsnprintf( repr, 4, "%%%02X", (unsigned char)(acc + stack[stack_size]));
+ if(chars_written < 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "cannot write char %c", c);
*repr_len += 3;
/************************
@@ -3109,17 +2571,11 @@ H5FD_s3comms_percent_encode_char(
************************/
/* 10xxxxxx */
- for (i = 0; i < stack_size; i++) {
- chars_written = HDsnprintf(
- &repr[i*3 + 3],
- 4,
- "%%%02X",
- (unsigned char)(0x80 + stack[stack_size - 1 - i]));
- if (chars_written < 0) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "cannot write char %c",
- c);
- }
+ for(i = 0; i < stack_size; i++) {
+ chars_written = HDsnprintf( &repr[i*3 + 3], 4,
+ "%%%02X", (unsigned char)(0x80 + stack[stack_size - 1 - i]));
+ if(chars_written < 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "cannot write char %c", c);
*repr_len += 3;
} /* end for each continuation byte */
} /* end else (multi-byte) */
@@ -3190,38 +2646,24 @@ H5FD_s3comms_signing_key(
HDfprintf(stdout, "called H5FD_s3comms_signing_key.\n");
#endif
- if (md == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "Destination `md` cannot be NULL.\n")
- }
- if (secret == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "`secret` cannot be NULL.\n")
- }
- if (region == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "`region` cannot be NULL.\n")
- }
- if (iso8601now == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "`iso8601now` cannot be NULL.\n")
- }
+ if(md == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Destination `md` cannot be NULL.")
+ if(secret == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "`secret` cannot be NULL.")
+ if(region == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "`region` cannot be NULL.")
+ if(iso8601now == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "`iso8601now` cannot be NULL.")
AWS4_secret_len = 4 + HDstrlen(secret) + 1;
AWS4_secret = (char*)H5MM_malloc(sizeof(char *) * AWS4_secret_len);
- if (AWS4_secret == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "Could not allocate space.\n")
- }
+ if(AWS4_secret == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Could not allocate space.")
- /* prepend "AWS4" to start of the secret key
- */
+ /* prepend "AWS4" to start of the secret key */
ret = HDsnprintf(AWS4_secret, AWS4_secret_len,"%s%s", "AWS4", secret);
- if ((size_t)ret != (AWS4_secret_len - 1)) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "problem writing AWS4+secret `%s`",
- secret);
- }
+ if((size_t)ret != (AWS4_secret_len - 1))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem writing AWS4+secret `%s`", secret);
/* hash_func, key, len(key), msg, len(msg), digest_dest, digest_len_dest
* we know digest length, so ignore via NULL
@@ -3320,37 +2762,26 @@ H5FD_s3comms_tostringtosign(
HDfprintf(stdout, "called H5FD_s3comms_tostringtosign.\n");
#endif
- if (dest == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "destination buffer cannot be null.\n")
- }
- if (req == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "canonical request cannot be null.\n")
- }
- if (now == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "Timestring cannot be NULL.\n")
- }
- if (region == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "Region cannot be NULL.\n")
- }
+ if(dest == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "destination buffer cannot be null.")
+ if(req == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "canonical request cannot be null.")
+ if(now == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Timestring cannot be NULL.")
+ if(region == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Region cannot be NULL.")
- for (i = 0; i < 128; i++) {
+ for(i = 0; i < 128; i++)
tmp[i] = '\0';
- }
- for (i = 0; i < SHA256_DIGEST_LENGTH * 2 + 1; i++) {
+ for(i = 0; i < SHA256_DIGEST_LENGTH * 2 + 1; i++) {
checksum[i] = '\0';
hexsum[i] = '\0';
}
HDstrncpy(day, now, 8);
day[8] = '\0';
ret = HDsnprintf(tmp, 127, "%s/%s/s3/aws4_request", day, region);
- if (ret <= 0 || ret >= 127) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "problem adding day and region to string")
- }
+ if(ret <= 0 || ret >= 127)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "problem adding day and region to string")
HDmemcpy((dest + d), "AWS4-HMAC-SHA256\n", 17);
d = 17;
@@ -3363,24 +2794,14 @@ H5FD_s3comms_tostringtosign(
d += HDstrlen(tmp);
dest[d++] = '\n';
- SHA256((const unsigned char *)req,
- HDstrlen(req),
- checksum);
+ SHA256((const unsigned char *)req, HDstrlen(req), checksum);
- if (H5FD_s3comms_bytes_to_hex(
- hexsum,
- (const unsigned char *)checksum,
- SHA256_DIGEST_LENGTH,
- true)
- == FAIL)
- {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "could not create hex string");
- }
+ if(H5FD_s3comms_bytes_to_hex(hexsum, (const unsigned char *)checksum,
+ SHA256_DIGEST_LENGTH, true) == FAIL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "could not create hex string");
- for (i = 0; i < SHA256_DIGEST_LENGTH * 2; i++) {
+ for(i = 0; i < SHA256_DIGEST_LENGTH * 2; i++)
dest[d++] = hexsum[i];
- }
dest[d] = '\0';
@@ -3432,21 +2853,16 @@ H5FD_s3comms_trim(char *dest,
HDfprintf(stdout, "called H5FD_s3comms_trim.\n");
#endif
- if (dest == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "destination cannot be null.")
- }
- if (s == NULL) {
+ if(dest == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "destination cannot be null.")
+ if(s == NULL)
s_len = 0;
- }
- if (s_len > 0) {
+ if(s_len > 0) {
/* Find first non-whitespace character from start;
* reduce total length per character.
*/
- while ((s_len > 0) &&
- isspace((unsigned char)s[0]) && s_len > 0)
- {
+ while((s_len > 0) && HDisspace((unsigned char)s[0]) && s_len > 0) {
s++;
s_len--;
}
@@ -3455,14 +2871,13 @@ H5FD_s3comms_trim(char *dest,
* reduce length per-character.
* If length is 0 already, there is no non-whitespace character.
*/
- if (s_len > 0) {
+ if(s_len > 0) {
do {
s_len--;
- } while( isspace((unsigned char)s[s_len]) );
+ } while(HDisspace((unsigned char)s[s_len]));
s_len++;
- /* write output into dest
- */
+ /* write output into dest */
HDmemcpy(dest, s, s_len);
}
}
@@ -3534,54 +2949,36 @@ H5FD_s3comms_uriencode(
HDfprintf(stdout, "H5FD_s3comms_uriencode called.\n");
#endif
- if (s == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "source string cannot be NULL");
- }
- if (dest == NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "destination cannot be NULL");
- }
+ if(s == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "source string cannot be NULL");
+ if(dest == NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "destination cannot be NULL");
/* Write characters to destination, converting to percent-encoded
* "hex-utf-8" strings if necessary.
* e.g., '$' -> "%24"
*/
- for (s_off = 0; s_off < s_len; s_off++) {
+ for(s_off = 0; s_off < s_len; s_off++) {
c = s[s_off];
- if (isalnum(c) ||
- c == '.' ||
- c == '-' ||
- c == '_' ||
- c == '~' ||
- (c == '/' && encode_slash == FALSE))
- {
+ if(HDisalnum(c) || c == '.' || c == '-' || c == '_' ||
+ c == '~' || (c == '/' && encode_slash == FALSE))
dest[dest_off++] = c;
- }
else {
hex_off = 0;
- if (H5FD_s3comms_percent_encode_char(
- hex_buffer,
- (const unsigned char)c,
- &hex_len)
- == FAIL)
- {
+ if(H5FD_s3comms_percent_encode_char(hex_buffer, (const unsigned char)c,
+ &hex_len) == FAIL) {
hex_buffer[0] = c;
hex_buffer[1] = 0;
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "unable to percent-encode character \'%s\' "
- "at %d in \"%s\"", hex_buffer, (int)s_off, s);
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to percent-encode character \'%s\' " "at %d in \"%s\"", hex_buffer, (int)s_off, s);
}
- for (hex_off = 0; hex_off < hex_len; hex_off++) {
+ for(hex_off = 0; hex_off < hex_len; hex_off++)
dest[dest_off++] = hex_buffer[hex_off];
- }
} /* end else (not a regular character) */
} /* end for each character */
- if (dest_off < s_len)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "buffer overflow");
+ if(dest_off < s_len)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "buffer overflow");
*n_written = dest_off;