[xiph-commits] r13658 - trunk/ezstream/src

moritz at svn.xiph.org moritz at svn.xiph.org
Thu Aug 30 04:31:33 PDT 2007


Author: moritz
Date: 2007-08-30 04:31:33 -0700 (Thu, 30 Aug 2007)
New Revision: 13658

Modified:
   trunk/ezstream/src/ezstream.c
   trunk/ezstream/src/util.c
   trunk/ezstream/src/util.h
Log:
* Back out conversions to ISO8859-1.
* Add 'charset=UTF-8' to the metadata update query arguments. The current
  release of Icecast will ignore it, and the next one will know how to handle
  it (karl@ is still working on it at this point, but previous diffs worked
  as advertised.)
* If no metadata format string is available and we have both an artist and
  a title, use the artist/title way of updating instead of the generic "song"
  interface.


Modified: trunk/ezstream/src/ezstream.c
===================================================================
--- trunk/ezstream/src/ezstream.c	2007-08-30 02:40:29 UTC (rev 13657)
+++ trunk/ezstream/src/ezstream.c	2007-08-30 11:31:33 UTC (rev 13658)
@@ -470,7 +470,8 @@
 setMetadata(shout_t *shout, metadata_t *mdata, char **mdata_copy)
 {
 	shout_metadata_t	*shout_mdata = NULL;
-	char			*songInfo, *encSongInfo;
+	char			*songInfo;
+	const char		*artist, *title;
 	int			 ret = SHOUTERR_SUCCESS;
 
 	if (shout == NULL) {
@@ -488,37 +489,63 @@
 		exit(1);
 	}
 
+	artist = metadata_get_artist(mdata);
+	title = metadata_get_title(mdata);
+
+	/*
+	 * We can do this, because we know how libshout works. This adds
+	 * "charset=UTF-8" to the HTTP metadata update request and has the
+	 * desired effect of letting newer-than-2.3.1 versions of Icecast know
+	 * which encoding we're using.
+	 */
+	if (shout_metadata_add(shout_mdata, "charset", "UTF-8") != SHOUTERR_SUCCESS) {
+		/* Assume SHOUTERR_MALLOC */
+		printf("%s: shout_metadata_add(): %s\n", __progname,
+		       strerror(ENOMEM));
+		exit(1);
+	}
+
 	if ((songInfo = getMetadataString(pezConfig->metadataFormat, mdata)) == NULL) {
-		if (strlen(metadata_get_artist(mdata)) == 0 &&
-		    strlen(metadata_get_title(mdata)) == 0)
+		if (artist[0] == '\0' && title[0] == '\0')
 			songInfo = xstrdup(metadata_get_string(mdata));
 		else
 			songInfo = metadata_assemble_string(mdata);
-	}
-
-	if (strcmp(pezConfig->format, VORBIS_FORMAT) == 0 ||
-	    strcmp(pezConfig->format, THEORA_FORMAT) == 0)
-		encSongInfo = xstrdup(songInfo);
-	else
-		encSongInfo = UTF8toISO8859_1(songInfo, ICONV_TRANSLIT);
-
-	if (shout_metadata_add(shout_mdata, "song", (encSongInfo != NULL) ? encSongInfo : "")
-	    != SHOUTERR_SUCCESS) {
-		/* Assume SHOUTERR_MALLOC */
+		if (artist[0] != '\0' && title[0] != '\0') {
+			if (shout_metadata_add(shout_mdata, "artist", artist) != SHOUTERR_SUCCESS) {
+				printf("%s: shout_metadata_add(): %s\n", __progname,
+				       strerror(ENOMEM));
+				exit(1);
+			}
+			if (shout_metadata_add(shout_mdata, "title", title) != SHOUTERR_SUCCESS) {
+				printf("%s: shout_metadata_add(): %s\n", __progname,
+				       strerror(ENOMEM));
+				exit(1);
+			}
+		} else {
+			if (shout_metadata_add(shout_mdata, "song", songInfo) != SHOUTERR_SUCCESS) {
+				printf("%s: shout_metadata_add(): %s\n", __progname,
+				       strerror(ENOMEM));
+				exit(1);
+			}
+		}
+	} else if (shout_metadata_add(shout_mdata, "song", songInfo) != SHOUTERR_SUCCESS) {
 		printf("%s: shout_metadata_add(): %s\n", __progname,
 		       strerror(ENOMEM));
 		exit(1);
 	}
+
 	if ((ret = shout_set_metadata(shout, shout_mdata)) != SHOUTERR_SUCCESS)
 		printf("%s: shout_set_metadata(): %s\n",
 		       __progname, shout_get_error(shout));
+
 	shout_metadata_free(shout_mdata);
-	if (ret == SHOUTERR_SUCCESS &&
-	    mdata_copy != NULL && *mdata_copy == NULL)
-		*mdata_copy = xstrdup(songInfo);
 
+	if (ret == SHOUTERR_SUCCESS) {
+		if (mdata_copy != NULL && *mdata_copy == NULL)
+			*mdata_copy = xstrdup(songInfo);
+	}
+
 	xfree(songInfo);
-	xfree(encSongInfo);
 	return (ret);
 }
 

Modified: trunk/ezstream/src/util.c
===================================================================
--- trunk/ezstream/src/util.c	2007-08-30 02:40:29 UTC (rev 13657)
+++ trunk/ezstream/src/util.c	2007-08-30 11:31:33 UTC (rev 13658)
@@ -236,7 +236,7 @@
 	setlocale(LC_CTYPE, "C");
 # else
 	codeset = (char *)"";
-# endif /* HAVE_NL_LANGINFO && HAVE_SETLOCALE */
+# endif /* HAVE_NL_LANGINFO && HAVE_SETLOCALE && CODESET */
 #else
 	char	 codeset[24];
 
@@ -261,7 +261,7 @@
 	setlocale(LC_CTYPE, "C");
 # else
 	codeset = (char *)"";
-# endif /* HAVE_NL_LANGINFO && HAVE_SETLOCALE */
+# endif /* HAVE_NL_LANGINFO && HAVE_SETLOCALE && CODESET */
 #else
 	char	 codeset[24];
 
@@ -275,15 +275,6 @@
 }
 
 char *
-UTF8toISO8859_1(const char *in_str, int mode)
-{
-	if (in_str == NULL || strlen(in_str) == 0)
-		return (NULL);
-
-	return (iconvert(in_str, "UTF-8", "ISO-8859-1", mode));
-}
-
-char *
 iconvert(const char *in_str, const char *from, const char *to, int mode)
 {
 #ifdef HAVE_ICONV

Modified: trunk/ezstream/src/util.h
===================================================================
--- trunk/ezstream/src/util.h	2007-08-30 02:40:29 UTC (rev 13657)
+++ trunk/ezstream/src/util.h	2007-08-30 11:31:33 UTC (rev 13658)
@@ -29,6 +29,5 @@
 shout_t *	stream_setup(const char *, const int, const char *);
 char *		CHARtoUTF8(const char *, int);
 char *		UTF8toCHAR(const char *, int);
-char *		UTF8toISO8859_1(const char *, int);
 
 #endif /* __UTIL_H__ */



More information about the commits mailing list