[xiph-commits] r8784 - trunk/icecast2yp/src

oddsock at motherfish-iii.xiph.org oddsock at motherfish-iii.xiph.org
Sun Jan 23 21:28:06 PST 2005


Author: oddsock
Date: 2005-01-23 21:28:05 -0800 (Sun, 23 Jan 2005)
New Revision: 8784

Modified:
   trunk/icecast2yp/src/Makefile.am
   trunk/icecast2yp/src/yp_cachegen.c
Log:
generate yp cache in UTF-8 and also, use iconv for the conversion to UTF-8


Modified: trunk/icecast2yp/src/Makefile.am
===================================================================
--- trunk/icecast2yp/src/Makefile.am	2005-01-23 17:38:44 UTC (rev 8783)
+++ trunk/icecast2yp/src/Makefile.am	2005-01-24 05:28:05 UTC (rev 8784)
@@ -12,8 +12,8 @@
 yp_clean_SOURCES = yp_clean.c log.c yp_routines.c
 yp_random_SOURCES = yp_random.c log.c yp_routines.c
     
-CFLAGS = @CFLAGS@ @MYSQL_CFLAGS@ @XML_CFLAGS@ -I${prefix}/include
-LIBS = @LIBS@ @MYSQL_LIBS@ @XML_LIBS@ -L${prefix}/lib
+CFLAGS = @CFLAGS@ @MYSQL_CFLAGS@ @XML_CFLAGS@ -I${prefix}/include -I/usr/include/libcgi `xml2-config --cflags`
+LIBS = @LIBS@ @MYSQL_LIBS@ @XML_LIBS@ -L${prefix}/lib `xml2-config --libs`
 
 
 static:

Modified: trunk/icecast2yp/src/yp_cachegen.c
===================================================================
--- trunk/icecast2yp/src/yp_cachegen.c	2005-01-23 17:38:44 UTC (rev 8783)
+++ trunk/icecast2yp/src/yp_cachegen.c	2005-01-24 05:28:05 UTC (rev 8784)
@@ -9,6 +9,7 @@
 #include <unistd.h>
 #include <libxml/xmlmemory.h>
 #include <libxml/parser.h>
+#include <iconv.h>
 #include "log.h"
 
 
@@ -22,38 +23,26 @@
 unsigned char*
 convert (unsigned char *in, char *encoding)
 {
-	unsigned char *out;
+	char *out, *pin, *pout;
         int ret,size,out_size,temp;
-        xmlCharEncodingHandlerPtr handler;
+	iconv_t	iconv_handle;
 
         size = (int)strlen(in)+1; 
         out_size = size*2-1; 
         out = malloc((size_t)out_size); 
 
+	pin = (char *)in;
+	pout = out;
+
         if (out) {
-                handler = xmlFindCharEncodingHandler(encoding);
-                
-                if (!handler) {
-                        free(out);
-                        out = NULL;
-                }
+		iconv_handle =  iconv_open("UTF-8", "ISO-8859-1");
         }
         if (out) {
-                temp=size-1;
-                ret = handler->input(out, &out_size, in, &temp);
-                if (ret || temp-size+1) {
-                        if (ret) {
-                                printf("conversion wasn't successful.\n");
-                        } else {
-                                printf("conversion wasn't successful. converted: %i octets.\n",temp);
-                        }
-                        free(out);
-                        out = NULL;
-                } else {
-                        out = realloc(out,out_size+1); 
-                        out[out_size]=0; /*null terminating out*/
-                        
-                }
+		size_t ret = iconv(iconv_handle, &pin, &size, &pout, &out_size);
+		if (ret == -1) {
+			printf("unable to convert (%s)", in);
+		}
+		iconv_close(iconv_handle);
         } else {
                 printf("no mem\n");
         }
@@ -73,7 +62,7 @@
         char    parent_id[255] = "";
 	char	*p1;
 	int	randomNumber = 0;
-	char *encoding = "ISO-8859-1";
+	char *encoding = "UTF-8";
 
 	xmlDocPtr doc;
 	xmlNodePtr rootNode;
@@ -141,6 +130,7 @@
 		}
 		mysql_free_result(result);
 	}
+	unlink("yp.xml");
 	xmlSaveFormatFileEnc("yp.xml", doc, encoding, 1);
 	return(SUCCESS);
 }



More information about the commits mailing list