1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2024-11-03 04:17:18 -05:00

Perform more charset conversions where necessary. This should fix the handling

of files with non-ASCII filenames, as well as some more cases related to
metadata.
From Roman Donchenko <DXDragon at yandex dot ru>, with some minor fixes by
myself.


git-svn-id: https://svn.xiph.org/trunk/ezstream@15770 0101bb08-14d6-0310-b084-bc0e0c8e3800
This commit is contained in:
moritz 2009-03-15 11:05:44 +00:00
parent 057bc88dad
commit ae3dd91581
2 changed files with 32 additions and 16 deletions

View File

@ -29,6 +29,7 @@
#include "compat.h"
#include "configfile.h"
#include "strfctns.h"
#include "util.h"
#include "xalloc.h"
extern char *__progname;
@ -175,7 +176,7 @@ parseConfig(const char *fileName)
config_error++;
continue;
}
ezConfig.fileName = xstrdup(ls_xmlContentPtr);
ezConfig.fileName = UTF8toCHAR(ls_xmlContentPtr, ICONV_REPLACE);
xmlFree(ls_xmlContentPtr);
}
}
@ -194,7 +195,7 @@ parseConfig(const char *fileName)
config_error++;
continue;
}
ezConfig.metadataProgram = xstrdup(ls_xmlContentPtr);
ezConfig.metadataProgram = UTF8toCHAR(ls_xmlContentPtr, ICONV_REPLACE);
xmlFree(ls_xmlContentPtr);
}
}
@ -516,7 +517,7 @@ parseConfig(const char *fileName)
unsigned int ret;
ls_xmlContentPtr = (char *)xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
pformatEncDec->decoder = xstrdup(ls_xmlContentPtr);
pformatEncDec->decoder = UTF8toCHAR(ls_xmlContentPtr, ICONV_REPLACE);
xmlFree(ls_xmlContentPtr);
if ((ret = checkDecoderLine(pformatEncDec->decoder,
fileName, xmlGetLineNo(cur3)))
@ -537,7 +538,7 @@ parseConfig(const char *fileName)
unsigned int ret;
ls_xmlContentPtr = (char *)xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
pformatEncDec->encoder = xstrdup(ls_xmlContentPtr);
pformatEncDec->encoder = UTF8toCHAR(ls_xmlContentPtr, ICONV_REPLACE);
xmlFree(ls_xmlContentPtr);
if ((ret = checkEncoderLine(pformatEncDec->encoder,
fileName, xmlGetLineNo(cur3)))

View File

@ -251,11 +251,20 @@ buildCommandString(const char *extension, const char *fileName,
size_t newDecoderLen = 0;
char *newEncoder = NULL;
size_t newEncoderLen = 0;
char *localTitle = UTF8toCHAR(metadata_get_title(mdata),
ICONV_REPLACE);
char *localArtist = UTF8toCHAR(metadata_get_artist(mdata),
ICONV_REPLACE);
char *localMetaString = UTF8toCHAR(metadata_get_string(mdata),
ICONV_REPLACE);
decoder = xstrdup(getFormatDecoder(extension));
if (strlen(decoder) == 0) {
printf("%s: Unknown extension '%s', cannot decode '%s'\n",
__progname, extension, fileName);
xfree(localTitle);
xfree(localArtist);
xfree(localMetaString);
xfree(decoder);
return (NULL);
}
@ -264,18 +273,18 @@ buildCommandString(const char *extension, const char *fileName,
replaceString(decoder, newDecoder, newDecoderLen, TRACK_PLACEHOLDER,
fileName);
if (strstr(decoder, ARTIST_PLACEHOLDER) != NULL) {
size_t tmpLen = strlen(newDecoder) + strlen(metadata_get_artist(mdata)) + 1;
size_t tmpLen = strlen(newDecoder) + strlen(localArtist) + 1;
char *tmpStr = xcalloc(tmpLen, sizeof(char));
replaceString(newDecoder, tmpStr, tmpLen, ARTIST_PLACEHOLDER,
metadata_get_artist(mdata));
localArtist);
xfree(newDecoder);
newDecoder = tmpStr;
}
if (strstr(decoder, TITLE_PLACEHOLDER) != NULL) {
size_t tmpLen = strlen(newDecoder) + strlen(metadata_get_title(mdata)) + 1;
size_t tmpLen = strlen(newDecoder) + strlen(localTitle) + 1;
char *tmpStr = xcalloc(tmpLen, sizeof(char));
replaceString(newDecoder, tmpStr, tmpLen, TITLE_PLACEHOLDER,
metadata_get_title(mdata));
localTitle);
xfree(newDecoder);
newDecoder = tmpStr;
}
@ -308,11 +317,11 @@ buildCommandString(const char *extension, const char *fileName,
xfree(newDecoder);
newDecoder = tmpStr;
} else {
size_t tmpLen = strlen(newDecoder) + strlen(metadata_get_string(mdata)) + 1;
size_t tmpLen = strlen(newDecoder) + strlen(localMetaString) + 1;
char *tmpStr = xcalloc(tmpLen, sizeof(char));
replaceString(newDecoder, tmpStr, tmpLen,
METADATA_PLACEHOLDER,
metadata_get_string(mdata));
localMetaString);
xfree(newDecoder);
newDecoder = tmpStr;
}
@ -329,21 +338,24 @@ buildCommandString(const char *extension, const char *fileName,
commandStringLen = strlen(newDecoder) + 1;
commandString = xcalloc(commandStringLen, sizeof(char));
strlcpy(commandString, newDecoder, commandStringLen);
xfree(localTitle);
xfree(localArtist);
xfree(localMetaString);
xfree(decoder);
xfree(encoder);
xfree(newDecoder);
return (commandString);
}
newEncoderLen = strlen(encoder) + strlen(metadata_get_artist(mdata)) + 1;
newEncoderLen = strlen(encoder) + strlen(localArtist) + 1;
newEncoder = xcalloc(newEncoderLen, sizeof(char));
replaceString(encoder, newEncoder, newEncoderLen, ARTIST_PLACEHOLDER,
metadata_get_artist(mdata));
localArtist);
if (strstr(encoder, TITLE_PLACEHOLDER) != NULL) {
size_t tmpLen = strlen(newEncoder) + strlen(metadata_get_title(mdata)) + 1;
size_t tmpLen = strlen(newEncoder) + strlen(localTitle) + 1;
char *tmpStr = xcalloc(tmpLen, sizeof(char));
replaceString(newEncoder, tmpStr, tmpLen, TITLE_PLACEHOLDER,
metadata_get_title(mdata));
localTitle);
xfree(newEncoder);
newEncoder = tmpStr;
}
@ -366,11 +378,11 @@ buildCommandString(const char *extension, const char *fileName,
xfree(newEncoder);
newEncoder = tmpStr;
} else {
size_t tmpLen = strlen(newEncoder) + strlen(metadata_get_string(mdata)) + 1;
size_t tmpLen = strlen(newEncoder) + strlen(localMetaString) + 1;
char *tmpStr = xcalloc(tmpLen, sizeof(char));
replaceString(newEncoder, tmpStr, tmpLen,
METADATA_PLACEHOLDER,
metadata_get_string(mdata));
localMetaString);
xfree(newEncoder);
newEncoder = tmpStr;
}
@ -383,6 +395,9 @@ buildCommandString(const char *extension, const char *fileName,
snprintf(commandString, commandStringLen, "%s | %s", newDecoder,
newEncoder);
xfree(localTitle);
xfree(localArtist);
xfree(localMetaString);
xfree(decoder);
xfree(encoder);
xfree(newDecoder);