2013-03-14 03:35:26 +08:00
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
|
* Copyright by The HDF Group. *
|
|
|
|
|
* All rights reserved. *
|
|
|
|
|
* *
|
2013-04-04 03:15:13 +08:00
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
2013-03-14 03:35:26 +08:00
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
|
|
|
|
* the files COPYING and Copyright.html. COPYING can be found at the root *
|
|
|
|
|
* of the source code distribution tree; Copyright.html can be found at the *
|
2013-04-04 03:15:13 +08:00
|
|
|
|
* root level of an installed copy of the electronic document set and is *
|
|
|
|
|
* linked from the top-level documents page. It can also be found at *
|
|
|
|
|
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have access *
|
|
|
|
|
* to either file, you may request a copy from help@hdfgroup.org. *
|
2013-03-14 03:35:26 +08:00
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
2013-03-19 12:22:34 +08:00
|
|
|
|
/****************/
|
|
|
|
|
/* Module Setup */
|
|
|
|
|
/****************/
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
|
|
|
|
/* Interface initialization */
|
2013-03-19 12:22:34 +08:00
|
|
|
|
#define H5_INTERFACE_INIT_FUNC H5PL__init_interface
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
2013-03-19 12:22:34 +08:00
|
|
|
|
|
|
|
|
|
/***********/
|
|
|
|
|
/* Headers */
|
|
|
|
|
/***********/
|
2013-03-14 03:35:26 +08:00
|
|
|
|
#include "H5private.h" /* Generic Functions */
|
|
|
|
|
#include "H5Eprivate.h" /* Error handling */
|
|
|
|
|
#include "H5MMprivate.h" /* Memory management */
|
2013-03-19 12:22:34 +08:00
|
|
|
|
#include "H5PLprivate.h" /* Plugin */
|
2013-03-14 03:35:26 +08:00
|
|
|
|
#include "H5Zprivate.h" /* Filter pipeline */
|
2013-03-19 12:22:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/****************/
|
|
|
|
|
/* Local Macros */
|
|
|
|
|
/****************/
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
2013-03-19 12:22:34 +08:00
|
|
|
|
#define H5PL_MAX_PATH_NUM 16
|
|
|
|
|
|
|
|
|
|
/****************************/
|
|
|
|
|
/* Macros for supporting
|
|
|
|
|
* both Windows and Unix */
|
|
|
|
|
/****************************/
|
2013-03-20 00:25:44 +08:00
|
|
|
|
/* Windows support */
|
2013-03-19 12:22:34 +08:00
|
|
|
|
#ifdef H5_HAVE_WIN32_API
|
2013-03-23 05:39:53 +08:00
|
|
|
|
|
2013-03-21 02:21:28 +08:00
|
|
|
|
#define H5PL_PATH_SEPARATOR ";"
|
2013-03-23 05:39:53 +08:00
|
|
|
|
|
2013-03-19 12:22:34 +08:00
|
|
|
|
/* Handle for dynamic library */
|
|
|
|
|
#define H5PL_HANDLE HINSTANCE
|
|
|
|
|
|
|
|
|
|
/* Get a handle to a plugin library. Windows: TEXT macro handles Unicode strings */
|
|
|
|
|
#define H5PL_OPEN_DLIB(S) LoadLibraryEx(TEXT(S), NULL, LOAD_WITH_ALTERED_SEARCH_PATH)
|
|
|
|
|
|
|
|
|
|
/* Get the address of a symbol in dynamic library */
|
|
|
|
|
#define H5PL_GET_LIB_FUNC(H,N) GetProcAddress(H,N)
|
|
|
|
|
|
|
|
|
|
/* Close dynamic library */
|
|
|
|
|
#define H5PL_CLOSE_LIB(H) FreeLibrary(H)
|
|
|
|
|
|
|
|
|
|
/* Clear error - nothing to do */
|
|
|
|
|
#define H5PL_CLR_ERROR
|
|
|
|
|
|
2013-04-05 04:57:59 +08:00
|
|
|
|
typedef const void *(__cdecl *H5PL_get_plugin_info_t)(void);
|
2013-03-20 04:07:03 +08:00
|
|
|
|
|
2013-03-23 05:39:53 +08:00
|
|
|
|
/* Unix support */
|
2013-03-19 12:22:34 +08:00
|
|
|
|
#else /* H5_HAVE_WIN32_API */
|
2013-03-23 05:39:53 +08:00
|
|
|
|
|
2013-03-21 02:21:28 +08:00
|
|
|
|
#define H5PL_PATH_SEPARATOR ":"
|
2013-03-23 05:39:53 +08:00
|
|
|
|
|
2013-03-19 12:22:34 +08:00
|
|
|
|
/* Handle for dynamic library */
|
|
|
|
|
#define H5PL_HANDLE void *
|
|
|
|
|
|
|
|
|
|
/* Get a handle to a plugin library. Windows: TEXT macro handles Unicode strings */
|
2013-03-26 04:34:05 +08:00
|
|
|
|
#define H5PL_OPEN_DLIB(S) dlopen(S, RTLD_NOW)
|
2013-03-19 12:22:34 +08:00
|
|
|
|
|
|
|
|
|
/* Get the address of a symbol in dynamic library */
|
|
|
|
|
#define H5PL_GET_LIB_FUNC(H,N) dlsym(H,N)
|
|
|
|
|
|
|
|
|
|
/* Close dynamic library */
|
|
|
|
|
#define H5PL_CLOSE_LIB(H) dlclose(H)
|
|
|
|
|
|
|
|
|
|
/* Clear error */
|
|
|
|
|
#define H5PL_CLR_ERROR dlerror()
|
|
|
|
|
|
2013-04-05 04:57:59 +08:00
|
|
|
|
typedef const void *(*H5PL_get_plugin_info_t)(void);
|
2013-03-19 12:22:34 +08:00
|
|
|
|
#endif /* H5_HAVE_WIN32_API */
|
|
|
|
|
|
2013-09-20 00:38:08 +08:00
|
|
|
|
#define H5PL_DEFAULT_PATH H5_DEFAULT_PLUGINDIR
|
2013-09-06 23:15:50 +08:00
|
|
|
|
|
2013-03-23 05:39:53 +08:00
|
|
|
|
/* Special symbol to indicate no plugin loading */
|
|
|
|
|
#define H5PL_NO_PLUGIN "::"
|
2013-03-19 12:22:34 +08:00
|
|
|
|
|
|
|
|
|
/******************/
|
|
|
|
|
/* Local Typedefs */
|
|
|
|
|
/******************/
|
|
|
|
|
|
|
|
|
|
/* Type for the list of info for opened plugin libraries */
|
|
|
|
|
typedef struct H5PL_table_t {
|
|
|
|
|
H5PL_type_t pl_type; /* plugin type */
|
|
|
|
|
int pl_id; /* ID for the plugin */
|
|
|
|
|
H5PL_HANDLE handle; /* plugin handle */
|
|
|
|
|
} H5PL_table_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************/
|
|
|
|
|
/* Local Prototypes */
|
|
|
|
|
/********************/
|
|
|
|
|
|
|
|
|
|
static herr_t H5PL__init_path_table(void);
|
2013-04-05 04:57:59 +08:00
|
|
|
|
static htri_t H5PL__find(H5PL_type_t plugin_type, int type_id, char *dir, const void **info);
|
|
|
|
|
static htri_t H5PL__open(H5PL_type_t pl_type, char *libname, int plugin_id, const void **pl_info);
|
|
|
|
|
static htri_t H5PL__search_table(H5PL_type_t plugin_type, int type_id, const void **info);
|
2013-03-19 12:22:34 +08:00
|
|
|
|
static herr_t H5PL__close(H5PL_HANDLE handle);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********************/
|
|
|
|
|
/* Package Variables */
|
|
|
|
|
/*********************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************/
|
|
|
|
|
/* Library Private Variables */
|
|
|
|
|
/*****************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*******************/
|
|
|
|
|
/* Local Variables */
|
|
|
|
|
/*******************/
|
|
|
|
|
|
|
|
|
|
/* Table for opened plugin libraries */
|
|
|
|
|
static size_t H5PL_table_alloc_g = 0;
|
|
|
|
|
static size_t H5PL_table_used_g = 0;
|
|
|
|
|
static H5PL_table_t *H5PL_table_g = NULL;
|
|
|
|
|
|
|
|
|
|
/* Table of location paths for plugin libraries */
|
|
|
|
|
static char *H5PL_path_table_g[H5PL_MAX_PATH_NUM];
|
|
|
|
|
static size_t H5PL_num_paths_g = 0;
|
2013-04-04 21:29:14 +08:00
|
|
|
|
static hbool_t H5PL_path_found_g = FALSE;
|
2013-03-19 12:22:34 +08:00
|
|
|
|
|
2013-04-04 21:29:14 +08:00
|
|
|
|
/* Whether to preload pathnames for plugin libraries */
|
2013-03-23 05:39:53 +08:00
|
|
|
|
static hbool_t H5PL_no_plugin_g = FALSE;
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------
|
|
|
|
|
NAME
|
2013-03-19 12:22:34 +08:00
|
|
|
|
H5PL__init_interface -- Initialize interface-specific information
|
2013-03-14 03:35:26 +08:00
|
|
|
|
USAGE
|
2013-03-19 12:22:34 +08:00
|
|
|
|
herr_t H5PL__init_interface()
|
2013-03-14 03:35:26 +08:00
|
|
|
|
RETURNS
|
|
|
|
|
Non-negative on success/Negative on failure
|
|
|
|
|
DESCRIPTION
|
|
|
|
|
Initializes any interface-specific data or routines.
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------*/
|
|
|
|
|
static herr_t
|
2013-03-19 12:22:34 +08:00
|
|
|
|
H5PL__init_interface(void)
|
2013-03-14 03:35:26 +08:00
|
|
|
|
{
|
2013-04-04 21:29:14 +08:00
|
|
|
|
char *preload_path;
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
2013-04-04 21:29:14 +08:00
|
|
|
|
FUNC_ENTER_STATIC_NOERR
|
2013-03-23 05:39:53 +08:00
|
|
|
|
|
|
|
|
|
/* Retrieve pathnames from HDF5_PLUGIN_PRELOAD if the user sets it
|
|
|
|
|
* to tell the library to load plugin libraries without search.
|
|
|
|
|
*/
|
2013-04-04 21:29:14 +08:00
|
|
|
|
if(NULL != (preload_path = HDgetenv("HDF5_PLUGIN_PRELOAD"))) {
|
|
|
|
|
/* Special symbal "::" means no plugin during data reading. */
|
|
|
|
|
if(!HDstrcmp(preload_path, H5PL_NO_PLUGIN))
|
|
|
|
|
H5PL_no_plugin_g = TRUE;
|
|
|
|
|
} /* end if */
|
2013-03-23 05:39:53 +08:00
|
|
|
|
|
2013-04-04 21:29:14 +08:00
|
|
|
|
FUNC_LEAVE_NOAPI(SUCCEED)
|
2013-03-19 12:22:34 +08:00
|
|
|
|
} /* end H5PL__init_interface() */
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
2013-03-23 05:39:53 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: H5PL_no_plugin
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Quick way for filter module to query whether to load plugin
|
|
|
|
|
*
|
|
|
|
|
* Return: TRUE: No plugin loading during data reading
|
|
|
|
|
*
|
|
|
|
|
* FALSE: Load plugin during data reading
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* 20 February 2013
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2013-04-04 21:29:14 +08:00
|
|
|
|
htri_t
|
|
|
|
|
H5PL_no_plugin(void)
|
2013-03-23 05:39:53 +08:00
|
|
|
|
{
|
2013-04-04 21:29:14 +08:00
|
|
|
|
htri_t ret_value;
|
2013-03-23 05:39:53 +08:00
|
|
|
|
|
2013-04-04 21:29:14 +08:00
|
|
|
|
FUNC_ENTER_NOAPI(FAIL)
|
2013-03-23 05:39:53 +08:00
|
|
|
|
|
2013-04-05 04:57:59 +08:00
|
|
|
|
ret_value = (htri_t)H5PL_no_plugin_g;
|
2013-03-23 05:39:53 +08:00
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
2013-04-04 21:29:14 +08:00
|
|
|
|
} /* end H5PL_no_plugin() */
|
2013-03-23 05:39:53 +08:00
|
|
|
|
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: H5PL_term_interface
|
|
|
|
|
*
|
2013-03-15 04:00:48 +08:00
|
|
|
|
* Purpose: Terminate the H5PL interface: release all memory, reset all
|
2013-03-14 03:35:26 +08:00
|
|
|
|
* global variables to initial values. This only happens if all
|
|
|
|
|
* types have been destroyed from other interfaces.
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: Positive if any action was taken that might
|
|
|
|
|
* affect some other interface; zero otherwise.
|
|
|
|
|
*
|
|
|
|
|
* Failure: Negative.
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* 20 February 2013
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
H5PL_term_interface(void)
|
|
|
|
|
{
|
2013-03-19 12:22:34 +08:00
|
|
|
|
int i = 0;
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
|
|
|
|
FUNC_ENTER_NOAPI_NOINIT_NOERR
|
|
|
|
|
|
|
|
|
|
if(H5_interface_initialize_g) {
|
2013-03-19 12:22:34 +08:00
|
|
|
|
size_t u; /* Local index variable */
|
|
|
|
|
|
2013-03-15 04:00:48 +08:00
|
|
|
|
/* Close opened dynamic libraries */
|
2013-03-19 12:22:34 +08:00
|
|
|
|
for(u = 0; u < H5PL_table_used_g; u++)
|
|
|
|
|
H5PL__close((H5PL_table_g[u]).handle);
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
2013-03-15 04:00:48 +08:00
|
|
|
|
/* Free the table of dynamic libraries */
|
2013-03-14 03:35:26 +08:00
|
|
|
|
H5PL_table_g = (H5PL_table_t *)H5MM_xfree(H5PL_table_g);
|
|
|
|
|
H5PL_table_used_g = H5PL_table_alloc_g = 0;
|
|
|
|
|
|
2013-03-15 04:00:48 +08:00
|
|
|
|
/* Free the table of search paths */
|
2013-03-19 12:22:34 +08:00
|
|
|
|
for(u = 0; u < H5PL_num_paths_g; u++)
|
|
|
|
|
if(H5PL_path_table_g[u])
|
|
|
|
|
H5PL_path_table_g[u] = (char *)H5MM_xfree(H5PL_path_table_g[u]);
|
|
|
|
|
H5PL_num_paths_g = 0;
|
|
|
|
|
H5PL_path_found_g = FALSE;
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
|
|
|
|
H5_interface_initialize_g = 0;
|
|
|
|
|
i = 1;
|
|
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
|
|
FUNC_LEAVE_NOAPI(i)
|
|
|
|
|
} /* end H5PL_term_interface() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: H5PL_load
|
|
|
|
|
*
|
2013-03-15 04:00:48 +08:00
|
|
|
|
* Purpose: Given the plugin type and identifier, this function searches
|
|
|
|
|
* and/or loads a dynamic plugin library first among the already
|
|
|
|
|
* opened libraries then in the designated location paths.
|
2013-03-14 03:35:26 +08:00
|
|
|
|
*
|
2013-03-19 12:22:34 +08:00
|
|
|
|
* Return: Non-NULL on success/NULL on failure
|
2013-03-14 03:35:26 +08:00
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* 13 February 2013
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2013-04-05 04:57:59 +08:00
|
|
|
|
const void *
|
2013-03-14 03:35:26 +08:00
|
|
|
|
H5PL_load(H5PL_type_t type, int id)
|
|
|
|
|
{
|
2013-04-05 04:57:59 +08:00
|
|
|
|
htri_t found; /* Whether the plugin was found */
|
|
|
|
|
const void *plugin_info = NULL;
|
|
|
|
|
const void *ret_value = NULL;
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
|
|
|
|
FUNC_ENTER_NOAPI(NULL)
|
|
|
|
|
|
2013-09-20 00:38:08 +08:00
|
|
|
|
/* Check for "no plugins" indicated" */
|
|
|
|
|
if(H5PL_no_plugin_g)
|
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "required dynamically loaded plugin filter '%d' is not available", id)
|
|
|
|
|
|
2013-03-19 12:22:34 +08:00
|
|
|
|
/* Initialize the location paths for dynamic libraries, if they aren't
|
|
|
|
|
* already set up.
|
|
|
|
|
*/
|
|
|
|
|
if(FALSE == H5PL_path_found_g)
|
|
|
|
|
if(H5PL__init_path_table() < 0)
|
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTINIT, NULL, "can't initialize search path table")
|
|
|
|
|
|
2013-03-14 03:35:26 +08:00
|
|
|
|
/* Search in the table of already loaded plugin libraries */
|
2013-04-05 04:57:59 +08:00
|
|
|
|
if((found = H5PL__search_table(type, id, &plugin_info)) < 0)
|
2013-03-14 03:35:26 +08:00
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, NULL, "search in table failed")
|
|
|
|
|
|
2013-03-19 12:22:34 +08:00
|
|
|
|
/* If not found, iterate through the path table to find the right dynamic library */
|
|
|
|
|
if(!found) {
|
|
|
|
|
size_t i; /* Local index variable */
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < H5PL_num_paths_g; i++) {
|
2013-04-05 04:57:59 +08:00
|
|
|
|
if((found = H5PL__find(type, id, H5PL_path_table_g[i], &plugin_info)) < 0)
|
2013-03-19 12:22:34 +08:00
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, NULL, "search in paths failed")
|
|
|
|
|
|
|
|
|
|
/* Break out if found */
|
|
|
|
|
if(found) {
|
|
|
|
|
HDassert(plugin_info);
|
|
|
|
|
break;
|
|
|
|
|
} /* end if */
|
|
|
|
|
} /* end for */
|
|
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
|
|
/* Check if we found the plugin */
|
|
|
|
|
if(found)
|
|
|
|
|
ret_value = plugin_info;
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
|
|
|
|
} /* end H5PL_load() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: H5PL__init_path_table
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Initialize the path table.
|
|
|
|
|
*
|
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* 18 March 2013
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
|
|
|
|
H5PL__init_path_table(void)
|
|
|
|
|
{
|
|
|
|
|
char *dl_path = NULL;
|
|
|
|
|
char *origin_dl_path;
|
|
|
|
|
char *dir;
|
|
|
|
|
herr_t ret_value = SUCCEED; /* Return value */
|
|
|
|
|
|
|
|
|
|
FUNC_ENTER_STATIC
|
|
|
|
|
|
|
|
|
|
/* Retrieve paths from HDF5_PLUGIN_PATH if the user sets it
|
|
|
|
|
* or from the default paths if it isn't set.
|
|
|
|
|
*/
|
|
|
|
|
origin_dl_path = HDgetenv("HDF5_PLUGIN_PATH");
|
|
|
|
|
if(NULL == origin_dl_path)
|
|
|
|
|
dl_path = HDstrdup(H5PL_DEFAULT_PATH);
|
|
|
|
|
else
|
|
|
|
|
dl_path = HDstrdup(origin_dl_path);
|
|
|
|
|
if(NULL == dl_path)
|
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path")
|
|
|
|
|
|
|
|
|
|
/* Put paths in the path table. They are separated by ":" */
|
|
|
|
|
dir = HDstrtok(dl_path, H5PL_PATH_SEPARATOR);
|
|
|
|
|
while(dir) {
|
2013-04-04 21:29:14 +08:00
|
|
|
|
/* Check for too many directories in path */
|
|
|
|
|
if(H5PL_num_paths_g == H5PL_MAX_PATH_NUM)
|
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "too many directories in path for table")
|
2013-03-19 12:22:34 +08:00
|
|
|
|
if(NULL == (H5PL_path_table_g[H5PL_num_paths_g] = HDstrdup(dir)))
|
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path")
|
|
|
|
|
H5PL_num_paths_g++;
|
|
|
|
|
dir = HDstrtok(NULL, H5PL_PATH_SEPARATOR);
|
|
|
|
|
} /* end while */
|
|
|
|
|
|
|
|
|
|
H5PL_path_found_g = TRUE;
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
if(dl_path)
|
|
|
|
|
dl_path = (char *)H5MM_xfree(dl_path);
|
|
|
|
|
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
2013-03-19 12:22:34 +08:00
|
|
|
|
} /* end H5PL__init_path_table() */
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2013-03-19 12:22:34 +08:00
|
|
|
|
* Function: H5PL__find
|
2013-03-14 03:35:26 +08:00
|
|
|
|
*
|
2013-03-16 05:25:30 +08:00
|
|
|
|
* Purpose: Given a path, this function opens the directory and envokes
|
|
|
|
|
* another function to go through all files to find the right
|
2013-03-17 05:16:22 +08:00
|
|
|
|
* plugin library. Two function definitions are for Unix and
|
|
|
|
|
* Windows.
|
2013-03-14 03:35:26 +08:00
|
|
|
|
*
|
|
|
|
|
* Return: TRUE on success,
|
|
|
|
|
* FALSE on not found,
|
|
|
|
|
* negative on failure
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* 13 February 2013
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2013-03-17 05:16:22 +08:00
|
|
|
|
#ifndef H5_HAVE_WIN32_API
|
2013-03-19 12:22:34 +08:00
|
|
|
|
static htri_t
|
2013-04-05 04:57:59 +08:00
|
|
|
|
H5PL__find(H5PL_type_t plugin_type, int type_id, char *dir, const void **info)
|
2013-03-14 03:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
char *pathname = NULL;
|
|
|
|
|
DIR *dirp = NULL;
|
2013-03-19 12:22:34 +08:00
|
|
|
|
struct dirent *dp;
|
2013-03-14 03:35:26 +08:00
|
|
|
|
htri_t ret_value = FALSE;
|
|
|
|
|
|
2013-03-19 12:22:34 +08:00
|
|
|
|
FUNC_ENTER_STATIC
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
2013-03-15 04:00:48 +08:00
|
|
|
|
/* Open the directory */
|
2013-03-16 05:25:30 +08:00
|
|
|
|
if(!(dirp = HDopendir(dir)))
|
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_OPENERROR, FAIL, "can't open directory")
|
|
|
|
|
|
|
|
|
|
/* Iterates through all entries in the directory to find the right plugin library */
|
2013-04-04 21:29:14 +08:00
|
|
|
|
while(NULL != (dp = HDreaddir(dirp))) {
|
2013-03-19 12:22:34 +08:00
|
|
|
|
/* The library we are looking for should be called libxxx.so... on Unix
|
|
|
|
|
* or libxxx.xxx.dylib on Mac.
|
|
|
|
|
*/
|
|
|
|
|
if(!HDstrncmp(dp->d_name, "lib", (size_t)3) &&
|
|
|
|
|
(HDstrstr(dp->d_name, ".so") || HDstrstr(dp->d_name, ".dylib"))) {
|
|
|
|
|
h5_stat_t my_stat;
|
2013-04-04 21:29:14 +08:00
|
|
|
|
size_t pathname_len;
|
2013-03-19 12:22:34 +08:00
|
|
|
|
htri_t found_in_dir;
|
|
|
|
|
|
2013-04-04 21:29:14 +08:00
|
|
|
|
/* Allocate & initialize the path name */
|
|
|
|
|
pathname_len = HDstrlen(dir) + HDstrlen(dp->d_name) + 2;
|
|
|
|
|
if(NULL == (pathname = (char *)H5MM_malloc(pathname_len)))
|
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path")
|
|
|
|
|
HDsnprintf(pathname, pathname_len, "%s/%s", dir, dp->d_name);
|
2013-03-19 12:22:34 +08:00
|
|
|
|
|
2013-04-04 21:29:14 +08:00
|
|
|
|
/* Get info for directory entry */
|
2013-03-19 12:22:34 +08:00
|
|
|
|
if(HDstat(pathname, &my_stat) == -1)
|
2013-05-22 01:30:54 +08:00
|
|
|
|
HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't stat file: %s", HDstrerror(errno))
|
2013-03-19 12:22:34 +08:00
|
|
|
|
|
|
|
|
|
/* If it is a directory, skip it */
|
|
|
|
|
if(S_ISDIR(my_stat.st_mode))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* Attempt to open the dynamic library as a filter library */
|
|
|
|
|
if((found_in_dir = H5PL__open(plugin_type, pathname, type_id, info)) < 0)
|
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "search in directory failed")
|
|
|
|
|
if(found_in_dir) {
|
|
|
|
|
/* Indicate success */
|
2013-04-04 21:29:14 +08:00
|
|
|
|
HGOTO_DONE(TRUE)
|
2013-03-19 12:22:34 +08:00
|
|
|
|
} /* end if */
|
|
|
|
|
else
|
2013-04-04 21:29:14 +08:00
|
|
|
|
HDassert(pathname);
|
|
|
|
|
pathname = (char *)H5MM_xfree(pathname);
|
2013-03-19 12:22:34 +08:00
|
|
|
|
} /* end if */
|
|
|
|
|
} /* end while */
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
|
|
|
|
done:
|
2013-03-19 12:22:34 +08:00
|
|
|
|
if(dirp)
|
|
|
|
|
if(HDclosedir(dirp) < 0)
|
2013-05-22 01:30:54 +08:00
|
|
|
|
HDONE_ERROR(H5E_FILE, H5E_CLOSEERROR, FAIL, "can't close directory: %s", HDstrerror(errno))
|
2013-03-14 03:35:26 +08:00
|
|
|
|
if(pathname)
|
|
|
|
|
pathname = (char *)H5MM_xfree(pathname);
|
|
|
|
|
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
2013-03-19 12:22:34 +08:00
|
|
|
|
} /* end H5PL__find() */
|
2013-04-04 21:29:14 +08:00
|
|
|
|
#else /* H5_HAVE_WIN32_API */
|
2013-03-19 12:22:34 +08:00
|
|
|
|
static htri_t
|
2013-04-05 04:57:59 +08:00
|
|
|
|
H5PL__find(H5PL_type_t plugin_type, int type_id, char *dir, const void **info)
|
2013-03-17 05:16:22 +08:00
|
|
|
|
{
|
|
|
|
|
WIN32_FIND_DATA fdFile;
|
2013-03-19 12:22:34 +08:00
|
|
|
|
HANDLE hFind;
|
|
|
|
|
char *pathname = NULL;
|
2013-03-21 02:21:28 +08:00
|
|
|
|
char service[2048];
|
2013-04-04 21:29:14 +08:00
|
|
|
|
htri_t ret_value = FALSE;
|
2013-03-17 05:16:22 +08:00
|
|
|
|
|
2013-03-19 12:22:34 +08:00
|
|
|
|
FUNC_ENTER_STATIC
|
2013-03-17 05:16:22 +08:00
|
|
|
|
|
2013-03-21 02:21:28 +08:00
|
|
|
|
/* Specify a file mask. *.* = We want everything! */
|
2013-06-06 01:55:09 +08:00
|
|
|
|
sprintf(service, "%s\\*.dll", dir);
|
2013-03-21 02:21:28 +08:00
|
|
|
|
if((hFind = FindFirstFile(service, &fdFile)) == INVALID_HANDLE_VALUE)
|
2013-03-17 05:16:22 +08:00
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_OPENERROR, FAIL, "can't open directory")
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
/* Find first file will always return "."
|
2013-03-19 12:22:34 +08:00
|
|
|
|
* and ".." as the first two directories.
|
|
|
|
|
*/
|
2013-03-17 05:16:22 +08:00
|
|
|
|
if(HDstrcmp(fdFile.cFileName, ".") != 0 && HDstrcmp(fdFile.cFileName, "..") != 0) {
|
2013-04-04 21:29:14 +08:00
|
|
|
|
size_t pathname_len;
|
|
|
|
|
htri_t found_in_dir;
|
2013-03-19 12:22:34 +08:00
|
|
|
|
|
2013-04-04 21:29:14 +08:00
|
|
|
|
/* Allocate & initialize the path name */
|
|
|
|
|
pathname_len = HDstrlen(dir) + HDstrlen(fdFile.cFileName) + 2;
|
|
|
|
|
if(NULL == (pathname = (char *)H5MM_malloc(pathname_len)))
|
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path")
|
|
|
|
|
HDsnprintf(pathname, pathname_len, "%s\\%s", dir, fdFile.cFileName);
|
2013-03-17 05:16:22 +08:00
|
|
|
|
|
|
|
|
|
/* Is the entity a File or Folder? */
|
2013-04-04 21:29:14 +08:00
|
|
|
|
if(fdFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
2013-03-17 05:16:22 +08:00
|
|
|
|
continue;
|
|
|
|
|
|
2013-03-19 12:22:34 +08:00
|
|
|
|
if((found_in_dir = H5PL__open(plugin_type, pathname, type_id, info)) < 0)
|
2013-03-17 05:16:22 +08:00
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "search in directory failed")
|
|
|
|
|
if(found_in_dir) {
|
2013-03-19 12:22:34 +08:00
|
|
|
|
/* Indicate success */
|
2013-04-04 21:29:14 +08:00
|
|
|
|
HGOTO_DONE(TRUE)
|
2013-03-19 12:22:34 +08:00
|
|
|
|
} /* end if */
|
|
|
|
|
else
|
2013-04-04 21:29:14 +08:00
|
|
|
|
HDassert(pathname);
|
|
|
|
|
pathname = (char *)H5MM_xfree(pathname);
|
2013-03-19 12:22:34 +08:00
|
|
|
|
} /* end if */
|
2013-03-17 05:16:22 +08:00
|
|
|
|
} while(FindNextFile(hFind, &fdFile)); /* Find the next file. */
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
if(hFind)
|
|
|
|
|
FindClose(hFind);
|
2013-03-19 12:22:34 +08:00
|
|
|
|
if(pathname)
|
|
|
|
|
pathname = (char *)H5MM_xfree(pathname);
|
2013-03-17 05:16:22 +08:00
|
|
|
|
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
2013-03-19 12:22:34 +08:00
|
|
|
|
} /* end H5PL__find() */
|
2013-04-04 21:29:14 +08:00
|
|
|
|
#endif /* H5_HAVE_WIN32_API */
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
2013-03-16 05:25:30 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2013-03-19 12:22:34 +08:00
|
|
|
|
* Function: H5PL__open
|
2013-03-16 05:25:30 +08:00
|
|
|
|
*
|
|
|
|
|
* Purpose: Iterates through all files to find the right plugin library.
|
|
|
|
|
* It loads the dynamic plugin library and keeps it on the list
|
|
|
|
|
* of loaded libraries.
|
|
|
|
|
*
|
|
|
|
|
* Return: TRUE on success,
|
|
|
|
|
* FALSE on not found,
|
|
|
|
|
* negative on failure
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* 13 February 2013
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2013-03-19 12:22:34 +08:00
|
|
|
|
static htri_t
|
2013-04-05 04:57:59 +08:00
|
|
|
|
H5PL__open(H5PL_type_t pl_type, char *libname, int pl_id, const void **pl_info)
|
2013-03-16 05:25:30 +08:00
|
|
|
|
{
|
|
|
|
|
H5PL_HANDLE handle = NULL;
|
|
|
|
|
htri_t ret_value = FALSE;
|
|
|
|
|
|
2013-03-19 12:22:34 +08:00
|
|
|
|
FUNC_ENTER_STATIC
|
2013-03-16 05:25:30 +08:00
|
|
|
|
|
|
|
|
|
/* There are different reasons why a library can't be open, e.g. wrong architecture.
|
2013-03-19 12:22:34 +08:00
|
|
|
|
* simply continue if we can't open it.
|
|
|
|
|
*/
|
|
|
|
|
if(NULL == (handle = H5PL_OPEN_DLIB(libname))) {
|
|
|
|
|
H5PL_CLR_ERROR; /* clear error */
|
|
|
|
|
} /* end if */
|
|
|
|
|
else {
|
2013-04-05 04:57:59 +08:00
|
|
|
|
H5PL_get_plugin_info_t get_plugin_info = NULL;
|
2013-04-04 21:29:14 +08:00
|
|
|
|
|
2013-04-05 04:57:59 +08:00
|
|
|
|
/* Return a handle for the function H5PLget_plugin_info in the dynamic library.
|
2013-03-19 12:22:34 +08:00
|
|
|
|
* The plugin library is suppose to define this function.
|
|
|
|
|
*/
|
2013-04-05 04:57:59 +08:00
|
|
|
|
if(NULL == (get_plugin_info = (H5PL_get_plugin_info_t)H5PL_GET_LIB_FUNC(handle, "H5PLget_plugin_info"))) {
|
2013-03-19 12:22:34 +08:00
|
|
|
|
if(H5PL__close(handle) < 0)
|
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CLOSEERROR, FAIL, "can't close dynamic library")
|
|
|
|
|
} /* end if */
|
|
|
|
|
else {
|
2013-04-05 04:57:59 +08:00
|
|
|
|
const H5Z_class2_t *plugin_info;
|
2013-03-19 12:22:34 +08:00
|
|
|
|
|
2013-04-05 04:57:59 +08:00
|
|
|
|
/* Invoke H5PLget_plugin_info to verify this is the right library we are looking for.
|
2013-03-19 12:22:34 +08:00
|
|
|
|
* Move on if it isn't.
|
|
|
|
|
*/
|
2013-04-05 04:57:59 +08:00
|
|
|
|
if(NULL == (plugin_info = (const H5Z_class2_t *)(*get_plugin_info)())) {
|
2013-03-19 12:22:34 +08:00
|
|
|
|
if(H5PL__close(handle) < 0)
|
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CLOSEERROR, FAIL, "can't close dynamic library")
|
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "can't get plugin info")
|
|
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
|
|
/* Successfully found plugin library, check if it's the right one */
|
|
|
|
|
if(plugin_info->id == pl_id) {
|
|
|
|
|
/* Expand the table if it is too small */
|
|
|
|
|
if(H5PL_table_used_g >= H5PL_table_alloc_g) {
|
|
|
|
|
size_t n = MAX(H5Z_MAX_NFILTERS, 2 * H5PL_table_alloc_g);
|
|
|
|
|
H5PL_table_t *table = (H5PL_table_t *)H5MM_realloc(H5PL_table_g, n * sizeof(H5PL_table_t));
|
|
|
|
|
|
|
|
|
|
if(!table)
|
2013-04-04 21:29:14 +08:00
|
|
|
|
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "unable to extend dynamic library table")
|
2013-03-19 12:22:34 +08:00
|
|
|
|
|
|
|
|
|
H5PL_table_g = table;
|
|
|
|
|
H5PL_table_alloc_g = n;
|
|
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
|
|
(H5PL_table_g[H5PL_table_used_g]).handle = handle;
|
|
|
|
|
(H5PL_table_g[H5PL_table_used_g]).pl_type = pl_type;
|
|
|
|
|
(H5PL_table_g[H5PL_table_used_g]).pl_id = plugin_info->id;
|
|
|
|
|
H5PL_table_used_g++;
|
|
|
|
|
|
|
|
|
|
/* Set the plugin info to return */
|
2013-04-05 04:57:59 +08:00
|
|
|
|
*pl_info = (const void *)plugin_info;
|
2013-03-19 12:22:34 +08:00
|
|
|
|
|
|
|
|
|
/* Indicate success */
|
|
|
|
|
ret_value = TRUE;
|
|
|
|
|
} /* end if */
|
|
|
|
|
else
|
|
|
|
|
if(H5PL__close(handle) < 0)
|
|
|
|
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CLOSEERROR, FAIL, "can't close dynamic library")
|
|
|
|
|
} /* end if */
|
|
|
|
|
} /* end else */
|
2013-03-16 05:25:30 +08:00
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
2013-03-19 12:22:34 +08:00
|
|
|
|
} /* end H5PL__open() */
|
2013-03-16 05:25:30 +08:00
|
|
|
|
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2013-03-19 12:22:34 +08:00
|
|
|
|
* Function: H5PL__search_table
|
2013-03-14 03:35:26 +08:00
|
|
|
|
*
|
2013-03-15 04:00:48 +08:00
|
|
|
|
* Purpose: Search in the list of already opened dynamic libraries
|
|
|
|
|
* to see if the one we are looking for is already opened.
|
2013-03-14 03:35:26 +08:00
|
|
|
|
*
|
|
|
|
|
* Return: TRUE on success,
|
|
|
|
|
* FALSE on not found,
|
2013-03-19 12:22:34 +08:00
|
|
|
|
* Negative on failure
|
2013-03-14 03:35:26 +08:00
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* 13 February 2013
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2013-03-19 12:22:34 +08:00
|
|
|
|
static htri_t
|
2013-04-05 04:57:59 +08:00
|
|
|
|
H5PL__search_table(H5PL_type_t plugin_type, int type_id, const void **info)
|
2013-03-14 03:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
htri_t ret_value = FALSE;
|
|
|
|
|
|
2013-03-19 12:22:34 +08:00
|
|
|
|
FUNC_ENTER_STATIC
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
|
|
|
|
/* Search in the table of already opened dynamic libraries */
|
2013-03-19 12:22:34 +08:00
|
|
|
|
if(H5PL_table_used_g > 0) {
|
2013-04-04 21:29:14 +08:00
|
|
|
|
size_t i;
|
|
|
|
|
|
2013-03-19 12:22:34 +08:00
|
|
|
|
for(i = 0; i < H5PL_table_used_g; i++) {
|
2013-03-14 03:35:26 +08:00
|
|
|
|
if((plugin_type == (H5PL_table_g[i]).pl_type) && (type_id == (H5PL_table_g[i]).pl_id)) {
|
2013-04-05 04:57:59 +08:00
|
|
|
|
H5PL_get_plugin_info_t get_plugin_info;
|
|
|
|
|
const H5Z_class2_t *plugin_info;
|
2013-04-04 21:29:14 +08:00
|
|
|
|
|
2013-04-05 04:57:59 +08:00
|
|
|
|
if(NULL == (get_plugin_info = (H5PL_get_plugin_info_t)H5PL_GET_LIB_FUNC((H5PL_table_g[i]).handle, "H5PLget_plugin_info")))
|
|
|
|
|
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get function for H5PLget_plugin_info")
|
2013-03-20 04:07:03 +08:00
|
|
|
|
|
2013-04-05 04:57:59 +08:00
|
|
|
|
if(NULL == (plugin_info = (const H5Z_class2_t *)(*get_plugin_info)()))
|
2013-03-14 03:35:26 +08:00
|
|
|
|
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get plugin info")
|
2013-03-20 04:07:03 +08:00
|
|
|
|
|
2013-04-05 04:57:59 +08:00
|
|
|
|
*info = plugin_info;
|
2013-04-04 21:29:14 +08:00
|
|
|
|
HGOTO_DONE(TRUE)
|
2013-03-19 12:22:34 +08:00
|
|
|
|
} /* end if */
|
|
|
|
|
} /* end for */
|
2013-03-14 03:35:26 +08:00
|
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
2013-03-19 12:22:34 +08:00
|
|
|
|
} /* end H5PL__search_table() */
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2013-03-19 12:22:34 +08:00
|
|
|
|
* Function: H5PL__close
|
2013-03-14 03:35:26 +08:00
|
|
|
|
*
|
2013-03-15 04:00:48 +08:00
|
|
|
|
* Purpose: Closes the handle for dynamic library
|
2013-03-14 03:35:26 +08:00
|
|
|
|
*
|
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* 13 February 2013
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2013-03-19 12:22:34 +08:00
|
|
|
|
static herr_t
|
|
|
|
|
H5PL__close(H5PL_HANDLE handle)
|
2013-03-14 03:35:26 +08:00
|
|
|
|
{
|
2013-03-19 12:22:34 +08:00
|
|
|
|
FUNC_ENTER_STATIC_NOERR
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
2013-03-16 05:25:30 +08:00
|
|
|
|
H5PL_CLOSE_LIB(handle);
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|
2013-03-19 12:22:34 +08:00
|
|
|
|
FUNC_LEAVE_NOAPI(SUCCEED)
|
|
|
|
|
} /* end H5PL__close() */
|
2013-03-14 03:35:26 +08:00
|
|
|
|
|