static void LinkBlockIndex(tag_block_definition& source_block_definition , cstring block_field_path , tag_block_definition& target_block_definition , cstring block_index_field_name) { static_assert((kFieldType == Enums::_field_long_block_index) || (kFieldType == Enums::_field_short_block_index) , "LinkBlockIndex can only be used with short and long block indices fields"); // Get the source block field and the target block index auto& source_field = GetTagField(source_block_definition, Enums::_field_block, block_field_path); auto& target_field = GetTagField(target_block_definition, kFieldType, block_index_field_name); // Set the index fields definition target_field.definition = source_field.Definition<tag_block_definition>(); }
int CAPETag::GetFieldBinary(const str_utf16 * pFieldName, void * pBuffer, int * pBufferBytes) { if (m_bAnalyzed == FALSE) { Analyze(); } int nRetVal = ERROR_UNDEFINED; if (*pBufferBytes > 0) { CAPETagField * pAPETagField = GetTagField(pFieldName); if (pAPETagField == NULL) { memset(pBuffer, 0, *pBufferBytes); *pBufferBytes = 0; } else { if (pAPETagField->GetFieldValueSize() > *pBufferBytes) { // we'll fail here, because partial data may be worse than no data memset(pBuffer, 0, *pBufferBytes); *pBufferBytes = pAPETagField->GetFieldValueSize(); } else { // memcpy *pBufferBytes = pAPETagField->GetFieldValueSize(); memcpy(pBuffer, pAPETagField->GetFieldValue(), *pBufferBytes); nRetVal = ERROR_SUCCESS; } } } return nRetVal; }
static string_list* FindFlagsField(tag_block_definition* definition, cstring flags_field_name = "flags") { static_assert(kFieldType == Enums::_field_byte_flags || kFieldType == Enums::_field_word_flags || kFieldType == Enums::_field_long_flags, "Expected a flags-based field type"); auto& flags_field = GetTagField(*definition, kFieldType, flags_field_name); return flags_field.Definition<string_list>(); }
int CAPETag::GetFieldString(const str_utf16 * pFieldName, str_utf16 * pBuffer, int * pBufferCharacters) { if (m_bAnalyzed == FALSE) { Analyze(); } int nRetVal = ERROR_UNDEFINED; if (*pBufferCharacters > 0) { CAPETagField * pAPETagField = GetTagField(pFieldName); if (pAPETagField == NULL) { // the field doesn't exist -- return an empty string memset(pBuffer, 0, *pBufferCharacters * sizeof(str_utf16)); *pBufferCharacters = 0; } else if (pAPETagField->GetIsUTF8Text() || (m_nAPETagVersion < 2000)) { // get the value in UTF-16 format CSmartPtr<str_utf16> spUTF16; if (m_nAPETagVersion >= 2000) spUTF16.Assign(GetUTF16FromUTF8((str_utf8 *) pAPETagField->GetFieldValue()), TRUE); else spUTF16.Assign(GetUTF16FromANSI(pAPETagField->GetFieldValue()), TRUE); // get the number of characters int nCharacters = (wcslen(spUTF16) + 1); if (nCharacters > *pBufferCharacters) { // we'll fail here, because it's not clear what would get returned (null termination, size, etc.) // and we really don't want to cause buffer overruns on the client side *pBufferCharacters = nCharacters; } else { // just copy in *pBufferCharacters = nCharacters; memcpy(pBuffer, spUTF16.GetPtr(), *pBufferCharacters * sizeof(str_utf16)); nRetVal = ERROR_SUCCESS; } } else { // memset the whole buffer to NULL (so everything left over is NULL terminated) memset(pBuffer, 0, *pBufferCharacters * sizeof(str_utf16)); // do a binary dump (need to convert from wchar's to bytes) int nBufferBytes = (*pBufferCharacters - 1) * sizeof(str_utf16); nRetVal = GetFieldBinary(pFieldName, pBuffer, &nBufferBytes); *pBufferCharacters = (nBufferBytes / sizeof(str_utf16)) + 1; } } return nRetVal; }