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

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Sat Jun 11 06:31:44 PDT 2005


Author: karl
Date: 2005-06-11 06:31:40 -0700 (Sat, 11 Jun 2005)
New Revision: 9438

Modified:
   icecast/branches/kh/icecast/src/auth_htpasswd.c
   icecast/branches/kh/icecast/src/fserve.c
   icecast/branches/kh/icecast/src/source.c
Log:
small cleanups, and a few extra checks added


Modified: icecast/branches/kh/icecast/src/auth_htpasswd.c
===================================================================
--- icecast/branches/kh/icecast/src/auth_htpasswd.c	2005-06-11 01:24:58 UTC (rev 9437)
+++ icecast/branches/kh/icecast/src/auth_htpasswd.c	2005-06-11 13:31:40 UTC (rev 9438)
@@ -22,6 +22,8 @@
 #include <string.h>
 #include <errno.h>
 #include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #include "auth.h"
 #include "source.h"
@@ -257,6 +259,7 @@
     char *sep;
     char *tmpfile = NULL;
     int tmpfile_len = 0;
+    struct stat file_info;
 
     state = auth->state;
     passwdfile = fopen(state->filename, "rb");
@@ -268,7 +271,14 @@
     }
     tmpfile_len = strlen(state->filename) + 6;
     tmpfile = calloc(1, tmpfile_len);
-    sprintf(tmpfile, "%s.tmp", state->filename);
+    snprintf (tmpfile, tmpfile_len, "%s.tmp", state->filename);
+    if (stat (tmpfile, &file_info) == 0)
+    {
+        WARN1 ("temp file \"%s\" exists, rejecting operation", tmpfile);
+        free (tmpfile);
+        fclose (passwdfile);
+        return AUTH_FAILED;
+    }
 
     tmp_passwdfile = fopen(tmpfile, "wb");
 

Modified: icecast/branches/kh/icecast/src/fserve.c
===================================================================
--- icecast/branches/kh/icecast/src/fserve.c	2005-06-11 01:24:58 UTC (rev 9437)
+++ icecast/branches/kh/icecast/src/fserve.c	2005-06-11 13:31:40 UTC (rev 9438)
@@ -344,6 +344,10 @@
             return "text/css";
         else if(!strcmp(ext, "txt"))
             return "text/plain";
+        else if(!strcmp(ext, "jpg"))
+            return "image/jpeg";
+        else if(!strcmp(ext, "png"))
+            return "image/png";
         else if(!strcmp(ext, "m3u"))
             return "audio/x-mpegurl";
         else
@@ -412,7 +416,7 @@
             host = strdup (config->hostname);
             port = config->port;
             config_release_config();
