]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ESX: Fix VMX path parsing and URL encoding
authorMatthias Bolte <matthias.bolte@googlemail.com>
Fri, 4 Sep 2009 15:55:55 +0000 (17:55 +0200)
committerDaniel Veillard <veillard@redhat.com>
Fri, 4 Sep 2009 15:55:55 +0000 (17:55 +0200)
* src/esx/esx_driver.c: handle spaces in VMX file path and use a
  virBuffer to encode spaces correctly in the resulting URL
* src/esx/esx_vi.c: include the URL in the error message in case
  of a download error

src/esx/esx_driver.c
src/esx/esx_vi.c

index 0225e9ae273b117933313a9075c37eb261ce5e31..fc225cfbb60585736500f5b4b9cfbd1e4f10ea76 100644 (file)
@@ -2015,6 +2015,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
     const char *vmPathName = NULL;
     char *datastoreName = NULL;
     char *vmxPath = NULL;
+    virBuffer buffer = VIR_BUFFER_INITIALIZER;
     char *url = NULL;
     char *vmx = NULL;
     virDomainDefPtr def = NULL;
@@ -2052,21 +2053,28 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
     }
 
     /* expected format: "[<datastoreName>] <vmxPath>" */
-    if (sscanf(vmPathName, "[%a[^]%]] %as", &datastoreName, &vmxPath) != 2) {
+    if (sscanf(vmPathName, "[%a[^]%]] %a[^\n]", &datastoreName, &vmxPath) != 2) {
         ESX_ERROR(domain->conn, VIR_ERR_OPERATION_INVALID,
                   "'config.files.vmPathName' property '%s' doesn't have "
                   "expected format '[<datastore>] <vmx>'", vmPathName);
         goto failure;
     }
 
-    if (virAsprintf(&url, "%s://%s:%d/folder/%s?dcPath=%s&dsName=%s",
-                    priv->transport, domain->conn->uri->server,
-                    domain->conn->uri->port, vmxPath,
-                    priv->host->datacenter->value, datastoreName) < 0) {
+    virBufferVSprintf(&buffer, "%s://%s:%d/folder/", priv->transport,
+                      domain->conn->uri->server, domain->conn->uri->port);
+    virBufferURIEncodeString(&buffer, vmxPath);
+    virBufferAddLit(&buffer, "?dcPath=");
+    virBufferURIEncodeString(&buffer, priv->host->datacenter->value);
+    virBufferAddLit(&buffer, "&dsName=");
+    virBufferURIEncodeString(&buffer, datastoreName);
+
+    if (virBufferError(&buffer)) {
         virReportOOMError(domain->conn);
         goto failure;
     }
 
+    url = virBufferContentAndReset(&buffer);
+
     if (esxVI_Context_Download(domain->conn, priv->host, url, &vmx) < 0) {
         goto failure;
     }
index 10dd7fda6f8b2ad485bba6743dd8c85ee2f12252..dfcb35217a1216e0e40e001916db674528047dfe 100644 (file)
@@ -442,7 +442,8 @@ esxVI_Context_Download(virConnectPtr conn, esxVI_Context *ctx, const char *url,
 
     if (responseCode != 200) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
-                     "HTTP response code %d", (int)responseCode);
+                     "HTTP response code %d while trying to download '%s'",
+                     (int)responseCode, url);
         goto failure;
     }