// --------------------------------------------------------------------------- // CCache::TransCacheEntryFromName // create transport entry from name //--------------------------------------------------------------------------- HRESULT CCache::TransCacheEntryFromName(IAssemblyName *pName, DWORD dwFlags, CTransCache **ppTransCache) { HRESULT hr; DWORD cb, dwCacheId = 0; TRANSCACHEINFO *pTCInfo = 0; CTransCache *pTransCache = NULL; // Get the correct cache index. if(FAILED(hr = ResolveCacheIndex(pName, dwFlags, &dwCacheId))) goto exit; // Construct new CTransCache object. if(FAILED(hr = CreateTransCacheEntry(dwCacheId, &pTransCache))) goto exit; // Cast base info ptr to TRANSCACHEINFO ptr pTCInfo = (TRANSCACHEINFO*) pTransCache->_pInfo; // Downcased text name from target if (FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_NAME, (LPBYTE*) &pTCInfo->pwzName, &(cb = 0))) // Version || FAILED(hr = pName->GetVersion(&pTCInfo->dwVerHigh, &pTCInfo->dwVerLow)) // Culture || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_CULTURE, (LPBYTE*) &pTCInfo->pwzCulture, &cb)) || (pTCInfo->pwzCulture && !_wcslwr(pTCInfo->pwzCulture)) // PublicKeyToken || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_PUBLIC_KEY_TOKEN, &pTCInfo->blobPKT.pBlobData, &pTCInfo->blobPKT.cbSize)) // Custom || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_CUSTOM, &pTCInfo->blobCustom.pBlobData, &pTCInfo->blobCustom.cbSize)) // MVID || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_MVID, &pTCInfo->blobMVID.pBlobData, &pTCInfo->blobMVID.cbSize)) // Codebase url if any from target || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_CODEBASE_URL, (LPBYTE*) &pTCInfo->pwzCodebaseURL, &(cb = 0))) || FAILED(hr = pName->GetProperty(ASM_NAME_CODEBASE_LASTMOD, &pTCInfo->ftLastModified, &(cb = sizeof(FILETIME))))) { goto exit; } if(pTCInfo->pwzName && (lstrlen(pTCInfo->pwzName) >= MAX_PATH) ) hr = FUSION_E_INVALID_NAME; // name is too long; this is an error. exit: if (SUCCEEDED(hr)) { *ppTransCache = pTransCache; } else { SAFERELEASE(pTransCache); } return hr; }
// --------------------------------------------------------------------------- // CCache::TransCacheEntryFromName // create transport entry from name //--------------------------------------------------------------------------- HRESULT CCache::TransCacheEntryFromName(IAssemblyName *pName, DWORD dwFlags, CTransCache **ppTransCache) { HRESULT hr; DWORD cb, dwCacheId = 0; TRANSCACHEINFO *pTCInfo = 0; CTransCache *pTransCache = NULL; _ASSERTE(pName); // Get the correct cache index. if(FAILED(hr = ResolveCacheIndex(pName, dwFlags, &dwCacheId))) goto exit; // Construct new CTransCache object. if(FAILED(hr = CreateTransCacheEntry(dwCacheId, &pTransCache))) goto exit; // Cast base info ptr to TRANSCACHEINFO ptr pTCInfo = (TRANSCACHEINFO*) pTransCache->_pInfo; // Downcased text name from target hr = NameObjGetWrapper(pName, ASM_NAME_NAME, (LPBYTE*) &pTCInfo->pwzName, &(cb = 0)); if (SUCCEEDED(hr)) { for (DWORD i=0; i<4; i++) { cb = sizeof(WORD); hr = pName->GetProperty(ASM_NAME_MAJOR_VERSION+i, &(pTCInfo->wVers[i]), &cb); if (FAILED(hr)) { goto exit; } } } if (SUCCEEDED(hr)) { hr = NameObjGetWrapper(pName, ASM_NAME_CULTURE, (LPBYTE*) &pTCInfo->pwzCulture, &cb); } if (SUCCEEDED(hr)) { hr = NameObjGetWrapper(pName, ASM_NAME_PUBLIC_KEY_TOKEN, &pTCInfo->blobPKT.pBlobData, &pTCInfo->blobPKT.cbSize); } if (SUCCEEDED(hr)) { hr = NameObjGetWrapper(pName, ASM_NAME_SIGNATURE_BLOB, &pTCInfo->blobSignature.pBlobData, &pTCInfo->blobSignature.cbSize); } if (SUCCEEDED(hr)) { hr = NameObjGetWrapper(pName, ASM_NAME_MVID, &pTCInfo->blobMVID.pBlobData, &pTCInfo->blobMVID.cbSize); } if (SUCCEEDED(hr)) { hr = NameObjGetWrapper(pName, ASM_NAME_CODEBASE_URL, (LPBYTE*) &pTCInfo->pwzCodebaseURL, &(cb = 0)); } if (SUCCEEDED(hr)) { hr = pName->GetProperty(ASM_NAME_CODEBASE_LASTMOD, &pTCInfo->ftLastModified, &(cb = sizeof(FILETIME))); } if(SUCCEEDED(hr)) { CAssemblyName *pCName = static_cast<CAssemblyName*>(pName); // dynamic_cast DWORD dwSize = 0; // Returns S_OK if no modifier exists hr = pCName->GetPathModifier(NULL, &dwSize); if(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) { pTCInfo->pwzPathModifier = NEW(WCHAR[dwSize]); if(!pTCInfo->pwzPathModifier) { hr = E_OUTOFMEMORY; goto exit; } hr = pCName->GetPathModifier(pTCInfo->pwzPathModifier, &dwSize); } } if (SUCCEEDED(hr)) { if(pTCInfo->pwzName && (lstrlenW(pTCInfo->pwzName) >= MAX_PATH) ) hr = FUSION_E_INVALID_NAME; // name is too long; this is an error. } if (SUCCEEDED(hr)) { CAssemblyName *pCName = static_cast<CAssemblyName*>(pName); // dynamic_cast pTCInfo->fLegacyAssembly = pCName->IsLegacyAssembly(); hr = pName->GetProperty(ASM_NAME_ARCHITECTURE, (LPBYTE) &pTCInfo->dwAsmImageType, &(cb = sizeof(DWORD))); } exit: if (SUCCEEDED(hr)) { *ppTransCache = pTransCache; } else { SAFERELEASE(pTransCache); } return hr; }
// --------------------------------------------------------------------------- // CCache::InsertTransCacheEntry //--------------------------------------------------------------------------- HRESULT CCache::InsertTransCacheEntry(IAssemblyName *pName, LPTSTR szPath, DWORD dwKBSize, DWORD dwFlags, DWORD dwCommitFlags, DWORD dwPinBits, CTransCache **ppTransCache) { HRESULT hr; DWORD cb, dwCacheId; TRANSCACHEINFO *pTCInfo = NULL; CTransCache *pTransCache = NULL; LPWSTR pwzCodebaseUrl = NULL; WCHAR pwzCanonicalized[MAX_URL_LENGTH]; // Determine which cache index to insert to. if (FAILED(hr = ResolveCacheIndex(pName, dwFlags, &dwCacheId))) goto exit; // Construct new CTransCache object. if(FAILED(hr = CreateTransCacheEntry(dwCacheId, &pTransCache))) goto exit; // Cast pTransCache base info ptr to TRANSCACHEINFO ptr pTCInfo = (TRANSCACHEINFO*) pTransCache->_pInfo; // Downcased text name from target if (FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_NAME, (LPBYTE*) &pTCInfo->pwzName, &(cb = 0))) // Version || FAILED(hr = pName->GetVersion(&pTCInfo->dwVerHigh, &pTCInfo->dwVerLow)) // Culture (downcased) || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_CULTURE, (LPBYTE*) &pTCInfo->pwzCulture, &cb)) || (pTCInfo->pwzCulture && !_wcslwr(pTCInfo->pwzCulture)) // PublicKeyToken || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_PUBLIC_KEY_TOKEN, &pTCInfo->blobPKT.pBlobData, &pTCInfo->blobPKT.cbSize)) // Custom || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_CUSTOM, &pTCInfo->blobCustom.pBlobData, &pTCInfo->blobCustom.cbSize)) // MVID || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_MVID, &pTCInfo->blobMVID.pBlobData, &pTCInfo->blobMVID.cbSize)) // Codebase url if any from target || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_CODEBASE_URL, (LPBYTE*)&pwzCodebaseUrl, &(cb = 0))) // Codebase last modified time if any from target. || FAILED(hr = pName->GetProperty(ASM_NAME_CODEBASE_LASTMOD, &pTCInfo->ftLastModified, &(cb = sizeof(FILETIME)))) // PK if any from source. || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_PUBLIC_KEY, &pTCInfo->blobPK.pBlobData, &pTCInfo->blobPK.cbSize)) ) { goto exit; } if (pwzCodebaseUrl) { cb = MAX_URL_LENGTH; hr = UrlCanonicalizeUnescape(pwzCodebaseUrl, pwzCanonicalized, &cb, 0); if (FAILED(hr)) { goto exit; } pTCInfo->pwzCodebaseURL = WSTRDupDynamic(pwzCanonicalized); if (!pTCInfo->pwzCodebaseURL) { hr = E_OUTOFMEMORY; goto exit; } } else { pTCInfo->pwzCodebaseURL = NULL; } // Copy in path. if (!(pTCInfo->pwzPath = TSTRDupDynamic(szPath))) { hr = E_OUTOFMEMORY; goto exit; } // File size pTCInfo->dwKBSize = dwKBSize; // Set pin Bits pTCInfo->dwPinBits = dwPinBits; exit: SAFEDELETEARRAY(pwzCodebaseUrl); // Base destructor takes care // of everything. if (!ppTransCache || (FAILED(hr) && (hr != DB_E_DUPLICATE))) { SAFERELEASE(pTransCache); } else { *ppTransCache = pTransCache; } return hr; }