Index: /trunk/src/VBox/HostServices/DragAndDrop/dndmanager.cpp
===================================================================
--- /trunk/src/VBox/HostServices/DragAndDrop/dndmanager.cpp	(revision 50307)
+++ /trunk/src/VBox/HostServices/DragAndDrop/dndmanager.cpp	(revision 50308)
@@ -137,12 +137,14 @@
  ******************************************************************************/
 
-DnDHGSendFilePrivate::DnDHGSendFilePrivate(const RTCString &strHostPath, const RTCString &strGuestPath, uint32_t fMode, uint64_t cbSize, PFNDNDPRIVATEPROGRESS pfnProgressCallback, void *pvProgressUser)
-  : m_strHostPath(strHostPath)
-  , m_strGuestPath(strGuestPath)
-  , m_cbFileSize(cbSize)
-  , m_cbFileProcessed(0)
-  , m_hCurFile(0)
-  , m_pfnProgressCallback(pfnProgressCallback)
-  , m_pvProgressUser(pvProgressUser)
+DnDHGSendFilePrivate::DnDHGSendFilePrivate(const RTCString &strHostPath, const RTCString &strGuestPath,
+                                           uint32_t fMode, uint64_t cbSize,
+                                           PFNDNDPRIVATEPROGRESS pfnProgressCallback, void *pvProgressUser)
+    : m_strHostPath(strHostPath)
+    , m_strGuestPath(strGuestPath)
+    , m_cbFileSize(cbSize)
+    , m_cbFileProcessed(0)
+    , m_hCurFile(0)
+    , m_pfnProgressCallback(pfnProgressCallback)
+    , m_pvProgressUser(pvProgressUser)
 {
     m_paSkelParms[0].setString(m_strGuestPath.c_str());
@@ -155,5 +157,5 @@
 }
 
-DnDHGSendFilePrivate::~DnDHGSendFilePrivate()
+DnDHGSendFilePrivate::~DnDHGSendFilePrivate(void)
 {
     if (m_hCurFile)
@@ -161,5 +163,6 @@
 }
 
