[xiph-commits] r9546 - icecast/branches/kh/icecast/src

karl at svn.xiph.org karl at svn.xiph.org
Sun Jul 3 16:30:29 PDT 2005


Author: karl
Date: 2005-07-03 16:30:26 -0700 (Sun, 03 Jul 2005)
New Revision: 9546

Modified:
   icecast/branches/kh/icecast/src/xslt.c
Log:
fix a couple of corner cases wrt xslt files, make sure sockets are closed
and that the buffer is truncated to the correct length or else some junk
chars may appear at the end.


Modified: icecast/branches/kh/icecast/src/xslt.c
===================================================================
--- icecast/branches/kh/icecast/src/xslt.c	2005-07-03 14:10:46 UTC (rev 9545)
+++ icecast/branches/kh/icecast/src/xslt.c	2005-07-03 23:30:26 UTC (rev 9546)
@@ -156,7 +156,7 @@
     xmlDocPtr    res;
     xsltStylesheetPtr cur;
     xmlChar *string;
-    int len;
+    int len, problem = 0;
 
     thread_mutex_lock(&xsltlock);
     cur = xslt_get_stylesheet(xslfilename);
@@ -171,20 +171,29 @@
 
     res = xsltApplyStylesheet(cur, doc, NULL);
 
-    xsltSaveResultToString (&string, &len, res, cur);
+    if (xsltSaveResultToString (&string, &len, res, cur) < 0)
+        problem = 1;
     thread_mutex_unlock(&xsltlock);
-    if (string)
+    if (problem == 0)
     {
         const char *http = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nContent-Length: ";
-        unsigned buf_len = strlen (http) + 20 + len;
+        int buf_len = strlen (http) + 20 + len;
 
+        if (string == NULL)
+            string = xmlStrdup ("");
         client->respcode = 200;
         client_set_queue (client, NULL);
         client->refbuf = refbuf_new (buf_len);
-        snprintf (client->refbuf->data, buf_len, "%s%d\r\n\r\n%s", http, len, string);
+        len = snprintf (client->refbuf->data, buf_len, "%s%d\r\n\r\n%s", http, len, string);
+        client->refbuf->len = len;
         fserve_add_client (client, NULL);
         xmlFree (string);
     }
+    else
+    {
+        WARN1 ("problem applying stylesheet \"%s\"", xslfilename);
+        client_send_404 (client, "XSLT problem");
+    }
     xmlFreeDoc(res);
 }
 



More information about the commits mailing list