Changeset 61724 in vbox
- Timestamp:
- Jun 15, 2016 3:43:04 PM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 108094
- Location:
- trunk/src/VBox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp
r61658 r61724 1784 1784 pvDest = NULL; 1785 1785 cbDest = 0; 1786 rc = clipUTF16ToWinHTML((RTUTF16*)pvSrc, cbSrc, 1787 (char**)&pvDest, &cbDest); 1788 LogRelFlowFunc(("Source unicode %ls, cbSrc = %d\n", pvSrc, cbSrc)); 1786 /* Some applications sends data in utf16, some in itf8, 1787 * without indication it in MIME. 1788 * But in case of utf16, at least an OpenOffice adds Byte Order Mark - 0xfeff 1789 * at start of clipboard data 1790 */ 1791 if( *(PRTUTF16)pvSrc == 0xfeff ) 1792 { 1793 LogRelFlowFunc((" \n")); 1794 rc = clipUTF16ToWinHTML((RTUTF16*)pvSrc, cbSrc, 1795 (char**)&pvDest, &cbDest); 1796 } 1797 else 1798 { 1799 pvDest = RTMemAlloc(cbSrc); 1800 if(pvDest) 1801 { 1802 memcpy(pvDest, pvSrc, cbSrc); 1803 cbDest = cbSrc; 1804 } 1805 else 1806 { 1807 rc = VERR_NO_MEMORY; 1808 break; 1809 } 1810 } 1811 1812 LogRelFlowFunc(("Source unicode %ls, cbSrc = %d\n, Byte Order Mark = %hx", 1813 pvSrc, cbSrc, ((PRTUTF16)pvSrc)[0])); 1789 1814 LogRelFlowFunc(("converted to win unicode %s, cbDest = %d, rc = %Rrc\n", pvDest, cbDest, rc)); 1790 1815 rc = VINF_SUCCESS; -
trunk/src/VBox/HostServices/SharedClipboard/VBoxClipboard-win.cpp
r61589 r61724 986 986 if (cb > 0) 987 987 { 988 char* result = NULL;988 char* pszResult = NULL; 989 989 size_t cch; 990 990 … … 993 993 { 994 994 /* check that this is not already CF_HTML */ 995 int rc = ConvertMimeToCFHTML((const char*)pv, cb, & result, &cch);995 int rc = ConvertMimeToCFHTML((const char*)pv, cb, &pszResult, &cch); 996 996 if (RT_SUCCESS(rc)) 997 997 { 998 if ( result != NULL && cch != 0)998 if (pszResult != NULL && cch != 0) 999 999 { 1000 pClient->data.pv = result;1000 pClient->data.pv = pszResult; 1001 1001 pClient->data.cb = cch; 1002 1002 pClient->data.u32Format = u32Format; … … 1032 1032 EndFragment = Header length + fragment length - 40(ending length) 1033 1033 */ 1034 c har strFormatSample[] =1034 const char pcszFormatSample[] = 1035 1035 "Version:1.0\r\n" 1036 1036 "StartHTML:000000101\r\n" … … 1051 1051 * returns RC result code 1052 1052 */ 1053 int GetHeaderValue(const char * src, const char *option, size_t *value)1054 { 1055 size_t optionLenght;1053 int GetHeaderValue(const char *pcszSrc, const char *pcszOption, size_t *pcValue) 1054 { 1055 size_t cOptionLenght = 0; 1056 1056 int rc = VERR_INVALID_PARAMETER; 1057 1057 1058 Assert( src);1059 Assert( option);1060 1061 char* optionValue = RTStrStr(src, option);1062 if ( optionValue)1063 { 1064 rc = RTStrNLenEx( option, RTSTR_MAX, &optionLenght);1065 Assert( optionLenght);1058 Assert(pcszSrc); 1059 Assert(pcszOption); 1060 1061 char* pcszOptionValue = RTStrStr(pcszSrc, pcszOption); 1062 if (pcszOptionValue) 1063 { 1064 rc = RTStrNLenEx(pcszOption, RTSTR_MAX, &cOptionLenght); 1065 Assert(cOptionLenght); 1066 1066 if (RT_SUCCESS(rc)) 1067 1067 { 1068 1068 int32_t tmpValue; 1069 rc = RTStrToInt32Ex( optionValue + optionLenght, NULL, 10, &tmpValue);1069 rc = RTStrToInt32Ex(pcszOptionValue + cOptionLenght, NULL, 10, &tmpValue); 1070 1070 if (RT_SUCCESS(rc)) 1071 1071 { 1072 * value = tmpValue;1072 *pcValue = tmpValue; 1073 1073 rc = VINF_SUCCESS; 1074 1074 } … … 1082 1082 * returns true if the @source string is in CF_HTML format 1083 1083 */ 1084 bool IsWindowsHTML(const char * source)1085 { 1086 return RTStrStr( source, "Version:") != NULL1087 && RTStrStr( source, "StartHTML:") != NULL;1084 bool IsWindowsHTML(const char *pcszSource) 1085 { 1086 return RTStrStr(pcszSource, "Version:") != NULL 1087 && RTStrStr(pcszSource, "StartHTML:") != NULL; 1088 1088 } 1089 1089 … … 1097 1097 * Allocated buffer should be destroyed by RTMemFree after usage 1098 1098 */ 1099 int ConvertCFHtmlToMime(const char * source, const uint32_t cch, char **output, size_t *pcch)1099 int ConvertCFHtmlToMime(const char *pcszSource, const uint32_t cch, char **ppszOutput, size_t *pcCh) 1100 1100 { 1101 1101 char* result = NULL; 1102 1102 1103 Assert( source);1103 Assert(pcszSource); 1104 1104 Assert(cch); 1105 Assert( output);1106 Assert(pc ch);1107 1108 size_t startOffset, endOffset;1109 int rc = GetHeaderValue( source, "StartFragment:", &startOffset);1105 Assert(ppszOutput); 1106 Assert(pcCh); 1107 1108 size_t cStartOffset, cEndOffset; 1109 int rc = GetHeaderValue(pcszSource, "StartFragment:", &cStartOffset); 1110 1110 if (!RT_SUCCESS(rc)) 1111 1111 { … … 1113 1113 return VERR_INVALID_PARAMETER; 1114 1114 } 1115 rc = GetHeaderValue( source, "EndFragment:", &endOffset);1115 rc = GetHeaderValue(pcszSource, "EndFragment:", &cEndOffset); 1116 1116 if (!RT_SUCCESS(rc)) 1117 1117 { … … 1119 1119 return VERR_INVALID_PARAMETER; 1120 1120 } 1121 if ( startOffset > 0 && endOffset > 0 && endOffset > startOffset)1122 { 1123 size_t substrlen = endOffset - startOffset;1124 result = (char*)RTMemAlloc( substrlen + 1);1121 if (cStartOffset > 0 && cEndOffset > 0 && cEndOffset > cStartOffset) 1122 { 1123 size_t cSubstrlen = cEndOffset - cStartOffset; 1124 result = (char*)RTMemAlloc(cSubstrlen + 1); 1125 1125 if (result) 1126 1126 { 1127 RT_BZERO(result, substrlen + 1);1128 rc = RTStrCopyEx(result, substrlen + 1, source + startOffset, substrlen);1127 RT_BZERO(result, cSubstrlen + 1); 1128 rc = RTStrCopyEx(result, cSubstrlen + 1, pcszSource + cStartOffset, cSubstrlen); 1129 1129 if (RT_SUCCESS(rc)) 1130 1130 { 1131 * output = result;1132 *pc ch = substrlen + 1;1131 *ppszOutput = result; 1132 *pcCh = cSubstrlen + 1; 1133 1133 } 1134 1134 else … … 1166 1166 * @note: Everything inside of fragment can be UTF8. Windows allows it. Everything in header should be Latin1. 1167 1167 */ 1168 int ConvertMimeToCFHTML(const char * source, size_t cb, char **output, size_t *pcch)1169 { 1170 Assert( output);1171 Assert(pc ch);1172 Assert( source);1168 int ConvertMimeToCFHTML(const char *pcszSource, size_t cb, char **pcszOutput, size_t *pcCh) 1169 { 1170 Assert(pcszOutput); 1171 Assert(pcCh); 1172 Assert(pcszSource); 1173 1173 Assert(cb); 1174 1174 1175 size_t fragmentLength = 0;1176 1177 char* buf = (char*)source;1175 size_t cFragmentLength = 0; 1176 1177 char* pszBuf = (char*)pcszSource; 1178 1178 1179 1179 /* construct CF_HTML formatted string */ 1180 char* result = NULL;1181 int rc = RTStrNLenEx( buf, RTSTR_MAX, &fragmentLength);1180 char* pszResult = NULL; 1181 int rc = RTStrNLenEx(pszBuf, RTSTR_MAX, &cFragmentLength); 1182 1182 if (!RT_SUCCESS(rc)) 1183 1183 { … … 1187 1187 1188 1188 /* caluclate parameters of CF_HTML header */ 1189 size_t headerLength = (sizeof(strFormatSample) - 1) + 8;1190 size_t endHtml = headerLength + fragmentLength;1191 size_t endFragment = headerLength + fragmentLength - 38;1192 result = (char*)RTMemAlloc(endHtml + 1);1193 if ( result == NULL)1189 size_t cHeaderLength = (sizeof(pcszFormatSample) - 1) + 8; 1190 size_t cEndHtml = cHeaderLength + cFragmentLength; 1191 size_t cEndFragment = cHeaderLength + cFragmentLength - 38; 1192 pszResult = (char*)RTMemAlloc(cEndHtml + 1); 1193 if (pszResult == NULL) 1194 1194 { 1195 1195 LogRelFlowFunc(("Error: Cannot allocate memory for result buffer. rc = %Rrc.\n")); … … 1198 1198 1199 1199 /* format result CF_HTML string */ 1200 rc = RTStrPrintf( result, endHtml + 1, strFormatSample, endHtml, endFragment, buf);1200 rc = RTStrPrintf(pszResult, cEndHtml + 1, pcszFormatSample, cEndHtml, cEndFragment, pszBuf); 1201 1201 if (rc == -1) 1202 1202 { … … 1204 1204 return VERR_CANT_CREATE; 1205 1205 } 1206 Assert( endHtml == rc);1206 Assert(cEndHtml == rc); 1207 1207 1208 1208 #ifdef DEBUG 1209 1209 { 1210 1210 /*Control calculations. check consistency.*/ 1211 const char strStartFragment[] = "<!--StartFragment-->";1212 const char strEndFragment[] = "<!--EndFragment-->";1211 const char pcszStartFragment[] = "<!--StartFragment-->"; 1212 const char pcszEndFragment[] = "<!--EndFragment-->"; 1213 1213 1214 1214 /* check 'StartFragment:' value */ 1215 const char* realStartFragment = RTStrStr(result, strStartFragment);1216 Assert(( realStartFragment + sizeof(strStartFragment) - 1) - result == 137);//141);1215 const char* pcszRealStartFragment = RTStrStr(pszResult, pcszStartFragment); 1216 Assert((pcszRealStartFragment + sizeof(pcszStartFragment) - 1) - pszResult == 137);//141); 1217 1217 1218 1218 /* check 'EndFragment:' value */ 1219 const char* realEndFragment = RTStrStr(result, strEndFragment);1220 Assert(( realEndFragment - result) == endFragment);1219 const char* pcszRealEndFragment = RTStrStr(pszResult, pcszEndFragment); 1220 Assert((pcszRealEndFragment - pszResult) == cEndFragment); 1221 1221 } 1222 1222 #endif 1223 1223 1224 * output = result;1225 *pc ch = rc+1;1224 *pcszOutput = pszResult; 1225 *pcCh = rc+1; 1226 1226 1227 1227 return VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.