Changeset 29901 in vbox
- Timestamp:
- May 31, 2010 12:53:25 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/manifest.h
r28800 r29901 52 52 53 53 /** 54 * Manifest progress callback. 55 * 56 * @returns IPRT status code. 57 * 58 * @param uPercent The progress completion percentage. 59 * @param pvUser The user defined parameter. 60 */ 61 typedef DECLCALLBACK(int) FNRTMANIFESTPROGRESS(unsigned uPercent, void *pvUser); 62 /** Pointer to a manifest progress callback. */ 63 typedef FNRTMANIFESTPROGRESS *PFNRTMANIFESTPROGRESS; 64 65 /** 54 66 * Verify the given SHA1 digests against the entries in the manifest file. 55 67 * … … 82 94 * VERR_MANIFEST_DIGEST_MISMATCH error case 83 95 * (optional). 96 * @param pfnProgressCallback optional callback for the progress indication 97 * @param pvUser user defined pointer for the callback 84 98 */ 85 RTR3DECL(int) RTManifestVerifyFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, size_t *piFailed );99 RTR3DECL(int) RTManifestVerifyFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, size_t *piFailed, PFNRTMANIFESTPROGRESS pfnProgressCallback, void *pvUser); 86 100 87 101 /** … … 95 109 * @param papszFiles Array of files to create SHA1 sums for. 96 110 * @param cFiles Number of entries in papszFiles. 111 * @param pfnProgressCallback optional callback for the progress indication 112 * @param pvUser user defined pointer for the callback 97 113 */ 98 RTR3DECL(int) RTManifestWriteFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles );114 RTR3DECL(int) RTManifestWriteFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, PFNRTMANIFESTPROGRESS pfnProgressCallback, void *pvUser); 99 115 100 116 /** @} */ -
trunk/include/iprt/sha.h
r29821 r29901 35 35 * @{ 36 36 */ 37 38 /** 39 * SHA progress callback. 40 * 41 * @returns IPRT status code. 42 * 43 * @param uPercent The progress completion percentage. 44 * @param pvUser The user defined parameter. 45 */ 46 typedef DECLCALLBACK(int) FNRTSHAPROGRESS(unsigned uPercent, void *pvUser); 47 /** Pointer to a SHA progress callback. */ 48 typedef FNRTSHAPROGRESS *PFNRTSHAPROGRESS; 37 49 38 50 /** The size of a SHA-1 hash. */ … … 90 102 91 103 /** 92 * Converts a SHA- 512hash to a digest string.104 * Converts a SHA-1 hash to a digest string. 93 105 * 94 106 * @returns IPRT status code. … … 118 130 * @returns iprt status code. 119 131 * 120 * @param pszFile Filename to create a SHA1 digest for. 121 * @param ppszDigest On success the SHA1 digest. 122 */ 123 RTR3DECL(int) RTSha1Digest(const char *pszFile, char **ppszDigest); 132 * @param pszFile Filename to create a SHA1 digest for. 133 * @param ppszDigest On success the SHA1 digest. 134 * @param pfnProgressCallback optional callback for the progress indication 135 * @param pvUser user defined pointer for the callback 136 */ 137 RTR3DECL(int) RTSha1Digest(const char *pszFile, char **ppszDigest, PFNRTSHAPROGRESS pfnProgressCallback, void *pvUser); 124 138 125 139 -
trunk/src/VBox/Main/ApplianceImplExport.cpp
r29875 r29901 1608 1608 ++it1, ++i) 1609 1609 ppManifestFiles[i] = (*it1).c_str(); 1610 int vrc = RTManifestWriteFiles(strMfFile.c_str(), ppManifestFiles, diskList.size()+1 );1610 int vrc = RTManifestWriteFiles(strMfFile.c_str(), ppManifestFiles, diskList.size()+1, NULL, NULL); 1611 1611 RTMemFree(ppManifestFiles); 1612 1612 if (RT_FAILURE(vrc)) -
trunk/src/VBox/Main/ApplianceImplImport.cpp
r29894 r29901 671 671 /* Create the SHA1 sum of the OVF file for later validation */ 672 672 char *pszDigest; 673 int vrc = RTSha1Digest(locInfo.strPath.c_str(), &pszDigest );673 int vrc = RTSha1Digest(locInfo.strPath.c_str(), &pszDigest, NULL, NULL); 674 674 if (RT_FAILURE(vrc)) 675 675 throw setError(VBOX_E_FILE_ERROR, … … 1065 1065 { 1066 1066 char* pszDigest; 1067 vrc = RTSha1Digest((*it1).c_str(), &pszDigest );1067 vrc = RTSha1Digest((*it1).c_str(), &pszDigest, NULL, NULL); 1068 1068 pTestList[i].pszTestFile = (char*)(*it1).c_str(); 1069 1069 pTestList[i].pszTestDigest = pszDigest; -
trunk/src/VBox/Runtime/common/checksum/RTSha1Digest.cpp
r29820 r29901 33 33 34 34 #include <iprt/assert.h> 35 #include <iprt/err.h> 36 #include <iprt/stream.h> 35 #include <iprt/mem.h> 37 36 #include <iprt/string.h> 37 #include <iprt/file.h> 38 38 39 39 #include <openssl/sha.h> 40 40 41 42 43 RTR3DECL(int) RTSha1Digest(const char *pszFile, char **ppszDigest) 41 RTR3DECL(int) RTSha1Digest(const char *pszFile, char **ppszDigest, PFNRTSHAPROGRESS pfnProgressCallback, void *pvUser) 44 42 { 45 43 /* Validate input */ 46 44 AssertPtrReturn(pszFile, VERR_INVALID_POINTER); 47 45 AssertPtrReturn(ppszDigest, VERR_INVALID_POINTER); 46 AssertPtrNullReturn(pfnProgressCallback, VERR_INVALID_PARAMETER); 48 47 49 48 *ppszDigest = NULL; 49 int rc = VINF_SUCCESS; 50 50 51 51 /* Initialize OpenSSL */ … … 54 54 return VERR_INTERNAL_ERROR; 55 55 56 /** @todo r=bird: Using a stream here doesn't really serve much purpose as 57 * few stream implementations uses a buffer much larger than 4KB. (The 58 * only I'm aware of is libc on OS/2, which uses 8KB.) */ 56 /* Fetch the file size. Only needed if there is a progress callback. */ 57 float multi = 0; 58 if (pfnProgressCallback) 59 { 60 uint64_t cbFile; 61 rc = RTFileQuerySize(pszFile, &cbFile); 62 if (RT_FAILURE(rc)) 63 return rc; 64 multi = 100.0 / cbFile; 65 } 59 66 60 67 /* Open the file to calculate a SHA1 sum of */ 61 PRTSTREAM pStream;62 int rc = RTStrmOpen(pszFile, "rb", &pStream);68 RTFILE file; 69 rc = RTFileOpen(&file, pszFile, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE); 63 70 if (RT_FAILURE(rc)) 64 71 return rc; 65 72 66 73 /* Read that file in blocks */ 67 void *pvBuf[4096]; 74 void *pvBuf = RTMemTmpAlloc(_1M); 75 if (!pvBuf) 76 { 77 RTFileClose(file); 78 rc = VERR_NO_MEMORY; 79 } 68 80 size_t cbRead; 69 do 81 size_t cbReadFull = 0; 82 for (;;) 70 83 { 71 84 cbRead = 0; 72 rc = RT StrmReadEx(pStream, pvBuf, 4096, &cbRead);73 if (RT_FAILURE(rc) )85 rc = RTFileRead(file, pvBuf, _1M, &cbRead); 86 if (RT_FAILURE(rc) || !cbRead) 74 87 break; 75 88 if(!SHA1_Update(&ctx, pvBuf, cbRead)) … … 78 91 break; 79 92 } 80 } while (cbRead > 0); 81 RTStrmClose(pStream); 93 cbReadFull += cbRead; 94 /* Call progress callback if some is defined */ 95 if ( pfnProgressCallback 96 && RT_FAILURE(pfnProgressCallback((unsigned)(cbReadFull * multi), pvUser))) 97 { 98 /* Cancel support */ 99 rc = VERR_CANCELLED; 100 break; 101 } 102 } 103 RTMemTmpFree(pvBuf); 104 RTFileClose(file); 82 105 83 106 if (RT_FAILURE(rc)) … … 85 108 86 109 /* Finally calculate & format the SHA1 sum */ 87 unsigned char auchDig[ 20];110 unsigned char auchDig[RTSHA1_HASH_SIZE]; 88 111 if (!SHA1_Final(auchDig, &ctx)) 89 112 return VERR_INTERNAL_ERROR; -
trunk/src/VBox/Runtime/common/checksum/manifest.cpp
r28800 r29901 55 55 typedef RTMANIFESTFILEENTRY* PRTMANIFESTFILEENTRY; 56 56 57 57 /** 58 * Internal structure used for the progress callback 59 */ 60 typedef struct RTMANIFESTCALLBACKDATA 61 { 62 PFNRTMANIFESTPROGRESS pfnProgressCallback; 63 void *pvUser; 64 uint32_t cMaxFiles; 65 uint32_t cCurrentFile; 66 } RTMANIFESTCALLBACKDATA; 67 typedef RTMANIFESTCALLBACKDATA* PRTMANIFESTCALLBACKDATA; 68 69 int rtSHAProgressCallback(unsigned uPercent, void *pvUser) 70 { 71 PRTMANIFESTCALLBACKDATA pData = (PRTMANIFESTCALLBACKDATA)pvUser; 72 return pData->pfnProgressCallback((unsigned)((uPercent + (float)pData->cCurrentFile * 100.0) / (float)pData->cMaxFiles), pData->pvUser); 73 } 58 74 59 75 RTR3DECL(int) RTManifestVerify(const char *pszManifestFile, PRTMANIFESTTEST paTests, size_t cTests, size_t *piFailed) … … 211 227 212 228 213 RTR3DECL(int) RTManifestVerifyFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, size_t *piFailed )229 RTR3DECL(int) RTManifestVerifyFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, size_t *piFailed, PFNRTMANIFESTPROGRESS pfnProgressCallback, void *pvUser) 214 230 { 215 231 /* Validate input */ 216 232 AssertPtrReturn(pszManifestFile, VERR_INVALID_POINTER); 217 233 AssertPtrReturn(papszFiles, VERR_INVALID_POINTER); 234 AssertPtrNullReturn(pfnProgressCallback, VERR_INVALID_PARAMETER); 235 236 int rc = VINF_SUCCESS; 218 237 219 238 /* Create our compare list */ … … 222 241 return VERR_NO_MEMORY; 223 242 243 RTMANIFESTCALLBACKDATA callback = { pfnProgressCallback, pvUser, cFiles, 0 }; 224 244 /* Fill our compare list */ 225 int rc = VINF_SUCCESS;226 245 for (size_t i = 0; i < cFiles; ++i) 227 246 { 228 247 char *pszDigest; 229 rc = RTSha1Digest(papszFiles[i], &pszDigest); 248 if (pfnProgressCallback) 249 { 250 callback.cCurrentFile = i; 251 rc = RTSha1Digest(papszFiles[i], &pszDigest, rtSHAProgressCallback, &callback); 252 } 253 else 254 rc = RTSha1Digest(papszFiles[i], &pszDigest, NULL, NULL); 230 255 if (RT_FAILURE(rc)) 231 256 break; … … 250 275 251 276 252 RTR3DECL(int) RTManifestWriteFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles )277 RTR3DECL(int) RTManifestWriteFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, PFNRTMANIFESTPROGRESS pfnProgressCallback, void *pvUser) 253 278 { 254 279 /* Validate input */ 255 280 AssertPtrReturn(pszManifestFile, VERR_INVALID_POINTER); 256 281 AssertPtrReturn(papszFiles, VERR_INVALID_POINTER); 282 AssertPtrNullReturn(pfnProgressCallback, VERR_INVALID_PARAMETER); 257 283 258 284 /* Open a file to stream in */ … … 262 288 return rc; 263 289 290 RTMANIFESTCALLBACKDATA callback = { pfnProgressCallback, pvUser, cFiles, 0 }; 264 291 for (size_t i = 0; i < cFiles; ++i) 265 292 { 266 293 /* Calculate the SHA1 digest of every file */ 267 294 char *pszDigest; 268 rc = RTSha1Digest(papszFiles[i], &pszDigest); 295 if (pfnProgressCallback) 296 { 297 callback.cCurrentFile = i; 298 rc = RTSha1Digest(papszFiles[i], &pszDigest, rtSHAProgressCallback, &callback); 299 } 300 else 301 rc = RTSha1Digest(papszFiles[i], &pszDigest, NULL, NULL); 269 302 if (RT_FAILURE(rc)) 270 303 break;
Note:
See TracChangeset
for help on using the changeset viewer.