[libgovirt] Add common ovirt_utils_strip_api_base_dir()



commit 9bf7ec5e676d4275c271aa91bb20760866c01b37
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Thu Aug 29 20:49:14 2013 +0200

    Add common ovirt_utils_strip_api_base_dir()
    
    This code was duplicated in OvirtVm and OvirtProxy

 govirt/ovirt-proxy.c      |   14 ++------------
 govirt/ovirt-utils.c      |   13 +++++++++++++
 govirt/ovirt-utils.h      |    3 +++
 govirt/ovirt-vm-private.h |    2 --
 govirt/ovirt-vm.c         |   17 +----------------
 5 files changed, 19 insertions(+), 30 deletions(-)
---
diff --git a/govirt/ovirt-proxy.c b/govirt/ovirt-proxy.c
index 0f0f631..232709e 100644
--- a/govirt/ovirt-proxy.c
+++ b/govirt/ovirt-proxy.c
@@ -131,16 +131,6 @@ static void dump_vm(OvirtVm *vm)
 #endif
 
 
-static const char *ovirt_rest_strip_api_base_dir(const char *path)
-{
-    if (g_str_has_prefix(path, OVIRT_API_BASE_DIR)) {
-        g_debug("stripping %s from %s", OVIRT_API_BASE_DIR, path);
-        path += strlen(OVIRT_API_BASE_DIR);
-    }
-
-    return path;
-}
-
 RestXmlNode *ovirt_proxy_get_collection_xml(OvirtProxy *proxy,
                                             const char *href,
                                             GError **error)
@@ -151,7 +141,7 @@ RestXmlNode *ovirt_proxy_get_collection_xml(OvirtProxy *proxy,
     g_return_val_if_fail(OVIRT_IS_PROXY(proxy), NULL);
 
     call = REST_PROXY_CALL(ovirt_rest_call_new(REST_PROXY(proxy)));
-    href = ovirt_rest_strip_api_base_dir(href);
+    href = ovirt_utils_strip_api_base_dir(href);
     rest_proxy_call_set_function(call, href);
     rest_proxy_call_add_header(call, "All-Content", "true");
 
@@ -252,7 +242,7 @@ void ovirt_rest_call_async(OvirtProxy *proxy,
     if (method != NULL) {
         rest_proxy_call_set_method(call, method);
     }
-    href = ovirt_rest_strip_api_base_dir(href);
+    href = ovirt_utils_strip_api_base_dir(href);
     rest_proxy_call_set_function(call, href);
     /* FIXME: to set or not to set ?? */
     rest_proxy_call_add_header(call, "All-Content", "true");
diff --git a/govirt/ovirt-utils.c b/govirt/ovirt-utils.c
index 567357f..f165689 100644
--- a/govirt/ovirt-utils.c
+++ b/govirt/ovirt-utils.c
@@ -22,6 +22,8 @@
 
 #include <config.h>
 
+#include <string.h>
+
 #include <rest/rest-xml-parser.h>
 
 #include "ovirt-utils.h"
@@ -121,3 +123,14 @@ ovirt_utils_boolean_from_string(const char *value)
 
     return (g_strcmp0(value, "true") == 0);
 }
+
+
+G_GNUC_INTERNAL const char *ovirt_utils_strip_api_base_dir(const char *path)
+{
+    if (g_str_has_prefix(path, OVIRT_API_BASE_DIR)) {
+        g_debug("stripping %s from %s", OVIRT_API_BASE_DIR, path);
+        path += strlen(OVIRT_API_BASE_DIR);
+    }
+
+    return path;
+}
diff --git a/govirt/ovirt-utils.h b/govirt/ovirt-utils.h
index 68e440d..5c8d42d 100644
--- a/govirt/ovirt-utils.h
+++ b/govirt/ovirt-utils.h
@@ -27,6 +27,8 @@
 
 G_BEGIN_DECLS
 
+#define OVIRT_API_BASE_DIR "/api/"
+
 RestXmlNode *ovirt_rest_xml_node_from_call(RestProxyCall *call);
 const char *ovirt_rest_xml_node_get_content(RestXmlNode *node, ...);
 
@@ -34,6 +36,7 @@ const char *ovirt_utils_genum_get_nick (GType enum_type, gint value);
 int ovirt_utils_genum_get_value (GType enum_type, const char *nick,
                                  gint default_value);
 gboolean ovirt_utils_boolean_from_string(const char *value);
+const char *ovirt_utils_strip_api_base_dir(const char *path);
 
 G_END_DECLS
 
diff --git a/govirt/ovirt-vm-private.h b/govirt/ovirt-vm-private.h
index d70d486..6c54ac8 100644
--- a/govirt/ovirt-vm-private.h
+++ b/govirt/ovirt-vm-private.h
@@ -28,8 +28,6 @@
 
 G_BEGIN_DECLS
 
-#define OVIRT_API_BASE_DIR "/api/"
-
 typedef enum {
     OVIRT_VM_ACTION_SHUTDOWN,
     OVIRT_VM_ACTION_START,
diff --git a/govirt/ovirt-vm.c b/govirt/ovirt-vm.c
index dcdeb9e..fbcccf6 100644
--- a/govirt/ovirt-vm.c
+++ b/govirt/ovirt-vm.c
@@ -28,7 +28,6 @@
 #include <rest/rest-xml-node.h>
 #include <rest/rest-xml-parser.h>
 #include <stdlib.h>
-#include <string.h>
 
 typedef gboolean (*ActionResponseParser)(RestXmlNode *node, OvirtVm *vm, GError **error);
 static gboolean parse_action_response(RestProxyCall *call, OvirtVm *vm,
@@ -303,20 +302,6 @@ ovirt_vm_stop_finish(OvirtVm *vm, GAsyncResult *result, GError **err)
     return ovirt_vm_action_finish(vm, result, err);
 }
 
-static const char *ovirt_rest_strip_api_base_dir(const char *path)
-{
-    if (g_str_has_prefix(path, OVIRT_API_BASE_DIR)) {
-        path += strlen(OVIRT_API_BASE_DIR);
-    } else {
-        /* action href should always be prefixed by /api/ */
-        /* it would be easier to remove /api/ from the RestProxy base
-         * URL but unfortunately I couldn't get this to work
-         */
-        g_warn_if_reached();
-    }
-
-    return path;
-}
 
 static gboolean
 ovirt_vm_action(OvirtVm *vm, OvirtProxy *proxy, const char *action,
@@ -331,7 +316,7 @@ ovirt_vm_action(OvirtVm *vm, OvirtProxy *proxy, const char *action,
     g_return_val_if_fail((error == NULL) || (*error == NULL), FALSE);
 
     function = ovirt_resource_get_action(OVIRT_RESOURCE(vm), action);
-    function = ovirt_rest_strip_api_base_dir(function);
+    function = ovirt_utils_strip_api_base_dir(function);
     g_return_val_if_fail(function != NULL, FALSE);
 
     call = REST_PROXY_CALL(ovirt_rest_call_new(REST_PROXY(proxy)));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]