From 1004890e253453faba81126028986f075e5fc5e7 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Tue, 13 Apr 2004 04:59:57 +0000 Subject: lots of fsCharset, utf8/ascii converting clean-up and robustness stuff Also, if fsCharsetToUtf8 can't convert to valid UTF-8, then don't add it to the db, this way clients don't have to worry about weirdness and it will force ppl to convert it. git-svn-id: https://svn.musicpd.org/mpd/trunk@711 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/path.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/path.c') diff --git a/src/path.c b/src/path.c index e209b671d..db41ed968 100644 --- a/src/path.c +++ b/src/path.c @@ -20,6 +20,7 @@ #include "log.h" #include "charConv.h" #include "conf.h" +#include "utf8.h" #include #include @@ -46,24 +47,35 @@ char * pathConvCharset(char * to, char * from, char * str, char * ret) { ret = convStrDup(str); } - if(!ret) ret = strdup(str); - return ret; } char * fsCharsetToUtf8(char * str) { static char * ret = NULL; - return ret = pathConvCharset("UTF-8",fsCharset,str,ret); + ret = pathConvCharset("UTF-8",fsCharset,str,ret); + + if(ret && !validUtf8String(ret)) ret = NULL; + /*if(!ret) ret = asciiStrToUtf8Dup(str);*/ + + /* if all else fails, just strdup */ + + return ret; } char * utf8ToFsCharset(char * str) { static char * ret = NULL; - return ret = pathConvCharset(fsCharset,"UTF-8",str,ret); + ret = pathConvCharset(fsCharset,"UTF-8",str,ret); + + if(!ret) ret = strdup(str); + + return ret; } void setFsCharset(char * charset) { + int error = 0; + if(fsCharset) free(fsCharset); fsCharset = strdup(charset); @@ -74,11 +86,19 @@ void setFsCharset(char * charset) { ERROR("fs charset conversion problem: " "not able to convert from \"%s\" to \"%s\"\n", fsCharset,"UTF-8"); + error = 1; } if(setCharSetConversion(fsCharset,"UTF-8")!=0) { ERROR("fs charset conversion problem: " "not able to convert from \"%s\" to \"%s\"\n", "UTF-8",fsCharset); + error = 1; + } + + if(error) { + free(fsCharset); + ERROR("setting fs charset to ISO-8859-1!\n"); + fsCharset = strdup("ISO-8859-1"); } } -- cgit v1.2.3