Changeset 62793 in vbox for trunk/src/VBox
- Timestamp:
- Aug 1, 2016 7:30:17 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedClipboard/VBoxClipboard-win.cpp
r62792 r62793 1020 1020 } 1021 1021 1022 /* 1023 @StartHtml - pos before <html> 1024 @EndHtml - whole size of text excluding ending zero char 1025 @StartFragment - pos after <!--StartFragment--> 1026 @EndFragment - pos before <!--EndFragment--> 1027 @note: all values includes CR\LF inserted into text 1028 Calculations: 1029 Header length = format Length + (3*6('digits')) - 2('%s') = format length + 16 (control value - 183) 1030 EndHtml = Header length + fragment length 1031 StartHtml = 105(constant) 1032 StartFragment = 143(constant) 1033 EndFragment = Header length + fragment length - 40(ending length) 1034 */ 1035 const char pcszFormatSample[] = 1036 "Version:1.0\r\n" 1037 "StartHTML:000000101\r\n" 1038 "EndHTML:%09d\r\n" // END HTML = Header length + fragment lengh 1039 "StartFragment:000000137\r\n" 1040 "EndFragment:%09d\r\n" 1041 "<html>\r\n" 1042 "<body>\r\n" 1043 "<!--StartFragment-->%s<!--EndFragment-->\r\n" 1044 "</body>\r\n" 1045 "</html>\r\n"; 1046 1047 /* 1048 * Extracts field value from CF_HTML struct 1049 * @src - source in CF_HTML format 1050 * @option - name of CF_HTML field 1051 * @value - extracted value of CF_HTML field 1052 * returns RC result code 1053 */ 1022 1023 /** 1024 * Extracts field value from CF_HTML struct 1025 * 1026 * @returns VBox status code 1027 * @param pcszSrc source in CF_HTML format 1028 * @param pcszOption Name of CF_HTML field 1029 * @param pcValue Where to return extracted value of CF_HTML field 1030 */ 1054 1031 int GetHeaderValue(const char *pcszSrc, const char *pcszOption, size_t *pcValue) 1055 1032 { … … 1079 1056 } 1080 1057 1081 /* 1058 1059 /** 1082 1060 * Check that the source string contains CF_HTML struct 1083 * returns true if the @source string is in CF_HTML format 1061 * 1062 * @returns @c true if the @source string is in CF_HTML format 1084 1063 */ 1085 1064 bool IsWindowsHTML(const char *pcszSource) … … 1092 1071 /* 1093 1072 * Converts clipboard data from CF_HTML format to mimie clipboard format 1073 * 1094 1074 * Returns allocated buffer that contains html converted to text/html mime type 1095 * return result code 1096 * parameters - output buffer and size of output buffer 1097 * It allocates the buffer needed for storing converted fragment 1098 * Allocated buffer should be destroyed by RTMemFree after usage 1075 * 1076 * @returns VBox status code. 1077 * @param pcszSource The input. 1078 * @param cch The length of the input. 1079 * @param ppszOutput Where to return the result. Free using RTMemFree. 1080 * @param pcch Where to the return length of the result (bytes/chars). 1099 1081 */ 1100 1082 int ConvertCFHtmlToMime(const char *pcszSource, const uint32_t cch, char **ppszOutput, size_t *pcch) 1101 1083 { 1102 char *result = NULL;1084 char *result = NULL; 1103 1085 1104 1086 Assert(pcszSource); … … 1146 1128 } 1147 1129 1148 return VINF_SUCCESS;1130 return VINF_SUCCESS; 1149 1131 } 1150 1132 … … 1152 1134 1153 1135 /* 1154 * Converts source Utf16 mime html clipboard data to Utf8 CF_HTML format 1155 * It allocates 1156 * Calculations: 1157 * Header length = format Length + (2*(10 - 5('%010d'))('digits')) - 2('%s') = format length + 8 1158 * EndHtml = Header length + fragment length 1159 * StartHtml = 105(constant) 1160 * StartFragment = 141(constant) may vary if the header html content will be extended 1161 * EndFragment = Header length + fragment length - 38(ending length) 1162 * @source: source buffer that contains utf-16 string in mime html format 1163 * @cb: size of source buffer in bytes 1164 * @output: allocated output buffer to put converted Utf8 CF_HTML clipboard data. This function allocates memory for this. 1165 * @pcch: size of allocated result buffer in bytes 1166 * @note: output buffer should be free using RTMemFree() 1167 * @note: Everything inside of fragment can be UTF8. Windows allows it. Everything in header should be Latin1. 1168 */ 1169 int ConvertMimeToCFHTML(const char *pcszSource, size_t cb, char **pszOutput, size_t *pcch) 1136 * Converts source Utf16 mime html clipboard data to Utf8 CF_HTML format. 1137 * 1138 * It allocates 1139 * 1140 * Calculations: 1141 * Header length = format Length + (2*(10 - 5('%010d'))('digits')) - 2('%s') = format length + 8 1142 * EndHtml = Header length + fragment length 1143 * StartHtml = 105(constant) 1144 * StartFragment = 141(constant) may vary if the header html content will be extended 1145 * EndFragment = Header length + fragment length - 38(ending length) 1146 * 1147 * @param pcszSource Source buffer that contains utf-16 string in mime html format 1148 * @param cb Size of source buffer in bytes 1149 * @param ppszOutput Where to return the allocated output buffer to put converted UTF-8 1150 * CF_HTML clipboard data. This function allocates memory for this. 1151 * @param pcch Where to return the Size of allocated result buffer in bytes/chars. 1152 * 1153 * @note output buffer should be free using RTMemFree() 1154 * @note Everything inside of fragment can be UTF8. Windows allows it. Everything in header should be Latin1. 1155 */ 1156 int ConvertMimeToCFHTML(const char *pcszSource, size_t cb, char **ppszOutput, size_t *pcch) 1170 1157 { 1171 1158 Assert(pszOutput); … … 1176 1163 size_t cFragmentLength = 0; 1177 1164 1178 char * pszBuf = (char*)pcszSource;1165 char *pszBuf = (char *)pcszSource; 1179 1166 1180 1167 /* construct CF_HTML formatted string */ … … 1187 1174 } 1188 1175 1189 /* caluclate parameters of CF_HTML header */ 1190 size_t cHeaderLength = (sizeof(pcszFormatSample) - 1) + 8; 1176 /* 1177 @StartHtml - pos before <html> 1178 @EndHtml - whole size of text excluding ending zero char 1179 @StartFragment - pos after <!--StartFragment--> 1180 @EndFragment - pos before <!--EndFragment--> 1181 @note: all values includes CR\LF inserted into text 1182 Calculations: 1183 Header length = format Length + (3*6('digits')) - 2('%s') = format length + 16 (control value - 183) 1184 EndHtml = Header length + fragment length 1185 StartHtml = 105(constant) 1186 StartFragment = 143(constant) 1187 EndFragment = Header length + fragment length - 40(ending length) 1188 */ 1189 static const char s_szFormatSample[] = 1190 "Version:1.0\r\n" 1191 "StartHTML:000000101\r\n" 1192 "EndHTML:%09d\r\n" // END HTML = Header length + fragment lengh 1193 "StartFragment:000000137\r\n" 1194 "EndFragment:%09d\r\n" 1195 "<html>\r\n" 1196 "<body>\r\n" 1197 "<!--StartFragment-->%s<!--EndFragment-->\r\n" 1198 "</body>\r\n" 1199 "</html>\r\n"; 1200 1201 /* calculate parameters of CF_HTML header */ 1202 size_t cHeaderLength = (sizeof(s_szFormatSample) - 1) + 8; 1191 1203 size_t cEndHtml = cHeaderLength + cFragmentLength; 1192 1204 size_t cEndFragment = cHeaderLength + cFragmentLength - 38; … … 1199 1211 1200 1212 /* format result CF_HTML string */ 1201 rc = RTStrPrintf(pszResult, cEndHtml + 1, pcszFormatSample, cEndHtml, cEndFragment, pszBuf);1213 rc = RTStrPrintf(pszResult, cEndHtml + 1, s_szFormatSample, cEndHtml, cEndFragment, pszBuf); 1202 1214 if (rc == -1) 1203 1215 { … … 1223 1235 #endif 1224 1236 1225 *p szOutput = pszResult;1237 *ppszOutput = pszResult; 1226 1238 *pcch = rc + 1; 1227 1239
Note:
See TracChangeset
for help on using the changeset viewer.