-int DnDHGSendFilePrivate::currentMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
+int DnDHGSendFilePrivate::currentMessage(uint32_t uMsg, uint32_t cParms,
+                                         VBOXHGCMSVCPARM paParms[])
 {
     if (!m_pNextMsg)
@@ -220,5 +223,7 @@
         if (   RT_SUCCESS(rc)
             && m_pfnProgressCallback)
+        {
             rc = m_pfnProgressCallback(cbRead, m_pvProgressUser);
+        }
 
         if (   fDone
@@ -237,18 +242,23 @@
  ******************************************************************************/
 
-DnDHGSendDataMessagePrivate::DnDHGSendDataMessagePrivate(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[], PFNDNDPRIVATEPROGRESS pfnProgressCallback, void *pvProgressUser)
-  : m_cbSize(paParms[4].u.uint32)
-  , m_cbDone(0)
-  , m_pfnProgressCallback(pfnProgressCallback)
-  , m_pvProgressUser(pvProgressUser)
-{
-    /* Create the initial data message. */
+DnDHGSendDataMessagePrivate::DnDHGSendDataMessagePrivate(uint32_t uMsg, uint32_t cParms,
+                                                         VBOXHGCMSVCPARM paParms[],
+                                                         PFNDNDPRIVATEPROGRESS pfnProgressCallback,
+                                                         void *pvProgressUser)
+    : m_cbSize(paParms[4].u.uint32)
+    , m_cbDone(0)
+    , m_pfnProgressCallback(pfnProgressCallback)
+    , m_pvProgressUser(pvProgressUser)
+{
+    /* Create the initial data message. This might throw
+     * a bad_alloc exception. */
     m_pNextMsg = new HGCM::Message(uMsg, cParms, paParms);
 }
 
-int DnDHGSendDataMessagePrivate::currentMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
-{
-    /* Todo: don't copy the data parts ... just move the data pointer in
-     * the original data ptr. */
+int DnDHGSendDataMessagePrivate::currentMessage(uint32_t uMsg, uint32_t cParms,
+                                                VBOXHGCMSVCPARM paParms[])
+{
+    /** @todo Don't copy the data parts ... just move the data pointer in
+     *        the original data ptr. */
     if (!m_pNextMsg)
         return VERR_NO_DATA;
@@ -261,4 +271,5 @@
     m_pNextMsg = 0;
     rc = pCurMsg->getData(uMsg, cParms, paParms);
+
     /* Depending on the current message, the data pointer is on a
      * different position (HOST_DND_HG_SND_DATA=3;
@@ -266,5 +277,6 @@
     int iPos = uMsg == DragAndDropSvc::HOST_DND_HG_SND_DATA ? 3 : 0;
     m_cbDone += paParms[iPos + 1].u.uint32;
-    /* Info & data send already? */
+
+    /* Info + data send already? */
     if (rc == VERR_BUFFER_OVERFLOW)
     {
@@ -287,10 +299,13 @@
     }
 
-    delete pCurMsg;
-
-    /* Advance progress info */
+    if (pCurMsg)
+        delete pCurMsg;
+
+    /* Advance progress info. */
     if (   RT_SUCCESS(rc)
         && m_pfnProgressCallback)
+    {
         rc = m_pfnProgressCallback(m_cbDone, m_pvProgressUser);
+    }
 
     return rc;
@@ -303,8 +318,11 @@
 /*
  * This class is a meta message class. It doesn't consist of any own message
- * data, but handle the meta info, the data itself as well any files or
+ * data, but handle the meta info, the data itself as well as any files or
  * directories which have to be transfered to the guest.
  */
-DnDHGSendDataMessage::DnDHGSendDataMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[], PFNDNDPROGRESS pfnProgressCallback, void *pvProgressUser)
+DnDHGSendDataMessage::DnDHGSendDataMessage(uint32_t uMsg, uint32_t cParms,
+                                           VBOXHGCMSVCPARM paParms[],
+                                           PFNDNDPROGRESS pfnProgressCallback,
+                                           void *pvProgressUser)
     : m_cbAll(0)
     , m_cbTransfered(0)
@@ -312,60 +330,71 @@
     , m_pvProgressUser(pvProgressUser)
 {
-    RTCString strNewUris;
+    RTCString strNewURIs;
+
     /* Check the format for any uri type. */
-    if (hasFileUrls(static_cast<const char*>(paParms[1].u.pointer.addr), paParms[1].u.pointer.size))
+    if (hasFileUrls(static_cast<const char*>(paParms[1].u.pointer.addr),
+                    paParms[1].u.pointer.size))
     {
         LogFlowFunc(("Old data: '%s'\n", (char*)paParms[3].u.pointer.addr));
-        /* The list is separated by newline (Even if only one file is
-         * listed). */
-        RTCList<RTCString> oldUriList = RTCString(static_cast<const char*>(paParms[3].u.pointer.addr),
-                                                  paParms[3].u.pointer.size).split("\r\n");
-        if (!oldUriList.isEmpty())
-        {
-            RTCList<RTCString> newUriList;
-            for (size_t i = 0; i < oldUriList.size(); ++i)
-            {
-                const RTCString &strUri = oldUriList.at(i);
+
+        /* The list is separated by newline (even if only one file is listed). */
+        RTCList<RTCString> lstURIOrg = RTCString(static_cast<const char*>(paParms[3].u.pointer.addr),
+                                                 paParms[3].u.pointer.size).split("\r\n");
+        if (!lstURIOrg.isEmpty())
+        {
+            RTCList<RTCString> lstURINew;
+            for (size_t i = 0; i < lstURIOrg.size(); ++i)
+            {
+                const RTCString &strURI = lstURIOrg.at(i);
+
                 /* Query the path component of a file URI. If this hasn't a
-                 * file scheme null is returned. */
-                if (char *pszFilePath = RTUriFilePath(strUri.c_str(), URI_FILE_FORMAT_AUTO))
+                 * file scheme NULL is returned. */
+                char *pszFilePath;
+                if (pszFilePath = RTUriFilePath(strURI.c_str(), URI_FILE_FORMAT_AUTO))
                 {
                     /* Add the path to our internal file list (recursive in
                      * the case of a directory). */
-                    if (char *pszFilename = RTPathFilename(pszFilePath))
+                    char *pszFilename;
+                    if (pszFilename = RTPathFilename(pszFilePath))
                     {
-                        char *pszNewUri = RTUriFileCreate(pszFilename);
-                        if (pszNewUri)
+                        char *pszNewURI = RTUriFileCreate(pszFilename);
+                        if (pszNewURI)
                         {
-                            newUriList.append(pszNewUri);
-                            RTStrFree(pszNewUri);
+                            lstURINew.append(pszNewURI);
+                            RTStrFree(pszNewURI);
+
                             buildFileTree(pszFilePath, pszFilename - pszFilePath);
                         }
                     }
+
                     RTStrFree(pszFilePath);
                 }
-                else
-                    newUriList.append(strUri);
-            }
+                else /* Just append the raw data. */
+                    lstURINew.append(strURI);
+            }
+
             /* We have to change the actual DnD data. Remove any host paths and
              * just decode the filename into the new data. The guest tools will
              * add the correct path again, before sending the DnD drop event to
              * some window. */
-            strNewUris = RTCString::join(newUriList, "\r\n") + "\r\n";
-            /* Remark: We don't delete the old pointer here, cause this is done
-             * by the caller. We just use the RTString data, which has the
-             * scope of this ctor. This is enough cause the data is copied in
-             * the DnDHGSendDataMessagePrivate anyway. */
-            paParms[3].u.pointer.addr = (void*)strNewUris.c_str();
-            paParms[3].u.pointer.size = strNewUris.length() + 1;
-            paParms[4].u.uint32       = strNewUris.length() + 1;
-        }
-    }
+            strNewURIs = RTCString::join(lstURINew, "\r\n") + "\r\n";
+
+            /* Note: We don't delete the old pointer here, cause this is done
+             *       by the caller. We just use the RTString data, which has the
+             *       scope of this ctor. This is enough cause the data is copied in
+             *       the DnDHGSendDataMessagePrivate anyway. */
+            paParms[3].u.pointer.addr = (void*)strNewURIs.c_str();
+            paParms[3].u.pointer.size = strNewURIs.length() + 1;
+            paParms[4].u.uint32       = strNewURIs.length() + 1;
+        }
+    }
+
     /* Add the size of the data to the todo list. */
     m_cbAll += paParms[4].u.uint32;
+
     /* The first message is the meta info for the data and the data itself. */
     m_pNextPathMsg = new DnDHGSendDataMessagePrivate(uMsg, cParms, paParms,
                                                      &DnDHGSendDataMessage::progressCallback, this);
-
+#ifdef DEBUG
     LogFlowFunc(("new data '%s'\n", (char*)paParms[3].u.pointer.addr));
     LogFlowFunc(("cbAll: %zu\n", m_cbAll));
@@ -376,7 +405,8 @@
                      m_uriList.at(i).m_strHostPath.c_str(), m_uriList.at(i).m_strGuestPath.c_str(),
                      m_uriList.at(i).m_fMode, m_uriList.at(i).m_cbSize));
-}
-
-DnDHGSendDataMessage::~DnDHGSendDataMessage()
+#endif
+}
+
+DnDHGSendDataMessage::~DnDHGSendDataMessage(void)
 {
     if (m_pNextPathMsg)
@@ -384,5 +414,5 @@
 }
 