-            bytes = sock_write (httpclient->con->sock,
+            sock_write (httpclient->con->sock,
                     "HTTP/1.0 200 OK\r\n"
                     "Content-Type: audio/x-mpegurl\r\n\r\n"
                     "http://%s:%d%s\r\n", 
@@ -423,7 +427,7 @@
         }
         else
         {
-            bytes = sock_write (httpclient->con->sock,
+            sock_write (httpclient->con->sock,
                     "HTTP/1.0 200 OK\r\n"
                     "Content-Type: audio/x-mpegurl\r\n\r\n"
                     "http://%s%s\r\n", 
@@ -442,7 +446,7 @@
         /* If the file exists, then transform it, otherwise, write a 404 */
         DEBUG0("Stats request, sending XSL transformed stats");
         httpclient->respcode = 200;
-        bytes = sock_write(httpclient->con->sock, 
+        sock_write(httpclient->con->sock, 
                 "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n");
         stats_transform_xslt (httpclient, fullpath);
         client_destroy (httpclient);
@@ -476,7 +480,6 @@
     client->ready = 0;
     client_set_queue (httpclient, NULL);
     httpclient->refbuf = refbuf_new (BUFSIZE);
-    httpclient->pos = BUFSIZE;
     client->content_length = (int64_t)file_buf.st_size;
 
     range = httpp_getvar (client->client->parser, "range");
@@ -508,7 +511,7 @@
                 strflen = strftime(currenttime, 50, "%a, %d-%b-%Y %X GMT",
                                    gmtime_r (&now, &result));
                 httpclient->respcode = 206;
-                bytes = sock_write(httpclient->con->sock,
+                bytes = snprintf (httpclient->refbuf->data, BUFSIZE,
                     "HTTP/1.1 206 Partial Content\r\n"
                     "Date: %s\r\n"
                     "Content-Length: " FORMAT_INT64 "\r\n"
@@ -527,14 +530,14 @@
         }
         else {
             httpclient->respcode = 200;
-            bytes = sock_write (httpclient->con->sock,
+            bytes = snprintf (httpclient->refbuf->data, BUFSIZE,
                     "HTTP/1.0 200 OK\r\n"
                     "Content-Length: " FORMAT_INT64 "\r\n"
                     "Content-Type: %s\r\n\r\n",
                     client->content_length,
                     fserve_content_type(path));
         }
-
+        httpclient->refbuf->len = bytes;
         stats_event_inc (NULL, "file_connections");
         sock_set_blocking(client->client->con->sock, SOCK_NONBLOCK);
         sock_set_nodelay(client->client->con->sock);
@@ -549,9 +552,8 @@
     /* If we run into any issues with the ranges
        we fallback to a normal/non-range request */
     httpclient->respcode = 416;
-    bytes = sock_write(httpclient->con->sock,
+    sock_write (httpclient->con->sock,
             "HTTP/1.0 416 Request Range Not Satisfiable\r\n\r\n");
-    if(bytes > 0) httpclient->con->sent_bytes = bytes;
     fserve_client_destroy (client);
     return 0;
 }
@@ -581,8 +583,11 @@
 
     mimetypes = avl_tree_new(_compare_mappings, NULL);
 
-    if(!mimefile)
+    if (mimefile == NULL)
+    {
+        WARN1 ("Cannot open mime type file %s", fn);
         return;
+    }
 
     while(fgets(line, 4096, mimefile))
     {

Modified: icecast/branches/kh/icecast/src/source.c
===================================================================
--- icecast/branches/kh/icecast/src/source.c	2005-06-11 01:24:58 UTC (rev 9437)
+++ icecast/branches/kh/icecast/src/source.c	2005-06-11 13:31:40 UTC (rev 9438)
@@ -570,6 +570,11 @@
 }
 
 
+/* run through the queue of listeners, the fast ones are at the back of the
+ * queue so you may want to process only those. If a buffer is going to be
+ * removed from the stream queue then flag it so that listeners can be
+ * dropped if need be.
+ */
 static void process_listeners (source_t *source, int fast_clients_only, int deletion_expected)
 {
     client_t *client, **client_p;
@@ -637,17 +642,16 @@
 }
 
 
+/* Perform any initialisation before the stream data is processed, the header
+ * info is processed by now and the format details are setup
+ */
 static void source_init (source_t *source)
 {
-    char *str = "0";
+    char *str;
     mount_proxy *mountinfo;
 
     thread_mutex_lock (&source->lock);
 
-    stats_event (source->mount, "server_type", source->format->contenttype);
-    stats_event_args (source->mount, "listener_peak", "0");
-    stats_event_time (source->mount, "stream_start");
-
     if (source->dumpfilename != NULL)
     {
         source->dumpfile = fopen (source->dumpfilename, "ab");
@@ -664,6 +668,9 @@
     /* start off the statistics */
     stats_event_inc (NULL, "source_total_connections");
     stats_event (source->mount, "slow_listeners", "0");
+    stats_event (source->mount, "server_type", source->format->contenttype);
+    stats_event (source->mount, "listener_peak", "0");
+    stats_event_time (source->mount, "stream_start");
 
     if (source->client->con)
         sock_set_blocking (source->client->con->sock, SOCK_NONBLOCK);



More information about the commits mailing list