儲存庫 vbox 的更動 18408
- 時間撮記:
- 2009-3-27 下午03:47:47 (16 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/HostServices/SharedClipboard/x11-clipboard.cpp
r18398 r18408 179 179 static bool g_fHaveX11; 180 180 181 /**182 * Reset the contents of the buffer used to pass clipboard data from VBox to X11.183 * This must be done after every clipboard transfer.184 */185 static void vboxClipboardEmptyGuestBuffer(void)186 {187 if (g_ctx.pClient->data.pv != 0)188 RTMemFree(g_ctx.pClient->data.pv);189 g_ctx.pClient->data.pv = 0;190 g_ctx.pClient->data.cb = 0;191 g_ctx.pClient->data.u32Format = 0;192 }193 181 194 182 /** … … 197 185 * @param pCtx Pointer to the host clipboard structure 198 186 * @param u32Format The format in which the data should be transfered 199 * @thread clipboard X11 event thread 200 * @note called by vboxClipboardConvert* 201 */ 202 static int vboxClipboardReadDataFromVBox (VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Format) 187 * @param ppv On success and if pcb > 0, this will point to a buffer 188 * to be freed with RTMemFree containing the data read. 189 * @param pcb On success, this contains the number of bytes of data 190 * returned 191 */ 192 static int vboxClipboardReadDataFromVBox (VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Format, void **ppv, uint32_t *pcb) 203 193 { 204 194 volatile VBOXCLIPBOARDCLIENTDATA *pClient = pCtx->pClient; … … 248 238 /* I believe this should not happen. Wait until the assertions arrive 249 239 * to prove the contrary. */ 250 vboxClipboardEmptyGuestBuffer(); 240 RTMemFree(pClient->data.pv); 241 g_ctx.pClient->data.pv = 0; 242 g_ctx.pClient->data.cb = 0; 243 g_ctx.pClient->data.u32Format = 0; 251 244 pCtx->guestFormats = 0; 252 245 return rc; … … 255 248 return VERR_TIMEOUT; 256 249 LogFlowFunc(("wait completed. Returning.\n")); 250 *ppv = pClient->data.pv; 251 *pcb = pClient->data.cb; 252 g_ctx.pClient->data.pv = 0; 253 g_ctx.pClient->data.cb = 0; 254 g_ctx.pClient->data.u32Format = 0; 257 255 return VINF_SUCCESS; 258 256 } … … 1056 1054 1057 1055 /** 1058 * Satisfy a request from the hostto convert the clipboard text to Utf16. We return non-zero1056 * Satisfy a request from VBox to convert the clipboard text to Utf16. We return non-zero 1059 1057 * terminated text. 1060 1058 * … … 1071 1069 { 1072 1070 PRTUTF16 pu16SrcText, pu16DestText; 1071 void *pvVBox; 1072 uint32_t cbVBox; 1073 1073 size_t cwSrcLen, cwDestLen; 1074 1074 int rc; 1075 1075 1076 1076 LogFlowFunc (("called\n")); 1077 rc = vboxClipboardReadDataFromVBox(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT );1078 if ((RT_FAILURE(rc)) || ( g_ctx.pClient->data.cb== 0))1077 rc = vboxClipboardReadDataFromVBox(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox); 1078 if ((RT_FAILURE(rc)) || (cbVBox == 0)) 1079 1079 { 1080 1080 /* If vboxClipboardReadDataFromVBox fails then pClient may be invalid */ 1081 1081 LogRelFunc (("vboxClipboardReadDataFromVBox returned %Rrc%s\n", rc, 1082 RT_SUCCESS(rc) ? ", g_ctx.pClient->data.cb== 0" : ""));1083 vboxClipboardEmptyGuestBuffer();1084 return false; 1085 } 1086 pu16SrcText = reinterpret_cast<PRTUTF16>( g_ctx.pClient->data.pv);1087 cwSrcLen = g_ctx.pClient->data.cb/ 2;1082 RT_SUCCESS(rc) ? ", cbVBox == 0" : "")); 1083 RTMemFree(pvVBox); 1084 return false; 1085 } 1086 pu16SrcText = reinterpret_cast<PRTUTF16>(pvVBox); 1087 cwSrcLen = cbVBox / 2; 1088 1088 /* How long will the converted text be? */ 1089 1089 rc = vboxClipboardUtf16GetLinSize(pu16SrcText, cwSrcLen, &cwDestLen); … … 1091 1091 { 1092 1092 LogRel(("vboxClipboardConvertUtf16: clipboard conversion failed. vboxClipboardUtf16GetLinSize returned %Rrc. Abandoning.\n", rc)); 1093 vboxClipboardEmptyGuestBuffer();1093 RTMemFree(pvVBox); 1094 1094 AssertRCReturn(rc, false); 1095 1095 } … … 1097 1097 { 1098 1098 LogFlowFunc(("received empty clipboard data from the guest, returning false.\n")); 1099 vboxClipboardEmptyGuestBuffer();1099 RTMemFree(pvVBox); 1100 1100 return false; 1101 1101 } … … 1104 1104 { 1105 1105 LogRel(("vboxClipboardConvertUtf16: failed to allocate %d bytes\n", cwDestLen * 2)); 1106 vboxClipboardEmptyGuestBuffer();1106 RTMemFree(pvVBox); 1107 1107 return false; 1108 1108 } … … 1113 1113 LogRel(("vboxClipboardConvertUtf16: clipboard conversion failed. vboxClipboardUtf16WinToLin returned %Rrc. Abandoning.\n", rc)); 1114 1114 XtFree(reinterpret_cast<char *>(pu16DestText)); 1115 vboxClipboardEmptyGuestBuffer();1115 RTMemFree(pvVBox); 1116 1116 return false; 1117 1117 } 1118 1118 LogFlowFunc (("converted string is %.*ls. Returning.\n", cwDestLen, pu16DestText)); 1119 vboxClipboardEmptyGuestBuffer();1119 RTMemFree(pvVBox); 1120 1120 *atomTypeReturn = g_ctx.atomUtf16; 1121 1121 *pValReturn = reinterpret_cast<XtPointer>(pu16DestText); … … 1145 1145 PRTUTF16 pu16SrcText, pu16DestText; 1146 1146 char *pu8DestText; 1147 void *pvVBox; 1148 uint32_t cbVBox; 1147 1149 size_t cwSrcLen, cwDestLen, cbDestLen; 1148 1150 int rc; … … 1150 1152 LogFlowFunc (("called\n")); 1151 1153 /* Read the clipboard data from the guest. */ 1152 rc = vboxClipboardReadDataFromVBox(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT );1153 if ((rc != VINF_SUCCESS) || ( g_ctx.pClient->data.cb== 0))1154 rc = vboxClipboardReadDataFromVBox(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox); 1155 if ((rc != VINF_SUCCESS) || (cbVBox == 0)) 1154 1156 { 1155 1157 /* If vboxClipboardReadDataFromVBox fails then pClient may be invalid */ 1156 1158 LogRelFunc (("vboxClipboardReadDataFromVBox returned %Rrc%s\n", rc, 1157 RT_SUCCESS(rc) ? ", g_ctx.pClient->data.cb== 0" : ""));1158 vboxClipboardEmptyGuestBuffer();1159 return false; 1160 } 1161 pu16SrcText = reinterpret_cast<PRTUTF16>( g_ctx.pClient->data.pv);1162 cwSrcLen = g_ctx.pClient->data.cb/ 2;1159 RT_SUCCESS(rc) ? ", cbVBox == 0" : "")); 1160 RTMemFree(pvVBox); 1161 return false; 1162 } 1163 pu16SrcText = reinterpret_cast<PRTUTF16>(pvVBox); 1164 cwSrcLen = cbVBox / 2; 1163 1165 /* How long will the converted text be? */ 1164 1166 rc = vboxClipboardUtf16GetLinSize(pu16SrcText, cwSrcLen, &cwDestLen); … … 1166 1168 { 1167 1169 LogRelFunc (("clipboard conversion failed. vboxClipboardUtf16GetLinSize returned %Rrc. Abandoning.\n", rc)); 1168 vboxClipboardEmptyGuestBuffer();1170 RTMemFree(pvVBox); 1169 1171 AssertRCReturn(rc, false); 1170 1172 } … … 1172 1174 { 1173 1175 LogFlowFunc(("received empty clipboard data from the guest, returning false.\n")); 1174 vboxClipboardEmptyGuestBuffer();1176 RTMemFree(pvVBox); 1175 1177 return false; 1176 1178 } … … 1179 1181 { 1180 1182 LogRelFunc (("failed to allocate %d bytes\n", cwDestLen * 2)); 1181 vboxClipboardEmptyGuestBuffer();1183 RTMemFree(pvVBox); 1182 1184 return false; 1183 1185 } … … 1188 1190 LogRelFunc (("clipboard conversion failed. vboxClipboardUtf16WinToLin() returned %Rrc. Abandoning.\n", rc)); 1189 1191 RTMemFree(reinterpret_cast<void *>(pu16DestText)); 1190 vboxClipboardEmptyGuestBuffer();1192 RTMemFree(pvVBox); 1191 1193 return false; 1192 1194 } … … 1198 1200 LogRelFunc (("failed to allocate %d bytes\n", cwDestLen * 4)); 1199 1201 RTMemFree(reinterpret_cast<void *>(pu16DestText)); 1200 vboxClipboardEmptyGuestBuffer();1202 RTMemFree(pvVBox); 1201 1203 return false; 1202 1204 } … … 1209 1211 LogRelFunc (("clipboard conversion failed. RTUtf16ToUtf8Ex() returned %Rrc. Abandoning.\n", rc)); 1210 1212 XtFree(pu8DestText); 1211 vboxClipboardEmptyGuestBuffer();1213 RTMemFree(pvVBox); 1212 1214 return false; 1213 1215 } 1214 1216 LogFlowFunc (("converted string is %.*s. Returning.\n", cbDestLen, pu8DestText)); 1215 vboxClipboardEmptyGuestBuffer();1217 RTMemFree(pvVBox); 1216 1218 *atomTypeReturn = g_ctx.atomUtf8; 1217 1219 *pValReturn = reinterpret_cast<XtPointer>(pu8DestText); … … 1240 1242 { 1241 1243 PRTUTF16 pu16SrcText, pu16DestText; 1244 void *pvVBox; 1245 uint32_t cbVBox; 1242 1246 char *pu8DestText = 0; 1243 1247 size_t cwSrcLen, cwDestLen, cbDestLen; … … 1247 1251 LogFlowFunc (("called\n")); 1248 1252 /* Read the clipboard data from the guest. */ 1249 rc = vboxClipboardReadDataFromVBox(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT );1250 if ((rc != VINF_SUCCESS) || ( g_ctx.pClient->data.cb== 0))1253 rc = vboxClipboardReadDataFromVBox(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox); 1254 if ((rc != VINF_SUCCESS) || (cbVBox == 0)) 1251 1255 { 1252 1256 /* If vboxClipboardReadDataFromVBox fails then pClient may be invalid */ 1253 1257 LogRelFunc (("vboxClipboardReadDataFromVBox returned %Rrc%s\n", rc, 1254 RT_SUCCESS(rc) ? ", g_ctx.pClient->data.cb== 0" : ""));1255 vboxClipboardEmptyGuestBuffer();1256 return false; 1257 } 1258 pu16SrcText = reinterpret_cast<PRTUTF16>( g_ctx.pClient->data.pv);1259 cwSrcLen = g_ctx.pClient->data.cb/ 2;1258 RT_SUCCESS(rc) ? ", cbVBox == 0" : "")); 1259 RTMemFree(pvVBox); 1260 return false; 1261 } 1262 pu16SrcText = reinterpret_cast<PRTUTF16>(pvVBox); 1263 cwSrcLen = cbVBox / 2; 1260 1264 /* How long will the converted text be? */ 1261 1265 rc = vboxClipboardUtf16GetLinSize(pu16SrcText, cwSrcLen, &cwDestLen); … … 1263 1267 { 1264 1268 LogRelFunc (("clipboard conversion failed. vboxClipboardUtf16GetLinSize returned %Rrc. Abandoning.\n", rc)); 1265 vboxClipboardEmptyGuestBuffer();1269 RTMemFree(pvVBox); 1266 1270 AssertRCReturn(rc, false); 1267 1271 } … … 1269 1273 { 1270 1274 LogFlowFunc(("received empty clipboard data from the guest, returning false.\n")); 1271 vboxClipboardEmptyGuestBuffer();1275 RTMemFree(pvVBox); 1272 1276 return false; 1273 1277 } … … 1276 1280 { 1277 1281 LogRelFunc (("failed to allocate %d bytes\n", cwDestLen * 2)); 1278 vboxClipboardEmptyGuestBuffer();1282 RTMemFree(pvVBox); 1279 1283 return false; 1280 1284 } … … 1285 1289 LogRelFunc (("clipboard conversion failed. vboxClipboardUtf16WinToLin() returned %Rrc. Abandoning.\n", rc)); 1286 1290 RTMemFree(reinterpret_cast<void *>(pu16DestText)); 1287 vboxClipboardEmptyGuestBuffer();1291 RTMemFree(pvVBox); 1288 1292 return false; 1289 1293 } … … 1294 1298 { 1295 1299 LogRelFunc (("clipboard conversion failed. RTUtf16ToUtf8Ex() returned %Rrc. Abandoning.\n", rc)); 1296 vboxClipboardEmptyGuestBuffer();1300 RTMemFree(pvVBox); 1297 1301 return false; 1298 1302 } … … 1325 1329 LogRelFunc (("Xutf8TextListToTextProperty failed. Reason: %s\n", 1326 1330 pcReason)); 1327 vboxClipboardEmptyGuestBuffer();1331 RTMemFree(pvVBox); 1328 1332 return false; 1329 1333 } 1330 1334 LogFlowFunc (("converted string is %s. Returning.\n", property.value)); 1331 vboxClipboardEmptyGuestBuffer();1335 RTMemFree(pvVBox); 1332 1336 *atomTypeReturn = property.encoding; 1333 1337 *pValReturn = reinterpret_cast<XtPointer>(property.value);
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器