Discussion:
[Libstoragemgmt-devel] [PATCH] C API: Clean up/reduce #includes
Tony Asleson
2014-03-31 23:20:27 UTC
Permalink
A number of header files included things they didn't need or already had.
In addition I changed the signature of the register function in C to pass the
URI as a string instead of a xmlURIPtr. I did this so that a plug-in writer
could choose to use whatever they want to parse their own URI string. It
also removes the requirement for the plug-in developer to have the libxml
development libraries.

I will be adding a library function that will parse the uri character string
into its parts, so that developers don't have to write their own. The
implementation will not expose in the interface.

Signed-off-by: Tony Asleson <***@redhat.com>
---
include/libstoragemgmt/libstoragemgmt_error.h | 1 -
.../libstoragemgmt/libstoragemgmt_plug_interface.h | 8 +++----
include/libstoragemgmt/libstoragemgmt_pool.h | 1 -
include/libstoragemgmt/libstoragemgmt_systems.h | 1 -
plugin/simc_lsmplugin.c | 8 +++----
src/lsm_plugin_ipc.cpp | 27 +++++++++++++++-------
6 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/include/libstoragemgmt/libstoragemgmt_error.h b/include/libstoragemgmt/libstoragemgmt_error.h
index 2a1a83d..2585b8f 100644
--- a/include/libstoragemgmt/libstoragemgmt_error.h
+++ b/include/libstoragemgmt/libstoragemgmt_error.h
@@ -20,7 +20,6 @@
#ifndef LIBSTORAGEMGMTERROR_H
#define LIBSTORAGEMGMTERROR_H

-#include <stdlib.h>
#include "libstoragemgmt_common.h"

#ifdef __cplusplus
diff --git a/include/libstoragemgmt/libstoragemgmt_plug_interface.h b/include/libstoragemgmt/libstoragemgmt_plug_interface.h
index 1909691..28ae176 100644
--- a/include/libstoragemgmt/libstoragemgmt_plug_interface.h
+++ b/include/libstoragemgmt/libstoragemgmt_plug_interface.h
@@ -20,9 +20,6 @@
#ifndef LIBSTORAGEMGMT_PLUG_INTERFACE_H
#define LIBSTORAGEMGMT_PLUG_INTERFACE_H

-#include <libxml/uri.h>
-
-#include "libstoragemgmt_types.h"
#include "libstoragemgmt_common.h"

#include "libstoragemgmt_accessgroups.h"
@@ -37,6 +34,9 @@
#include "libstoragemgmt_systems.h"
#include "libstoragemgmt_volumes.h"

+#include "libstoragemgmt_optionaldata.h"
+#include "libstoragemgmt_disk.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -79,7 +79,7 @@ typedef lsm_plugin *lsm_plugin_ptr;
* @param flags Reserved
* @return LSM_ERR_OK, else error reason
*/
-typedef int (*lsm_plugin_register)( lsm_plugin_ptr c, xmlURIPtr uri,
+typedef int (*lsm_plugin_register)( lsm_plugin_ptr c, const char *uri,
const char *password, uint32_t timeout, lsm_flag flags);

/**
diff --git a/include/libstoragemgmt/libstoragemgmt_pool.h b/include/libstoragemgmt/libstoragemgmt_pool.h
index 41586aa..e631594 100644
--- a/include/libstoragemgmt/libstoragemgmt_pool.h
+++ b/include/libstoragemgmt/libstoragemgmt_pool.h
@@ -21,7 +21,6 @@
#define LIBSTORAGEMGMT_POOL_H

#include "libstoragemgmt_common.h"
-#include "libstoragemgmt_types.h"

#ifdef __cplusplus
extern "C" {
diff --git a/include/libstoragemgmt/libstoragemgmt_systems.h b/include/libstoragemgmt/libstoragemgmt_systems.h
index 6a4389e..1441f19 100644
--- a/include/libstoragemgmt/libstoragemgmt_systems.h
+++ b/include/libstoragemgmt/libstoragemgmt_systems.h
@@ -20,7 +20,6 @@
#define LIBSTORAGEMGMT_SYSTEMS_H

#include "libstoragemgmt_common.h"
-#include "libstoragemgmt_types.h"

#ifdef __cplusplus
extern "C" {
diff --git a/plugin/simc_lsmplugin.c b/plugin/simc_lsmplugin.c
index 3fe2352..194a085 100644
--- a/plugin/simc_lsmplugin.c
+++ b/plugin/simc_lsmplugin.c
@@ -20,16 +20,14 @@

#include <libstoragemgmt/libstoragemgmt_plug_interface.h>
#include <string.h>
-#include <inttypes.h>
#define _XOPEN_SOURCE
#include <unistd.h>
#include <crypt.h>
#include <glib.h>
#include <assert.h>
#include <time.h>
-
-#include "libstoragemgmt/libstoragemgmt_optionaldata.h"
-#include "libstoragemgmt/libstoragemgmt_disk.h"
+#include <stdlib.h>
+#include <stdio.h>

#ifdef __cplusplus
extern "C" {
@@ -2456,7 +2454,7 @@ static void _unload(struct plugin_data *pd) {
}
}

-int load( lsm_plugin_ptr c, xmlURIPtr uri, const char *password,
+int load( lsm_plugin_ptr c, const char *uri, const char *password,
uint32_t timeout, lsm_flag flags)
{
struct plugin_data *pd = (struct plugin_data *)
diff --git a/src/lsm_plugin_ipc.cpp b/src/lsm_plugin_ipc.cpp
index 0d59260..9dd2359 100644
--- a/src/lsm_plugin_ipc.cpp
+++ b/src/lsm_plugin_ipc.cpp
@@ -264,25 +264,36 @@ static int handle_shutdown(lsm_plugin_ptr p, Value &params, Value &response)
static int handle_startup(lsm_plugin_ptr p, Value &params, Value &response)
{
int rc = LSM_ERR_NO_SUPPORT;
- xmlURIPtr uri = NULL;
- std::string uri_string = params["uri"].asString();
+ std::string uri_string;
std::string password;

- if( p ) {
- uri = xmlParseURI(uri_string.c_str());
- if( uri ) {
+ if( p && p->reg ) {
+
+ Value uri_v = params["uri"];
+ Value passwd_v = params["password"];
+ Value tmo_v = params["timeout"];
+
+ if( Value::string_t == uri_v.valueType() &&
+ (Value::string_t == passwd_v.valueType() ||
+ Value::null_t == passwd_v.valueType()) &&
+ Value::numeric_t == tmo_v.valueType()) {
lsm_flag flags = LSM_FLAG_GET_VALUE(params);

+ uri_string = uri_v.asString();
+
if( Value::string_t == params["password"].valueType() ) {
password = params["password"].asString();
}

//Let the plug-in initialize itself.
- rc = p->reg(p, uri, password.c_str(), params["timeout"].asUint32_t(),
+ rc = p->reg(p, uri_string.c_str(), password.c_str(),
+ tmo_v.asUint32_t(),
flags);
- xmlFreeURI(uri);
- uri = NULL;
+ } else {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
}
+ } else {
+ rc = LSM_ERR_NO_SUPPORT;
}
return rc;
}
--
1.8.2.1
Loading...