-HGCM::Message* DnDHGSendDataMessage::nextHGCMMessage()
+HGCM::Message* DnDHGSendDataMessage::nextHGCMMessage(void)
 {
     if (!m_pNextPathMsg)
@@ -450,7 +480,8 @@
 {
     LogFlowFunc(("format %s\n", pcszFormat));
+
     /** @todo text/uri also an official variant? */
-    return    RTStrNICmp(pcszFormat, "text/uri-list", cbMax)             == 0
-           || RTStrNICmp(pcszFormat, "x-special/gnome-icon-list", cbMax) == 0;
+    return (   RTStrNICmp(pcszFormat, "text/uri-list", cbMax)             == 0
+            || RTStrNICmp(pcszFormat, "x-special/gnome-icon-list", cbMax) == 0);
 }
 
@@ -462,9 +493,11 @@
         return rc;
 
-    /* These are the types we currently support. Symlinks are not directly
+    /*
+     * These are the types we currently support. Symlinks are not directly
      * supported. First the guest could be an OS which doesn't support it and
      * second the symlink could point to a file which is out of the base tree.
      * Both things are hard to support. For now we just copy the target file in
-     * this case. */
+     * this case.
+     */
     if (!(   RTFS_IS_DIRECTORY(objInfo.Attr.fMode)
           || RTFS_IS_FILE(objInfo.Attr.fMode)
@@ -476,6 +509,8 @@
     if (rc == VERR_IS_A_DIRECTORY)
         rc = VINF_SUCCESS;
+
     if (RT_FAILURE(rc))
         return rc;
+
     m_uriList.append(PathEntry(pcszPath, &pcszPath[cbBaseLen], objInfo.Attr.fMode, cbSize));
     m_cbAll += cbSize;
@@ -523,5 +558,6 @@
             case RTDIRENTRYTYPE_FILE:
             {
-                if (char *pszNewFile = RTStrAPrintf2("%s%c%s", pcszPath, RTPATH_DELIMITER, DirEntry.szName))
+                char *pszNewFile;
+                if (pszNewFile = RTStrAPrintf2("%s%c%s", pcszPath, RTPATH_DELIMITER, DirEntry.szName))
                 {
                     /* We need the size and the mode of the file. */
@@ -533,6 +569,9 @@
                     if (RT_FAILURE(rc))
                         break;
-                    m_uriList.append(PathEntry(pszNewFile, &pszNewFile[cbBaseLen], objInfo1.Attr.fMode, cbSize));
+
+                    m_uriList.append(PathEntry(pszNewFile, &pszNewFile[cbBaseLen],
+                                               objInfo1.Attr.fMode, cbSize));
                     m_cbAll += cbSize;
+
                     RTStrFree(pszNewFile);
                 }
@@ -541,7 +580,10 @@
                 break;
             }
-            default: break;
-        }
-    }
+
+            default:
+                break;
+        }
+    }
+
     RTDirClose(hDir);
 
