From 35d6ac4cfab635b0cb54301146ced0b5877b99f2 Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Mon, 21 Jun 2010 17:50:09 +0200 Subject: [PATCH] Add unicode_fixup_mfi() to check & reencode UTF-8 fields in struct media_file_info --- src/db.c | 34 ++++++++++++++++++++++++++++++++++ src/db.h | 3 +++ 2 files changed, 37 insertions(+) diff --git a/src/db.c b/src/db.c index efda780a..9f26fc78 100644 --- a/src/db.c +++ b/src/db.c @@ -351,6 +351,40 @@ free_mfi(struct media_file_info *mfi, int content_only) free(mfi); } +void +unicode_fixup_mfi(struct media_file_info *mfi) +{ + char *ret; + char **field; + int i; + + for (i = 0; i < (sizeof(mfi_cols_map) / sizeof(mfi_cols_map[0])); i++) + { + if (mfi_cols_map[i].type != DB_TYPE_STRING) + continue; + + switch (mfi_cols_map[i].offset) + { + case mfi_offsetof(path): + case mfi_offsetof(fname): + case mfi_offsetof(codectype): + continue; + } + + field = (char **) ((char *)mfi + mfi_cols_map[i].offset); + + if (!*field) + continue; + + ret = unicode_fixup_string(*field); + if (ret != *field) + { + free(*field); + *field = ret; + } + } +} + void free_pli(struct playlist_info *pli, int content_only) { diff --git a/src/db.h b/src/db.h index 119fec6a..5ab9fee5 100644 --- a/src/db.h +++ b/src/db.h @@ -268,6 +268,9 @@ free_pi(struct pairing_info *pi, int content_only); void free_mfi(struct media_file_info *mfi, int content_only); +void +unicode_fixup_mfi(struct media_file_info *mfi); + void free_pli(struct playlist_info *pli, int content_only);