1
0

frame_private.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "nsid3v2.h"
  2. #include "nsid3v2/header.h"
  3. #include "nsid3v2/tag.h"
  4. #include "nsid3v2/frame_utils.h"
  5. #include "nu/ByteReader.h"
  6. #include "nx/nxstring.h"
  7. #if defined(_WIN32) && !defined(strcasecmp)
  8. #define strcasecmp _stricmp
  9. #else
  10. #include <strings.h>
  11. #endif
  12. struct ParsedPrivate
  13. {
  14. ParsedString owner;
  15. const void *private_data;
  16. size_t private_byte_length;
  17. };
  18. static int ParsePrivate(const void *data, size_t data_len, ParsedPrivate &parsed)
  19. {
  20. if (data_len == 0)
  21. return NErr_Insufficient;
  22. bytereader_value_t byte_reader;
  23. bytereader_init(&byte_reader, data, data_len);
  24. int ret = ParseNullTerminatedString(&byte_reader, 0, parsed.owner);
  25. if (ret != NErr_Success)
  26. return ret;
  27. parsed.private_data = bytereader_pointer(&byte_reader);
  28. parsed.private_byte_length = bytereader_size(&byte_reader);
  29. return NErr_Success;
  30. }
  31. int NSID3v2_Frame_Private_Get(const nsid3v2_frame_t f, nx_string_t *description, const void **out_data, size_t *length)
  32. {
  33. const ID3v2::Frame *frame = (const ID3v2::Frame *)f;
  34. if (frame)
  35. {
  36. const void *data;
  37. size_t data_len;
  38. ParsedPrivate parsed;
  39. if (frame->GetData(&data, &data_len) == NErr_Success && data_len > 0 && ParsePrivate(data, data_len, parsed) == NErr_Success)
  40. {
  41. int ret = NXStringCreateFromParsedString(description, parsed.owner, 0);
  42. if (ret != NErr_Success)
  43. return ret;
  44. *out_data = parsed.private_data;
  45. *length = parsed.private_byte_length;
  46. return NErr_Success;
  47. }
  48. }
  49. return NErr_Empty;
  50. }