@@ -554,4 +596,5 @@
 
     DnDHGSendDataMessage *pSelf = static_cast<DnDHGSendDataMessage *>(pvUser);
+    AssertPtr(pSelf);
 
     /* How many bytes are transfered already. */
@@ -562,6 +605,9 @@
     if (   pSelf->m_pfnProgressCallback
         && pSelf->m_cbAll)
+    {
         rc = pSelf->m_pfnProgressCallback((uint64_t)pSelf->m_cbTransfered * 100 / pSelf->m_cbAll,
-                                          DragAndDropSvc::DND_PROGRESS_RUNNING, VINF_SUCCESS /* rc */, pSelf->m_pvProgressUser);
+                                          DragAndDropSvc::DND_PROGRESS_RUNNING,
+                                          VINF_SUCCESS /* rc */, pSelf->m_pvProgressUser);
+    }
 
     return rc;
@@ -603,4 +649,5 @@
                 break;
             }
+
             case DragAndDropSvc::HOST_DND_HG_EVT_MOVE:
             {
@@ -616,5 +663,7 @@
                     || paParms[5].type != VBOX_HGCM_SVC_PARM_PTR   /* data */
                     || paParms[6].type != VBOX_HGCM_SVC_PARM_32BIT /* size */)
+                {
                     rc = VERR_INVALID_PARAMETER;
+                }
                 else
                 {
@@ -625,4 +674,5 @@
                 break;
             }
