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

[virt-tools-list] [virt-viewer 16/20] Add oVirt URI parsing



---
 src/virt-viewer-session-ovirt.c |   60 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 58 insertions(+), 2 deletions(-)

diff --git a/src/virt-viewer-session-ovirt.c b/src/virt-viewer-session-ovirt.c
index de77306..3fc7c62 100644
--- a/src/virt-viewer-session-ovirt.c
+++ b/src/virt-viewer-session-ovirt.c
@@ -41,6 +41,8 @@ G_DEFINE_TYPE (VirtViewerSessionOvirt, virt_viewer_session_ovirt, VIRT_VIEWER_TY
 struct _VirtViewerSessionOvirtPrivate {
     VirtViewerSession *real_session;
     GtkWindow *main_window;
+    char *rest_uri;
+    char *vm_name;
 };
 
 #define VIRT_VIEWER_SESSION_OVIRT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), VIRT_VIEWER_TYPE_SESSION_OVIRT, VirtViewerSessionOvirtPrivate))
@@ -70,6 +72,12 @@ virt_viewer_session_ovirt_dispose(GObject *obj)
     g_clear_object(&ovirt->priv->real_session);
     g_clear_object(&ovirt->priv->main_window);
 
+    g_free(ovirt->priv->rest_uri);
+    ovirt->priv->rest_uri = NULL;
+
+    g_free(ovirt->priv->vm_name);
+    ovirt->priv->vm_name = NULL;
+
     G_OBJECT_CLASS(virt_viewer_session_ovirt_parent_class)->dispose(obj);
 }
 
@@ -136,16 +144,64 @@ virt_viewer_session_ovirt_open_host(VirtViewerSession *session,
 }
 
 static gboolean
+parse_uri(VirtViewerSession *session, const gchar *uri)
+{
+    VirtViewerSessionOvirt *self = VIRT_VIEWER_SESSION_OVIRT(session);
+    char *pos;
+    char *vm_name;
+    char *tmp_uri;
+
+    /* extract VM name from URI */
+    pos = strrchr(uri, '/');
+    if (pos == NULL)
+        return FALSE;
+
+    pos++;
+    if (*pos == '\0')
+        return FALSE;
+    vm_name = pos;
+
+    /* remove vm_name and trailing / from uri */
+    pos = pos - 1;
+    g_assert(*pos == '/');
+
+    while ((pos != uri) && (*pos == '/'))
+        pos--;
+    if (pos == uri)
+        return FALSE;
+    if (pos - uri + 1 < strlen("ovirt://")) {
+        /* we trimmed too much */
+        return FALSE;
+    }
+
+    tmp_uri = g_strndup(uri, pos - uri + 1);
+    g_assert(g_str_has_prefix(tmp_uri, "ovirt://"));
+    /* FIXME: how to decide between http and https? */
+    self->priv->rest_uri = g_strdup_printf("http://%s/api/";,
+                                           tmp_uri + strlen("ovirt://"));
+    g_free(tmp_uri);
+    self->priv->vm_name = g_strdup(vm_name);
+    g_message("oVirt base URI: %s", self->priv->rest_uri);
+    g_message("oVirt VM name: %s", self->priv->vm_name);
+
+    return TRUE;
+}
+
+static gboolean
 virt_viewer_session_ovirt_open_uri(VirtViewerSession *session,
                                    const gchar *uri)
 {
     /* FIXME: resolve */
     VirtViewerSessionOvirt *self = VIRT_VIEWER_SESSION_OVIRT(session);
+    OvirtProxy *proxy;
 
     g_return_val_if_fail(self != NULL, FALSE);
-    g_return_val_if_fail(self->priv->real_session != NULL, FALSE);
 
-    return virt_viewer_session_open_uri(self->priv->real_session, uri);
+    g_warning("open_uri: %s", uri);
+    if (!parse_uri(session, uri))
+        return FALSE;
+
+    return FALSE;
 }
 
 static gboolean
-- 
1.7.10.2


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