VirtualBox

Changeset 61724 in vbox


Ignore:
Timestamp:
Jun 15, 2016 3:43:04 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
108094
Message:

Additions/SharedClipboard: fix for ​​bugref:8363: fixed hieroglyphs in result of copying hyperlink from OpenOffice in VM to OpenOffice on host. Fixed code style.

Location:
trunk/src/VBox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp

    r61658 r61724  
    17841784                pvDest = NULL;
    17851785                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]));
    17891814                LogRelFlowFunc(("converted to win unicode %s, cbDest = %d, rc = %Rrc\n", pvDest, cbDest, rc));
    17901815                rc = VINF_SUCCESS;
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxClipboard-win.cpp

    r61589 r61724  
    986986    if (cb > 0)
    987987    {
    988         char* result = NULL;
     988        char* pszResult = NULL;
    989989        size_t cch;
    990990
     
    993993        {
    994994            /* 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);
    996996            if (RT_SUCCESS(rc))
    997997            {
    998                 if (result != NULL && cch != 0)
     998                if (pszResult != NULL && cch != 0)
    999999                {
    1000                     pClient->data.pv = result;
     1000                    pClient->data.pv = pszResult;
    10011001                    pClient->data.cb = cch;
    10021002                    pClient->data.u32Format = u32Format;
     
    10321032EndFragment  = Header length + fragment length - 40(ending length)
    10331033*/
    1034 char strFormatSample[] =
     1034const char pcszFormatSample[] =
    10351035    "Version:1.0\r\n"
    10361036    "StartHTML:000000101\r\n"
     
    10511051* returns RC result code
    10521052*/
    1053 int GetHeaderValue(const char *src, const char *option, size_t *value)
    1054 {
    1055     size_t optionLenght;
     1053int GetHeaderValue(const char *pcszSrc, const char *pcszOption, size_t *pcValue)
     1054{
     1055    size_t cOptionLenght = 0;
    10561056    int rc = VERR_INVALID_PARAMETER;
    10571057
    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);
    10661066        if (RT_SUCCESS(rc))
    10671067        {
    10681068            int32_t tmpValue;
    1069             rc = RTStrToInt32Ex(optionValue + optionLenght, NULL, 10, &tmpValue);
     1069            rc = RTStrToInt32Ex(pcszOptionValue + cOptionLenght, NULL, 10, &tmpValue);
    10701070            if (RT_SUCCESS(rc))
    10711071            {
    1072                 *value = tmpValue;
     1072                *pcValue = tmpValue;
    10731073                rc = VINF_SUCCESS;
    10741074            }
     
    10821082 * returns true if the @source string is in CF_HTML format
    10831083 */
    1084 bool IsWindowsHTML(const char *source)
    1085 {
    1086     return RTStrStr(source, "Version:") != NULL
    1087         && RTStrStr(source, "StartHTML:") != NULL;
     1084bool IsWindowsHTML(const char *pcszSource)
     1085{
     1086    return RTStrStr(pcszSource, "Version:") != NULL
     1087        && RTStrStr(pcszSource, "StartHTML:") != NULL;
    10881088}
    10891089
     
    10971097* Allocated buffer should be destroyed by RTMemFree after usage
    10981098*/
    1099 int ConvertCFHtmlToMime(const char *source, const uint32_t cch, char **output, size_t *pcch)
     1099int ConvertCFHtmlToMime(const char *pcszSource, const uint32_t cch, char **ppszOutput, size_t *pcCh)
    11001100{
    11011101    char* result = NULL;
    11021102
    1103     Assert(source);
     1103    Assert(pcszSource);
    11041104    Assert(cch);
    1105     Assert(output);
    1106     Assert(pcch);
    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);
    11101110    if (!RT_SUCCESS(rc))
    11111111    {
     
    11131113        return VERR_INVALID_PARAMETER;
    11141114    }
    1115     rc = GetHeaderValue(source, "EndFragment:", &endOffset);
     1115    rc = GetHeaderValue(pcszSource, "EndFragment:", &cEndOffset);
    11161116    if (!RT_SUCCESS(rc))
    11171117    {
     
    11191119        return VERR_INVALID_PARAMETER;
    11201120    }
    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);
    11251125        if (result)
    11261126        {
    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);
    11291129            if (RT_SUCCESS(rc))
    11301130            {
    1131                 *output = result;
    1132                 *pcch = substrlen + 1;
     1131                *ppszOutput = result;
     1132                *pcCh = cSubstrlen + 1;
    11331133            }
    11341134            else
     
    11661166* @note: Everything inside of fragment can be UTF8. Windows allows it. Everything in header should be Latin1.
    11671167*/
    1168 int ConvertMimeToCFHTML(const char *source, size_t cb, char **output, size_t *pcch)
    1169 {
    1170     Assert(output);
    1171     Assert(pcch);
    1172     Assert(source);
     1168int ConvertMimeToCFHTML(const char *pcszSource, size_t cb, char **pcszOutput, size_t *pcCh)
     1169{
     1170    Assert(pcszOutput);
     1171    Assert(pcCh);
     1172    Assert(pcszSource);
    11731173    Assert(cb);
    11741174
    1175     size_t fragmentLength = 0;
    1176 
    1177     char* buf = (char*)source;
     1175    size_t cFragmentLength = 0;
     1176
     1177    char* pszBuf = (char*)pcszSource;
    11781178   
    11791179    /* 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);
    11821182    if (!RT_SUCCESS(rc))
    11831183    {
     
    11871187
    11881188    /* 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)
    11941194    {
    11951195        LogRelFlowFunc(("Error: Cannot allocate memory for result buffer. rc = %Rrc.\n"));
     
    11981198
    11991199    /* 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);
    12011201    if (rc == -1)
    12021202    {
     
    12041204        return VERR_CANT_CREATE;
    12051205    }
    1206     Assert(endHtml == rc);
     1206    Assert(cEndHtml == rc);
    12071207
    12081208#ifdef DEBUG
    12091209    {
    12101210        /*Control calculations. check consistency.*/
    1211         const char strStartFragment[] = "<!--StartFragment-->";
    1212         const char strEndFragment[] = "<!--EndFragment-->";
     1211        const char pcszStartFragment[] = "<!--StartFragment-->";
     1212        const char pcszEndFragment[] = "<!--EndFragment-->";
    12131213
    12141214        /* 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);
    12171217
    12181218        /* 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);
    12211221    }
    12221222#endif
    12231223
    1224     *output = result;
    1225     *pcch = rc+1;
     1224    *pcszOutput = pszResult;
     1225    *pcCh = rc+1;
    12261226
    12271227    return VINF_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette