CTag::CTag(const CTag& rTag) { m_uType = rTag.m_uType; m_uName = rTag.m_uName; m_Name = rTag.m_Name; m_nSize = 0; if (rTag.IsStr()) { m_pstrVal = new wxString(rTag.GetStr()); } else if (rTag.IsInt()) { m_uVal = rTag.GetInt(); } else if (rTag.IsFloat()) { m_fVal = rTag.GetFloat(); } else if (rTag.IsHash()) { m_hashVal = new CMD4Hash(rTag.GetHash()); } else if (rTag.IsBlob()) { m_nSize = rTag.GetBlobSize(); m_pData = new unsigned char[rTag.GetBlobSize()]; memcpy(m_pData, rTag.GetBlob(), rTag.GetBlobSize()); } else if (rTag.IsBsob()) { m_nSize = rTag.GetBsobSize(); m_pData = new unsigned char[rTag.GetBsobSize()]; memcpy(m_pData, rTag.GetBsob(), rTag.GetBsobSize()); } else { wxFAIL; m_uVal = 0; } }
CTag::CTag(const CTag& rTag) { m_uType = rTag.m_uType; m_uName = rTag.m_uName; m_pszName = rTag.m_pszName!=NULL ? nstrdup(rTag.m_pszName) : NULL; m_nBlobSize = 0; if (rTag.IsStr()) m_pstrVal = new CString(rTag.GetStr()); else if (rTag.IsInt()) m_uVal = rTag.GetInt(); else if (rTag.IsFloat()) m_fVal = rTag.GetFloat(); else if (rTag.IsHash()){ m_pData = new BYTE[16]; md4cpy(m_pData, rTag.GetHash()); } else if (rTag.IsBlob()){ m_nBlobSize = rTag.GetBlobSize(); m_pData = new BYTE[rTag.GetBlobSize()]; memcpy(m_pData, rTag.GetBlob(), rTag.GetBlobSize()); } else{ ASSERT(0); m_uVal = 0; } ASSERT_VALID(this); }
void CFriend::LoadFromFile(CFileDataIO* file) { file->ReadHash16(m_abyUserhash); m_dwLastUsedIP = file->ReadUInt32(); m_nLastUsedPort = file->ReadUInt16(); m_dwLastSeen = ConvertFromTime32(file->ReadUInt32()); m_dwLastChatted = file->ReadUInt32(); UINT tagcount = file->ReadUInt32(); for (UINT j = 0; j < tagcount; j++){ CTag* newtag = new CTag(file, false); switch (newtag->GetNameID()){ case FF_NAME:{ ASSERT( newtag->IsStr() ); if (newtag->IsStr()){ if (m_strName.IsEmpty()) m_strName = newtag->GetStr(); } break; } case FF_KADID:{ ASSERT( newtag->IsHash() ); if (newtag->IsHash()) md4cpy(m_abyKadID, newtag->GetHash()); break; } } delete newtag; } }
void CFileDataIO::WriteTag(const CTag& tag) { try { WriteUInt8(tag.GetType()); if (!tag.GetName().IsEmpty()) { WriteString(tag.GetName(),utf8strNone); } else { WriteUInt16(1); WriteUInt8(tag.GetNameID()); } switch (tag.GetType()) { case TAGTYPE_HASH16: // Do NOT use this to transfer any tags for at least half a year!! WriteHash(CMD4Hash(tag.GetHash())); break; case TAGTYPE_STRING: WriteString(tag.GetStr(), utf8strRaw); // Always UTF8 break; case TAGTYPE_UINT64: WriteUInt64(tag.GetInt()); break; case TAGTYPE_UINT32: WriteUInt32(tag.GetInt()); break; case TAGTYPE_FLOAT32: WriteFloat(tag.GetFloat()); break; case TAGTYPE_BSOB: WriteBsob(tag.GetBsob(), tag.GetBsobSize()); break; case TAGTYPE_UINT16: WriteUInt16(tag.GetInt()); break; case TAGTYPE_UINT8: WriteUInt8(tag.GetInt()); break; case TAGTYPE_BLOB: // NOTE: This will break backward compatibility with met files for eMule versions prior to 0.44a // and any aMule prior to SVN 26/02/2005 WriteUInt32(tag.GetBlobSize()); Write(tag.GetBlob(), tag.GetBlobSize()); break; default: //TODO: Support more tag types // With the if above, this should NEVER happen. AddLogLineNS(CFormat(wxT("CFileDataIO::WriteTag: Unknown tag: type=0x%02X")) % tag.GetType()); wxFAIL; break; } } catch (...) { AddLogLineNS(wxT("Exception in CDataIO:WriteTag")); throw; } }
CCollectionFile::CCollectionFile(CFileDataIO* in_data) { UINT tagcount = in_data->ReadUInt32(); for (UINT i = 0; i < tagcount; i++) { CTag* toadd = new CTag(in_data, true); if (toadd) taglist.Add(toadd); } CTag* pTagHash = GetTag(FT_FILEHASH); if(pTagHash) SetFileHash(pTagHash->GetHash()); else ASSERT(0); // here we have two choices // - if the server/client sent us a filetype, we could use it (though it could be wrong) // - we always trust our filetype list and determine the filetype by the extension of the file // // if we received a filetype from server, we use it. // if we did not receive a filetype, we determine it by examining the file's extension. // // but, in no case, we will use the receive file type when adding this search result to the download queue, to avoid // that we are using 'wrong' file types in part files. (this has to be handled when creating the part files) const CString& rstrFileType = GetStrTagValue(FT_FILETYPE); SetFileName(GetStrTagValue(FT_FILENAME), false, rstrFileType.IsEmpty()); SetFileSize(GetIntTagValue(FT_FILESIZE)); if (!rstrFileType.IsEmpty()) { if (_tcscmp(rstrFileType, _T(ED2KFTSTR_PROGRAM))==0) { CString strDetailFileType = GetFileTypeByName(GetFileName()); if (!strDetailFileType.IsEmpty()) SetFileType(strDetailFileType); else SetFileType(rstrFileType); } else SetFileType(rstrFileType); } if(!GetFileSize() || !GetFileName().Compare(_T(""))) ASSERT(0); }