void PackageWriter::_WriteAttributeTypes() { // create an array of the attribute types int32 attributeTypeCount = fAttributeTypes->CountElements(); AttributeType** attributeTypes = new AttributeType*[attributeTypeCount]; ArrayDeleter<AttributeType*> attributeTypesDeleter(attributeTypes); int32 index = 0; for (AttributeTypeTable::Iterator it = fAttributeTypes->GetIterator(); AttributeType* type = it.Next();) { attributeTypes[index++] = type; } // sort it by descending usage count std::sort(attributeTypes, attributeTypes + attributeTypeCount, AttributeTypeUsageGreater()); // assign the indices and write entries to disk for (int32 i = 0; i < attributeTypeCount; i++) { AttributeType* attributeType = attributeTypes[i]; attributeType->index = i; _Write<uint8>(attributeType->type); _WriteString(attributeType->name); } // write a terminating 0 byte _Write<uint8>(0); }
STDMETHODIMP HXCloakedV2TCPSocket::Write(IHXBuffer* pBuffer) { IHXBuffer* pNew = NULL; HX_RESULT res = HXR_FAIL; CHXString GetString = ""; // HX_ASSERT( csReady == m_CloakingState && pBuffer ); // if( csReady == m_CloakingState && pBuffer ) if( pBuffer ) { pBuffer->AddRef(); res = _GeneratePostRequest(pBuffer, pNew); HX_ASSERT(SUCCEEDED(res)); if( SUCCEEDED(res) && pNew ) { res = m_pTCPSocket->Write(pNew); } HX_RELEASE(pBuffer); HX_RELEASE(pNew); //We always follow our POST request with a Get request. GetString = _GenerateGetRequest(); _WriteString(GetString); } return res; }
static void WriteStat( SkLine *l, int ashtml, char *fmt, ... ) { va_list args; char out[2048]; va_start( args, fmt ); vsprintf( out, fmt, args ); va_end( args ); _WriteString(l,out); if ( ashtml ) _WritePacket(l,(unsigned char*)"<BR>",4); else _WritePacket(l,(unsigned char*)"\r\n",2); }
HX_RESULT HXCloakedV2TCPSocket::_EstablishGetAndPost() { HX_RESULT res = HXR_FAIL; CHXString GetString = ""; // CHXString PostString = ""; //inv. HX_ASSERT( m_pTCPSocket ); HX_ASSERT( csConnected == m_CloakingState ); //Generate our unique file name and hash for this connection. _ResetResourceAndHash(); //Make the GET request. GetString = _GenerateGetRequest(); // //Make the POST request. // PostString = _GeneratePostRequest(); HX_ASSERT( !GetString.IsEmpty() ); // HX_ASSERT( !PostString.IsEmpty() ); //Send our Get and Post requests to the server or proxy. res = _WriteString(GetString); HX_ASSERT(SUCCEEDED(res)); // if( SUCCEEDED(res) ) // { // res = _WriteString(PostString); // HX_ASSERT(SUCCEEDED(res)); // } if( SUCCEEDED(res) ) { //Move cloaking into preping state. m_CloakingState = csPreping; } return res; }
int32 PackageWriter::_WriteCachedStrings() { // create an array of the cached strings int32 count = fCachedStrings->CountElements(); CachedString** cachedStrings = new CachedString*[count]; ArrayDeleter<CachedString*> cachedStringsDeleter(cachedStrings); int32 index = 0; for (CachedStringTable::Iterator it = fCachedStrings->GetIterator(); CachedString* string = it.Next();) { cachedStrings[index++] = string; } // sort it by descending usage count std::sort(cachedStrings, cachedStrings + count, CachedStringUsageGreater()); // assign the indices and write entries to disk int32 stringsWritten = 0; for (int32 i = 0; i < count; i++) { CachedString* cachedString = cachedStrings[i]; // strings that are used only once are better stored inline if (cachedString->usageCount < 2) break; cachedString->index = i; _WriteString(cachedString->string); stringsWritten++; } // write a terminating 0 byte _Write<uint8>(0); return stringsWritten; }
void PackageWriter::_WriteAttributeValue(const AttributeValue& value, uint8 encoding) { switch (value.type) { case B_HPKG_ATTRIBUTE_TYPE_INT: case B_HPKG_ATTRIBUTE_TYPE_UINT: { uint64 intValue = value.type == B_HPKG_ATTRIBUTE_TYPE_INT ? (uint64)value.signedInt : value.unsignedInt; switch (encoding) { case B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT: _Write<uint8>((uint8)intValue); break; case B_HPKG_ATTRIBUTE_ENCODING_INT_16_BIT: _Write<uint16>( B_HOST_TO_BENDIAN_INT16((uint16)intValue)); break; case B_HPKG_ATTRIBUTE_ENCODING_INT_32_BIT: _Write<uint32>( B_HOST_TO_BENDIAN_INT32((uint32)intValue)); break; case B_HPKG_ATTRIBUTE_ENCODING_INT_64_BIT: _Write<uint64>( B_HOST_TO_BENDIAN_INT64((uint64)intValue)); break; default: { fprintf(stderr, "_WriteAttributeValue(): invalid " "encoding %d for int value type %d\n", encoding, value.type); throw status_t(B_BAD_VALUE); } } break; } case B_HPKG_ATTRIBUTE_TYPE_STRING: { if (encoding == B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE) _WriteUnsignedLEB128(value.string->index); else _WriteString(value.string->string); break; } case B_HPKG_ATTRIBUTE_TYPE_RAW: { _WriteUnsignedLEB128(value.data.size); if (encoding == B_HPKG_ATTRIBUTE_ENCODING_RAW_HEAP) _WriteUnsignedLEB128(value.data.offset); else fDataWriter->WriteDataThrows(value.data.raw, value.data.size); break; } default: fprintf(stderr, "_WriteAttributeValue(): invalid value type: " "%d\n", value.type); throw status_t(B_BAD_VALUE); } }
HRESULT StoreFusionInfo(IAssemblyName *pName, LPWSTR pszDir, DWORD *pdwFileSizeLow) { HRESULT hr = S_OK; WCHAR pszFilePath[MAX_PATH+1]; PBYTE pMVID=NULL; PBYTE pCustom=NULL; LPWSTR pszCustomString=NULL; LPWSTR pszURL=NULL; LPWSTR pszDisplayName=NULL; DWORD cbSize=0; BOOL fRet = FALSE; DWORD dwSize; LPWSTR pszBuf=NULL; HINI hIni=NULL; if(( lstrlenW(pszDir) + lstrlenW(g_FusionInfoFile) + 1) >= MAX_PATH) { hr = HRESULT_FROM_WIN32(FUSION_E_INVALID_NAME); goto exit; } StrCpy(pszFilePath, pszDir); PathAddBackslash(pszFilePath); StrCat(pszFilePath, g_FusionInfoFile); if ((hIni = PAL_IniCreate()) == NULL) { hr = FusionpHresultFromLastError(); goto exit; } #define _WriteString(section, key, value) PAL_IniWriteString(hIni, section, key, value) pszBuf = NEW(WCHAR[MAX_URL_LENGTH+1]); if (!pszBuf) { hr = E_OUTOFMEMORY; goto exit; } cbSize = 0; if(FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_MVID, &pMVID, &cbSize))) goto exit; if(cbSize && (cbSize == MVID_LENGTH)) { CParseUtils::BinToUnicodeHex(pMVID, cbSize, pszBuf); pszBuf[MVID_LENGTH*2] = L'\0'; fRet = _WriteString(ASSEMBLY_INFO_STRING, MVID_KEY_STRING, pszBuf); if (!fRet) { hr = FusionpHresultFromLastError(); goto exit; } } cbSize = 0; if(FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_CUSTOM, &pCustom, &cbSize))) goto exit; if(cbSize) { pszCustomString = (LPWSTR) pCustom; fRet = _WriteString(ASSEMBLY_INFO_STRING, CUSTOM_BLOB_STRING, pszCustomString); if (!fRet) { hr = FusionpHresultFromLastError(); goto exit; } } else { // if there is no Custom Blob try storing URL. cbSize = 0; if(FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_CODEBASE_URL, (LPBYTE*) &pszURL, &cbSize))) goto exit; if(cbSize) { fRet = _WriteString(ASSEMBLY_INFO_STRING, URL_STRING, pszURL); if (!fRet) { hr = FusionpHresultFromLastError(); goto exit; } } dwSize = 0; hr = pName->GetDisplayName(NULL, &dwSize, 0); if (hr != HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) { ASSERT(0); hr = E_UNEXPECTED; goto exit; } pszDisplayName = NEW(WCHAR[dwSize]); if (!pszDisplayName) { hr = E_OUTOFMEMORY; goto exit; } hr = pName->GetDisplayName(pszDisplayName, &dwSize, 0); if (FAILED(hr)) { goto exit; } cbSize = dwSize * sizeof(WCHAR); if(cbSize) { fRet = _WriteString(ASSEMBLY_INFO_STRING, DISPLAY_NAME_STRING, pszDisplayName); if (!fRet) { hr = FusionpHresultFromLastError(); goto exit; } } } if (!PAL_IniSave(hIni, pszFilePath, TRUE)) { hr = FusionpHresultFromLastError(); goto exit; } { DWORD dwSizeHigh=0; *pdwFileSizeLow = 512; // hard-code info file size. hr = GetFileSizeRoundedToCluster(INVALID_HANDLE_VALUE, pdwFileSizeLow, &dwSizeHigh); } exit: if (hIni != NULL) PAL_IniClose(hIni); SAFEDELETEARRAY(pszBuf); SAFEDELETEARRAY(pszDisplayName); SAFEDELETEARRAY(pMVID); SAFEDELETEARRAY(pCustom); SAFEDELETEARRAY(pszURL); return hr; }