added autogen script to run autotools to generate configure and necessary make inputs
[ovirt-viewer.git] / wui_thread.c
index 060c7a2..c51c43f 100644 (file)
@@ -17,6 +17,8 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+/* For an explanation of the threading model, please main(). */
+
 #include <config.h>
 
 #include <stdio.h>
@@ -245,9 +247,9 @@ wui_thread (gpointer _queue)
 
   /* This checks wui_gthread global which is actually set in the
    * main thread.  Of course, it might not be set if the WUI thread
-   * runs first.  Hence we yield for the main thread to run.
+   * runs first.  Hence we sleep for the main thread to run. (XXX)
    */
-  g_thread_yield ();
+  g_usleep (100000);
   ASSERT_IS_WUI_THREAD ();
 
   g_async_queue_ref (queue);
@@ -518,10 +520,15 @@ write_fn_start_capture (void)
 static char *
 write_fn_finish_capture (void)
 {
-  char *ret = write_fn_buffer;
+  char *ret;
 
   ASSERT_IS_WUI_THREAD ();
 
+  /* Make sure the buffer is NUL-terminated before returning it. */
+  write_fn_buffer = g_realloc (write_fn_buffer, write_fn_len+1);
+  write_fn_buffer[write_fn_len] = '\0';
+  ret = write_fn_buffer;
+
   write_fn_buffer = NULL;
   write_fn_len = -1;
   return ret;
@@ -662,6 +669,10 @@ do_login (void)
   CURL_CHECK_ERROR (curl_easy_setopt, (curl, CURLOPT_FOLLOWLOCATION, (long) 1));
   CURL_CHECK_ERROR (curl_easy_setopt, (curl, CURLOPT_MAXREDIRS, (long) 10));
 
+  // FIXME when ssl is introduced into ovirt-viewer, remove there two lines
+  CURL_CHECK_ERROR(curl_easy_setopt, (curl, CURLOPT_SSL_VERIFYHOST, 0));
+  CURL_CHECK_ERROR(curl_easy_setopt, (curl, CURLOPT_SSL_VERIFYPEER, 0));
+
   /* Try to fetch the URI. */
   r = CURL_CHECK_ERROR (curl_easy_perform, (curl));
   if (r != CURLE_OK) {
@@ -798,8 +809,8 @@ copy_vm (struct vm *vm)
 
   vm2 = g_memdup (vm, sizeof (*vm));
   vm2->description = g_strdup (vm->description);
+  vm2->uuid = g_strdup (vm->uuid);
   vm2->state = vm->state ? g_strdup (vm->state) : NULL;
-  vm2->uuid = vm->uuid ? g_strdup (vm->uuid) : NULL;
   vm2->mac_addr = vm->mac_addr ? g_strdup (vm->mac_addr) : NULL;
   return vm2;
 }
@@ -878,12 +889,15 @@ parse_vmlist_from_xml (const char *xml)
   char *error_str;
   GSList *new_vmlist = NULL;
   struct vm *vm;
+  int len;
 
   /*DEBUG ("XML =\n%s", xml);*/
   ASSERT_IS_WUI_THREAD ();
 
   /* We don't really expect that we won't be able to parse the XML ... */
-  doc = xmlParseDoc ((const xmlChar *) xml);
+  len = strlen (xml);
+  doc = xmlReadMemory (xml, len, NULL, NULL, 0);
+
   if (!doc) {
     DEBUG ("error parsing XML document, xml =\n%s", xml);
     error_str = g_strdup ("error parsing XML document from remote server");
@@ -967,6 +981,7 @@ parse_vm_from_xml (xmlNodePtr node)
   vm.hostid = -1;
   vm.id = -1;
   vm.vnc_port = -1;
+  vm.forward_vnc_port = -1;
   vm.mem_allocated = -1;
   vm.mem_used = -1;
   vm.vcpus_allocated = -1;
@@ -1043,6 +1058,13 @@ parse_vm_from_xml (xmlNodePtr node)
        xmlFree (str);
       }
     }
+    else if (xmlStrcmp (p->name, (const xmlChar *) "forward-vnc-port") == 0) {
+      str = xmlNodeGetContent (p);
+      if (str != NULL) {
+       vm.forward_vnc_port = strtol ((char *) str, NULL, 10);
+       xmlFree (str);
+      }
+    }
     else if (xmlStrcmp (p->name, (const xmlChar *) "vnic-mac-addr") == 0) {
       str = xmlNodeGetContent (p);
       if (str != NULL) {
@@ -1062,6 +1084,10 @@ parse_vm_from_xml (xmlNodePtr node)
     DEBUG ("required field \"description\" missing from <vm> structure");
   else if (vm.vnc_port == -1)
     DEBUG ("required field \"vnc-port\" missing from <vm> structure");
+  else if (vm.forward_vnc_port == -1)
+    DEBUG ("required field \"forward-vnc-port\" missing from <vm> structure");
+  else if (vm.uuid == NULL)
+    DEBUG ("required field \"uuid\" missing from <vm> structure");
   else
     ret = g_memdup (&vm, sizeof vm);