+
             case DragAndDropSvc::HOST_DND_HG_EVT_LEAVE:
             {
@@ -637,7 +687,9 @@
                     m_dndMessageQueue.append(pMessage);
                 }
+
                 m_fOpInProcess = false;
                 break;
             }
+
             case DragAndDropSvc::HOST_DND_HG_EVT_DROPPED:
             {
@@ -653,5 +705,7 @@
                     || paParms[5].type != VBOX_HGCM_SVC_PARM_PTR   /* data */
                     || paParms[6].type != VBOX_HGCM_SVC_PARM_32BIT /* size */)
+                {
                     rc = VERR_INVALID_PARAMETER;
+                }
                 else
                 {
@@ -661,4 +715,5 @@
                 break;
             }
+
             case DragAndDropSvc::HOST_DND_HG_SND_DATA:
             {
@@ -672,13 +727,18 @@
                     || paParms[3].type != VBOX_HGCM_SVC_PARM_PTR   /* data */
                     || paParms[4].type != VBOX_HGCM_SVC_PARM_32BIT /* data size */)
+                {
                     rc = VERR_INVALID_PARAMETER;
+                }
                 else
                 {
-                    DnDHGSendDataMessage *pMessage = new DnDHGSendDataMessage(uMsg, cParms, paParms, m_pfnProgressCallback, m_pvProgressUser);
+                    DnDHGSendDataMessage *pMessage =
+                        new DnDHGSendDataMessage(uMsg, cParms, paParms,
+                                                 m_pfnProgressCallback, m_pvProgressUser);
                     m_dndMessageQueue.append(pMessage);
                 }
                 break;
             }
-    #ifdef VBOX_WITH_DRAG_AND_DROP_GH
+
+#ifdef VBOX_WITH_DRAG_AND_DROP_GH
             case DragAndDropSvc::HOST_DND_GH_REQ_PENDING:
             {
@@ -688,5 +748,7 @@
                 if (   cParms != 1
                     || paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* screen id */)
+                {
                     rc = VERR_INVALID_PARAMETER;
+                }
                 else
                 {
@@ -696,4 +758,5 @@
                 break;
             }
+
             case DragAndDropSvc::HOST_DND_GH_EVT_DROPPED:
             {
@@ -705,5 +768,7 @@
                     || paParms[1].type != VBOX_HGCM_SVC_PARM_32BIT /* format size */
                     || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* action */)
+                {
                     rc = VERR_INVALID_PARAMETER;
+                }
                 else
                 {
@@ -721,5 +786,6 @@
                 break;
             }
-    #endif
+#endif /* VBOX_WITH_DRAG_AND_DROP_GH */
+
             default:
                 rc = VERR_NOT_IMPLEMENTED;
@@ -735,15 +801,13 @@
 }
 
-HGCM::Message* DnDManager::nextHGCMMessage()
+HGCM::Message* DnDManager::nextHGCMMessage(void)
 {
     if (m_pCurMsg)
         return m_pCurMsg->nextHGCMMessage();
-    else
-    {
-        if (m_dndMessageQueue.isEmpty())
-            return 0;
-
-        return m_dndMessageQueue.first()->nextHGCMMessage();
-    }
+
+    if (m_dndMessageQueue.isEmpty())
+        return NULL;
+
+    return m_dndMessageQueue.first()->nextHGCMMessage();
 }
 
@@ -832,5 +896,5 @@
 }
 
-void DnDManager::clear()
+void DnDManager::clear(void)
 {
     if (m_pCurMsg)
@@ -839,4 +903,5 @@
         m_pCurMsg = 0;
     }
