~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201210021442

« back to all changes in this revision

Viewing changes to services/plugins/dndcp/dndGuest/guestCopyPasteSrc.cc

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2011-03-31 14:20:05 UTC
  • mfrom: (1.4.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110331142005-3n9red91p7ogkweo
Tags: 2011.03.28-387002-0ubuntu1
* Merge latest upstream git tag.  This has the unlocked_ioctl change
  needed to fix dkms build failures (LP: #727342)
* Changes in debian/rules:
  - work around a bug in toolbox/Makefile, where install-exec-hook is
    not happening.  This needs to get fixed the right way.
  - don't install 'vmware-user' which seems to no longer exist
  - move /etc/xdg into open-vm-toolbox (which should be done using .install)
* debian/open-vm-tools.init: add 'modprobe [-r] vmblock'. (LP: #332323)
* debian/rules and debian/open-vm-toolbox.lintian-overrides:
  - Make vmware-user-suid-wrapper suid-root (LP: #332323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************
 
2
 * Copyright (C) 2010 VMware, Inc. All rights reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License as published
 
6
 * by the Free Software Foundation version 2.1 and no later version.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
10
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
 
11
 * License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 
15
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 
16
 *
 
17
 *********************************************************/
 
18
 
 
19
/**
 
20
 * @guestCopyPasteSrc.cc --
 
21
 *
 
22
 * Implementation of common layer GuestCopyPasteSrc object for guest.
 
23
 */
 
24
 
 
25
#include "guestCopyPaste.hh"
 
26
 
 
27
extern "C" {
 
28
   #include "dndClipboard.h"
 
29
   #include "debug.h"
 
30
   #include "file.h"
 
31
   #include "cpNameUtil.h"
 
32
   #include "util.h"
 
33
   #include "str.h"
 
34
}
 
35
 
 
36
 
 
37
/**
 
38
 * Constructor.
 
39
 *
 
40
 * @param[in] mgr guest CP manager
 
41
 */
 
42
 
 
43
GuestCopyPasteSrc::GuestCopyPasteSrc(GuestCopyPasteMgr *mgr)
 
44
 : mMgr(mgr)
 
45
{
 
46
   ASSERT(mMgr);
 
47
   mMgr->GetRpc()->getFilesDoneChanged.connect(
 
48
      sigc::mem_fun(this, &GuestCopyPasteSrc::OnRpcGetFilesDone));
 
49
   CPClipboard_Init(&mClipboard);
 
50
}
 
51
 
 
52
 
 
53
/**
 
54
 * Destructor.
 
55
 */
 
56
 
 
57
GuestCopyPasteSrc::~GuestCopyPasteSrc(void)
 
58
{
 
59
   ASSERT(mMgr);
 
60
   CPClipboard_Destroy(&mClipboard);
 
61
   /* Reset current session id after finished. */
 
62
   mMgr->SetSessionId(0);
 
63
}
 
64
 
 
65
 
 
66
/**
 
67
 * Got valid clipboard data from host. Emit srcRecvClipChanged signal if state
 
68
 * machine is right.
 
69
 *
 
70
 * @param[in] isActive active or passive CopyPaste.
 
71
 * @param[in] clip cross-platform clipboard data.
 
72
 */
 
73
 
 
74
void
 
75
GuestCopyPasteSrc::OnRpcRecvClip(bool isActive,
 
76
                                 const CPClipboard *clip)
 
77
{
 
78
   ASSERT(mMgr);
 
79
   ASSERT(clip);
 
80
 
 
81
   Debug("%s: state is %d\n", __FUNCTION__, mMgr->GetState());
 
82
 
 
83
   CPClipboard_Clear(&mClipboard);
 
84
   CPClipboard_Copy(&mClipboard, clip);
 
85
 
 
86
   mMgr->srcRecvClipChanged.emit(clip);
 
87
}
 
88
 
 
89
 
 
90
/**
 
91
 * UI is asking for files. Send requestFiles cmd to controller.
 
92
 *
 
93
 * @param[in] dir staging directory in local format.
 
94
 *
 
95
 * @return The staging directory if succeed, otherwise empty string.
 
96
 */
 
97
 
 
98
const std::string
 
99
GuestCopyPasteSrc::UIRequestFiles(const std::string &dir)
 
100
{
 
101
   std::string destDir;
 
102
   char cpName[FILE_MAXPATH];
 
103
   int32 cpNameSize;
 
104
 
 
105
   if (mMgr->GetState() != GUEST_CP_READY) {
 
106
      /* Reset DnD for any wrong state. */
 
107
      Debug("%s: Bad state: %d\n", __FUNCTION__, mMgr->GetState());
 
108
      goto error;
 
109
   }
 
110
 
 
111
   /* Setup staging directory. */
 
112
   destDir = SetupDestDir(dir);
 
113
   if (destDir.empty()) {
 
114
      goto error;
 
115
   }
 
116
 
 
117
   /* Convert staging name to CP format. */
 
118
   cpNameSize = CPNameUtil_ConvertToRoot(destDir.c_str(),
 
119
                                         sizeof cpName,
 
120
                                         cpName);
 
121
   if (cpNameSize < 0) {
 
122
      Debug("%s: Error, could not convert to CPName.\n", __FUNCTION__);
 
123
      goto error;
 
124
   }
 
125
 
 
126
   if (!mMgr->GetRpc()->RequestFiles(mMgr->GetSessionId(),
 
127
                                     (const uint8 *)cpName,
 
128
                                     cpNameSize)) {
 
129
      goto error;
 
130
   }
 
131
 
 
132
   mStagingDir = destDir;
 
133
   mMgr->SetState(GUEST_CP_HG_FILE_COPYING);
 
134
   Debug("%s: state changed to GUEST_CP_HG_FILE_COPYING\n", __FUNCTION__);
 
135
 
 
136
   return destDir;
 
137
 
 
138
error:
 
139
   mMgr->ResetCopyPaste();
 
140
   return "";
 
141
}
 
142
 
 
143
 
 
144
/**
 
145
 * The file transfer is finished. Emit getFilesDoneChanged signal and reset
 
146
 * local state.
 
147
 *
 
148
 * @param[in] sessionId active DnD session id
 
149
 * @param[in] success if the file transfer is successful or not
 
150
 * @param[in] stagingDirCP staging dir name in cross-platform format
 
151
 * @param[in] sz the staging dir name size
 
152
 */
 
153
 
 
154
void
 
155
GuestCopyPasteSrc::OnRpcGetFilesDone(uint32 sessionId,
 
156
                                     bool success,
 
157
                                     const uint8 *stagingDirCP,
 
158
                                     uint32 sz)
 
159
{
 
160
   if (!success && !mStagingDir.empty()) {
 
161
      /* Delete all files if host canceled the file transfer. */
 
162
      DnD_DeleteStagingFiles(mStagingDir.c_str(), FALSE);
 
163
      mStagingDir.clear();
 
164
   }
 
165
   /* UI should remove block with this signal. */
 
166
   mMgr->getFilesDoneChanged.emit(success);
 
167
   mMgr->SetState(GUEST_CP_READY);
 
168
   Debug("%s: state changed to READY\n", __FUNCTION__);
 
169
}
 
170
 
 
171
 
 
172
/**
 
173
 * Creates a directory for file transfer. If the destination dir is provided,
 
174
 * we will attempt to copy files to that directory.
 
175
 *
 
176
 * @param[in] destDir the preferred destination directory
 
177
 *
 
178
 * @return the destination directory on success, an empty string on failure.
 
179
 */
 
180
 
 
181
const std::string &
 
182
GuestCopyPasteSrc::SetupDestDir(const std::string &destDir)
 
183
{
 
184
   mStagingDir = "";
 
185
 
 
186
   if (!destDir.empty() && File_Exists(destDir.c_str())) {
 
187
      mStagingDir = destDir;
 
188
      const char *lastSep = Str_Strrchr(mStagingDir.c_str(), DIRSEPC);
 
189
      if (lastSep && lastSep[1] != '\0') {
 
190
         mStagingDir += DIRSEPS;
 
191
      }
 
192
   } else {
 
193
      char *newDir;
 
194
 
 
195
      newDir = DnD_CreateStagingDirectory();
 
196
      if (newDir != NULL) {
 
197
         mStagingDir = newDir;
 
198
 
 
199
         char *lastSep = Str_Strrchr(newDir, DIRSEPC);
 
200
         if (lastSep && lastSep[1] != '\0') {
 
201
            mStagingDir += DIRSEPS;
 
202
         }
 
203
         free(newDir);
 
204
         Debug("%s: destdir: %s", __FUNCTION__, mStagingDir.c_str());
 
205
      } else {
 
206
         Debug("%s: destdir not created", __FUNCTION__);
 
207
      }
 
208
   }
 
209
   return mStagingDir;
 
210
}
 
211
 
 
212