+
     while (!m_dndMessageQueue.isEmpty())
     {
Index: /trunk/src/VBox/HostServices/DragAndDrop/dndmanager.h
===================================================================
--- /trunk/src/VBox/HostServices/DragAndDrop/dndmanager.h	(revision 50307)
+++ /trunk/src/VBox/HostServices/DragAndDrop/dndmanager.h	(revision 50308)
@@ -105,21 +105,23 @@
 {
 public:
+
     DnDHGSendDataMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[], PFNDNDPROGRESS pfnProgressCallback, void *pvProgressUser);
-    ~DnDHGSendDataMessage();
-
-    HGCM::Message* nextHGCMMessage();
+    virtual ~DnDHGSendDataMessage(void);
+
+    HGCM::Message* nextHGCMMessage(void);
     int currentMessageInfo(uint32_t *puMsg, uint32_t *pcParms);
     int currentMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
 
-    bool isMessageWaiting() const { return !!m_pNextPathMsg; }
+    bool isMessageWaiting(void) const { return !!m_pNextPathMsg; }
 
 protected:
+
     struct PathEntry
     {
         PathEntry(const RTCString &strHostPath, const RTCString &strGuestPath, uint32_t fMode, uint64_t cbSize)
-          : m_strHostPath(strHostPath)
-          , m_strGuestPath(strGuestPath)
-          , m_fMode(fMode)
-          , m_cbSize(cbSize) {}
+            : m_strHostPath(strHostPath)
+            , m_strGuestPath(strGuestPath)
+            , m_fMode(fMode)
+            , m_cbSize(cbSize) {}
         RTCString m_strHostPath;
         RTCString m_strGuestPath;
@@ -135,6 +137,7 @@
     DnDMessage         *m_pNextPathMsg;
 
-    /* Progress stuff */
+    /* Total size (in bytes). */
     size_t              m_cbAll;
+    /* Transferred size (in bytes). */
     size_t              m_cbTransfered;
     PFNDNDPROGRESS      m_pfnProgressCallback;
Index: /trunk/src/VBox/HostServices/DragAndDrop/service.cpp
===================================================================
--- /trunk/src/VBox/HostServices/DragAndDrop/service.cpp	(revision 50307)
+++ /trunk/src/VBox/HostServices/DragAndDrop/service.cpp	(revision 50308)
@@ -208,5 +208,5 @@
                 && modeGet() != VBOX_DRAG_AND_DROP_MODE_HOST_TO_GUEST)
             {
-                LogFlowFunc(("=> ignoring!\n"));
+                LogFlowFunc(("Wrong DnD mode, ignoring request\n"));
                 break;
             }
@@ -232,5 +232,5 @@
                 && modeGet() != VBOX_DRAG_AND_DROP_MODE_HOST_TO_GUEST)
             {
-                LogFlowFunc(("=> ignoring!\n"));
+                LogFlowFunc(("Wrong DnD mode, ignoring request\n"));
                 break;
             }
@@ -262,5 +262,5 @@
                 && modeGet() != VBOX_DRAG_AND_DROP_MODE_GUEST_TO_HOST)
             {
-                LogFlowFunc(("=> ignoring!\n"));
+                LogFlowFunc(("Wrong DnD mode, ignoring request\n"));
                 break;
             }
@@ -290,5 +290,5 @@
                 && modeGet() != VBOX_DRAG_AND_DROP_MODE_GUEST_TO_HOST)
             {
-                LogFlowFunc(("=> ignoring\n"));
+                LogFlowFunc(("Wrong DnD mode, ignoring request\n"));
                 break;
             }
@@ -315,5 +315,5 @@
                 && modeGet() != VBOX_DRAG_AND_DROP_MODE_GUEST_TO_HOST)
             {
-                LogFlowFunc(("=> ignoring!\n"));
+                LogFlowFunc(("Wrong DnD mode, ignoring request\n"));
                 break;
             }
