[xiph-commits] r9445 - icecast/branches/kh/icecast/src
karl at motherfish-iii.xiph.org
karl at motherfish-iii.xiph.org
Mon Jun 13 09:43:58 PDT 2005
Author: karl
Date: 2005-06-13 09:43:44 -0700 (Mon, 13 Jun 2005)
New Revision: 9445
Modified:
icecast/branches/kh/icecast/src/admin.c
icecast/branches/kh/icecast/src/connection.c
icecast/branches/kh/icecast/src/fserve.c
icecast/branches/kh/icecast/src/fserve.h
icecast/branches/kh/icecast/src/slave.c
icecast/branches/kh/icecast/src/xslt.c
Log:
file serve update. xsl/xml pages from webroot or adminroot are passed to file
server thread for delivery. Also small sync-up with trunk
Modified: icecast/branches/kh/icecast/src/admin.c
===================================================================
--- icecast/branches/kh/icecast/src/admin.c 2005-06-13 13:54:22 UTC (rev 9444)
+++ icecast/branches/kh/icecast/src/admin.c 2005-06-13 16:43:44 UTC (rev 9445)
@@ -32,6 +32,7 @@
#include "stats.h"
#include "os.h"
#include "xslt.h"
+#include "fserve.h"
#include "format.h"
@@ -215,7 +216,6 @@
static void admin_handle_general_request(client_t *client, int command);
static void admin_send_response(xmlDocPtr doc, client_t *client,
int response, char *xslt_template);
-static void html_write(client_t *client, char *fmt, ...);
/* build an XML doc containing information about currently running sources.
* If a mountpoint is passed then that source will not be added to the XML
@@ -288,41 +288,38 @@
void admin_send_response(xmlDocPtr doc, client_t *client,
int response, char *xslt_template)
{
- xmlChar *buff = NULL;
- int len = 0;
- ice_config_t *config;
- char *fullpath_xslt_template;
- int fullpath_xslt_template_len;
- char *adminwebroot;
-
- client->respcode = 200;
- if (response == RAW) {
- xmlDocDumpFormatMemoryEnc (doc, &buff, &len, NULL, 1);
- html_write(client, "HTTP/1.0 200 OK\r\n"
- "Content-Length: %d\r\n"
+ if (response == RAW)
+ {
+ xmlChar *buff = NULL;
+ int len = 0;
+ unsigned int buf_len;
+ const char *http = "HTTP/1.0 200 OK\r\n"
"Content-Type: text/xml\r\n"
- "\r\n", len);
- html_write(client, "%s", buff);
+ "Content-Length: ";
+ xmlDocDumpFormatMemoryEnc (doc, &buff, &len, NULL, 1);
+ buf_len = strlen (http) + len + 20;
+ client->refbuf = refbuf_new (buf_len);
+ snprintf (client->refbuf->data, buf_len, "%s%d\r\n\r\n%s", http, len, buff);
+ xmlFree(buff);
+ fserve_add_client (client, NULL);
}
- if (response == TRANSFORMED) {
- config = config_get_config();
- adminwebroot = config->adminroot_dir;
- fullpath_xslt_template_len = strlen(adminwebroot) +
+ if (response == TRANSFORMED)
+ {
+ char *fullpath_xslt_template;
+ int fullpath_xslt_template_len;
+ ice_config_t *config = config_get_config();
+
+ fullpath_xslt_template_len = strlen (config->adminroot_dir) +
strlen(xslt_template) + 2;
fullpath_xslt_template = malloc(fullpath_xslt_template_len);
snprintf(fullpath_xslt_template, fullpath_xslt_template_len, "%s%s%s",
- adminwebroot, PATH_SEPARATOR, xslt_template);
+ config->adminroot_dir, PATH_SEPARATOR, xslt_template);
config_release_config();
- html_write(client, "HTTP/1.0 200 OK\r\n"
- "Content-Type: text/html\r\n"
- "\r\n");
+
DEBUG1("Sending XSLT (%s)", fullpath_xslt_template);
xslt_transform(doc, fullpath_xslt_template, client);
free(fullpath_xslt_template);
}
- if (buff) {
- xmlFree(buff);
- }
}
void admin_handle_request(client_t *client, char *uri)
{
@@ -588,17 +585,7 @@
client_destroy(client);
}
-static void html_write(client_t *client, char *fmt, ...)
-{
- int bytes;
- va_list ap;
- va_start(ap, fmt);
- bytes = sock_write_fmt(client->con->sock, fmt, ap);
- va_end(ap);
- if(bytes > 0) client->con->sent_bytes = bytes;
-}
-
static void command_move_clients(client_t *client, source_t *source,
int response)
{
@@ -617,7 +604,6 @@
admin_send_response(doc, client, response,
MOVECLIENTS_TRANSFORMED_REQUEST);
xmlFreeDoc(doc);
- client_destroy(client);
return;
}
@@ -641,7 +627,7 @@
return;
}
- DEBUG2("source is \"%s\", destination is \"%s\"", source->mount, dest->mount);
+ INFO2 ("source is \"%s\", destination is \"%s\"", source->mount, dest->mount);
doc = xmlNewDoc("1.0");
node = xmlNewDocNode(doc, NULL, "iceresponse", NULL);
@@ -658,7 +644,6 @@
admin_send_response(doc, client, response,
ADMIN_XSL_RESPONSE);
xmlFreeDoc(doc);
- client_destroy(client);
}
static int admin_function (const char *function, char *buf, unsigned int len)
@@ -705,7 +690,6 @@
admin_send_response(doc, client, response,
ADMIN_XSL_RESPONSE);
xmlFreeDoc(doc);
- client_destroy(client);
}
@@ -753,7 +737,6 @@
thread_mutex_unlock (&(config_locks()->relay_lock));
admin_send_response (doc, client, response, MANAGE_RELAY_TRANSFORMED_REQUEST);
xmlFreeDoc (doc);
- client_destroy (client);
return;
}
@@ -784,7 +767,6 @@
xmlNewChild(node, NULL, "return", "1");
admin_send_response(doc, client, response, ADMIN_XSL_RESPONSE);
xmlFreeDoc(doc);
- client_destroy(client);
}
@@ -841,7 +823,6 @@
admin_send_response(doc, client, response,
LISTCLIENTS_TRANSFORMED_REQUEST);
xmlFreeDoc(doc);
- client_destroy(client);
}
static void command_buildm3u(client_t *client, source_t *source,
@@ -950,7 +931,6 @@
free(message);
}
xmlFreeDoc(doc);
- client_destroy(client);
}
static void command_kill_source(client_t *client, source_t *source,
@@ -970,7 +950,6 @@
admin_send_response(doc, client, response,
ADMIN_XSL_RESPONSE);
xmlFreeDoc(doc);
- client_destroy(client);
}
static void command_kill_client(client_t *client, source_t *source,
@@ -1017,7 +996,6 @@
admin_send_response(doc, client, response,
ADMIN_XSL_RESPONSE);
xmlFreeDoc(doc);
- client_destroy(client);
}
static void command_fallback(client_t *client, source_t *source,
@@ -1066,7 +1044,6 @@
admin_send_response(doc, client, response,
ADMIN_XSL_RESPONSE);
xmlFreeDoc(doc);
- client_destroy(client);
return;
}
@@ -1103,7 +1080,6 @@
admin_send_response(doc, client, response,
ADMIN_XSL_RESPONSE);
xmlFreeDoc(doc);
- client_destroy(client);
return;
}
@@ -1112,7 +1088,6 @@
admin_send_response(doc, client, response,
ADMIN_XSL_RESPONSE);
xmlFreeDoc(doc);
- client_destroy(client);
}
static void command_shoutcast_metadata(client_t *client, source_t *source)
@@ -1156,7 +1131,6 @@
stats_get_xml(&doc, 1);
admin_send_response(doc, client, response, STATS_TRANSFORMED_REQUEST);
xmlFreeDoc(doc);
- client_destroy(client);
return;
}
@@ -1216,7 +1190,6 @@
LISTMOUNTS_TRANSFORMED_REQUEST);
xmlFreeDoc(doc);
}
- client_destroy(client);
return;
}
@@ -1236,6 +1209,5 @@
admin_send_response(doc, client, response,
UPDATEMETADATA_TRANSFORMED_REQUEST);
xmlFreeDoc(doc);
- client_destroy(client);
}
Modified: icecast/branches/kh/icecast/src/connection.c
===================================================================
--- icecast/branches/kh/icecast/src/connection.c 2005-06-13 13:54:22 UTC (rev 9444)
+++ icecast/branches/kh/icecast/src/connection.c 2005-06-13 16:43:44 UTC (rev 9445)
@@ -752,7 +752,6 @@
static void _handle_get_request (client_t *client, char *passed_uri)
{
int fileserve;
- char *host = NULL;
int port;
int i;
char *serverhost = NULL;
@@ -764,8 +763,6 @@
DEBUG1("start with %s", passed_uri);
config = config_get_config();
fileserve = config->fileserve;
- if (config->hostname)
- host = strdup (config->hostname);
port = config->port;
for(i = 0; i < global.server_sockets; i++) {
if(global.serversock[i] == client->con->serversock) {
@@ -804,10 +801,8 @@
(strncmp(uri, "/admin/", 7) == 0)) {
admin_handle_request(client, uri);
if (uri != passed_uri) free (uri);
- free (host);
return;
}
- free (host);
add_client (uri, client);
Modified: icecast/branches/kh/icecast/src/fserve.c
===================================================================
--- icecast/branches/kh/icecast/src/fserve.c 2005-06-13 13:54:22 UTC (rev 9444)
+++ icecast/branches/kh/icecast/src/fserve.c 2005-06-13 16:43:44 UTC (rev 9445)
@@ -34,6 +34,8 @@
#else
#include <winsock2.h>
#include <windows.h>
+#define snprintf _snprintf
+#define S_ISREG (mode) ((mode) & _S_IFREG)
#endif
#include "thread/thread.h"
@@ -67,6 +69,7 @@
static fserve_t *active_list = NULL;
volatile static fserve_t *pending_list = NULL;
+
static mutex_t pending_lock;
static avl_tree *mimetypes = NULL;
@@ -94,14 +97,6 @@
void fserve_initialize(void)
{
- ice_config_t *config = config_get_config();
- int serve = config->fileserve;
-
- config_release_config();
-
- if(!serve)
- return;
-
create_mime_mappings(MIMETYPESFILE);
thread_mutex_create ("fserve pending", &pending_lock);
@@ -231,7 +226,7 @@
pending_list = NULL;
thread_mutex_unlock (&pending_lock);
}
- /* drop out of here is someone is ready */
+ /* drop out of here if someone is ready */
if (fserve_client_waiting())
break;
}
@@ -252,7 +247,7 @@
while (fclient)
{
- /* can we process this client */
+ /* process this client, if it is ready */
if (fclient->ready)
{
client_t *client = fclient->client;
@@ -261,7 +256,10 @@
if (client->pos == refbuf->len)
{
/* Grab a new chunk */
- bytes = fread (refbuf->data, 1, BUFSIZE, fclient->file);
+ if (fclient->file)
+ bytes = fread (refbuf->data, 1, BUFSIZE, fclient->file);
+ else
+ bytes = 0;
if (bytes == 0)
{
fserve_t *to_go = fclient;
@@ -369,20 +367,19 @@
}
-int fserve_client_create(client_t *httpclient, const char *path)
+int fserve_client_create (client_t *httpclient, const char *path)
{
- fserve_t *client;
- int bytes;
struct stat file_buf;
char *range = NULL;
int64_t new_content_len = 0;
- int64_t rangenumber = 0;
+ int64_t rangenumber = 0, content_length;
int ret = 0;
char *fullpath;
int m3u_requested = 0, m3u_file_available = 1;
+ FILE *file;
fullpath = util_get_path_from_normalised_uri (path);
- INFO2 ("handle file %s (%s)", path, fullpath);
+ INFO2 ("checking for file %s (%s)", path, fullpath);
if (strcmp (util_get_extension (fullpath), "m3u") == 0)
m3u_requested = 1;
@@ -406,7 +403,7 @@
char *host = httpp_getvar (httpclient->parser, "host");
char *sourceuri = strdup (path);
char *dot = strrchr(sourceuri, '.');
- int port = 8002;
+ int port = 8000;
*dot = 0;
DEBUG1 ("host passed is %s", host);
httpclient->respcode = 200;
@@ -445,51 +442,53 @@
{
/* If the file exists, then transform it, otherwise, write a 404 */
DEBUG0("Stats request, sending XSL transformed stats");
- httpclient->respcode = 200;
- 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);
free (fullpath);
return 0;
}
- if (S_ISREG (file_buf.st_mode) == 0)
+
+ /* on demand file serving check */
+ ice_config_t *config = config_get_config();
+ if (config->fileserve == 0)
{
+ DEBUG1 ("on demand file \"%s\" refused", fullpath);
client_send_404 (httpclient, "The file you requested could not be found");
- WARN1 ("found requested file but there is no handler for it: %s", fullpath);
+ config_release_config();
free (fullpath);
return 0;
}
+ config_release_config();
- client = calloc (1, sizeof(fserve_t));
- if (client == NULL)
+ if (S_ISREG (file_buf.st_mode) == 0)
{
+ client_send_404 (httpclient, "The file you requested could not be found");
+ WARN1 ("found requested file but there is no handler for it: %s", fullpath);
free (fullpath);
- client_send_404 (httpclient, "memory exhausted");
return 0;
}
- client->file = fopen (fullpath, "rb");
+
+ file = fopen (fullpath, "rb");
free (fullpath);
- if (client->file == NULL)
+ if (file == NULL)
{
+ WARN1 ("Problem accessing file \"%s\"", fullpath);
client_send_404 (httpclient, "File not readable");
return 0;
}
- client->client = httpclient;
- client->ready = 0;
client_set_queue (httpclient, NULL);
httpclient->refbuf = refbuf_new (BUFSIZE);
- client->content_length = (int64_t)file_buf.st_size;
+ content_length = (int64_t)file_buf.st_size;
+ range = httpp_getvar (httpclient->parser, "range");
- range = httpp_getvar (client->client->parser, "range");
-
do
{
+ int bytes;
+
if (range)
{
ret = sscanf(range, "bytes=" FORMAT_INT64 "-", &rangenumber);
- if (ret == 1 && rangenumber>=0 && rangenumber < client->content_length)
+ if (ret == 1 && rangenumber>=0 && rangenumber < content_length)
{
/* Date: is required on all HTTP1.1 responses */
char currenttime[50];
@@ -498,11 +497,11 @@
struct tm result;
int64_t endpos;
- ret = fseek(client->file, rangenumber, SEEK_SET);
+ ret = fseek (file, rangenumber, SEEK_SET);
if (ret == -1)
break;
- new_content_len = client->content_length - rangenumber;
+ new_content_len = content_length - rangenumber;
endpos = rangenumber + new_content_len - 1;
if (endpos < 0)
endpos = 0;
@@ -522,7 +521,7 @@
new_content_len,
rangenumber,
endpos,
- client->content_length,
+ content_length,
fserve_content_type(path));
}
else
@@ -534,19 +533,13 @@
"HTTP/1.0 200 OK\r\n"
"Content-Length: " FORMAT_INT64 "\r\n"
"Content-Type: %s\r\n\r\n",
- client->content_length,
+ 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);
-
- thread_mutex_lock (&pending_lock);
- client->next = (fserve_t *)pending_list;
- pending_list = client;
- thread_mutex_unlock (&pending_lock);
-
+ fserve_add_client (httpclient, file);
return 0;
} while (0);
/* If we run into any issues with the ranges
@@ -554,11 +547,37 @@
httpclient->respcode = 416;
sock_write (httpclient->con->sock,
"HTTP/1.0 416 Request Range Not Satisfiable\r\n\r\n");
- fserve_client_destroy (client);
return 0;
}
+/* Add client */
+int fserve_add_client (client_t *client, FILE *file)
+{
+ fserve_t *fclient = calloc (1, sizeof(fserve_t));
+
+ DEBUG0 ("Adding client to file serving engine");
+ if (fclient == NULL)
+ {
+ client_send_404 (client, "memory exhausted");
+ return -1;
+ }
+ fclient->file = file;
+ fclient->client = client;
+ fclient->ready = 0;
+
+ sock_set_blocking (client->con->sock, SOCK_NONBLOCK);
+ sock_set_nodelay (client->con->sock);
+
+ thread_mutex_lock (&pending_lock);
+ fclient->next = (fserve_t *)pending_list;
+ pending_list = fclient;
+ thread_mutex_unlock (&pending_lock);
+
+ return 0;
+}
+
+
static int _delete_mapping(void *mapping) {
mime_type *map = mapping;
free(map->ext);
Modified: icecast/branches/kh/icecast/src/fserve.h
===================================================================
--- icecast/branches/kh/icecast/src/fserve.h 2005-06-13 13:54:22 UTC (rev 9444)
+++ icecast/branches/kh/icecast/src/fserve.h 2005-06-13 16:43:44 UTC (rev 9445)
@@ -14,14 +14,12 @@
#define __FSERVE_H__
#include <stdio.h>
-#include "compat.h"
typedef struct _fserve_t
{
client_t *client;
FILE *file;
- int64_t content_length;
int ready;
struct _fserve_t *next;
} fserve_t;
@@ -29,6 +27,7 @@
void fserve_initialize(void);
void fserve_shutdown(void);
int fserve_client_create(client_t *httpclient, const char *path);
+int fserve_add_client (client_t *client, FILE *file);
const char *fserve_content_type (const char *path);
Modified: icecast/branches/kh/icecast/src/slave.c
===================================================================
--- icecast/branches/kh/icecast/src/slave.c 2005-06-13 13:54:22 UTC (rev 9444)
+++ icecast/branches/kh/icecast/src/slave.c 2005-06-13 16:43:44 UTC (rev 9445)
@@ -332,6 +332,7 @@
{
source_t *fallback_source;
+ DEBUG1 ("failed relay, fallback to %s", relay->source->fallback_mount);
avl_tree_rlock(global.source_tree);
fallback_source = source_find_mount (relay->source->fallback_mount);
Modified: icecast/branches/kh/icecast/src/xslt.c
===================================================================
--- icecast/branches/kh/icecast/src/xslt.c 2005-06-13 13:54:22 UTC (rev 9444)
+++ icecast/branches/kh/icecast/src/xslt.c 2005-06-13 16:43:44 UTC (rev 9445)
@@ -46,6 +46,7 @@
#include "refbuf.h"
#include "client.h"
#include "stats.h"
+#include "fserve.h"
#define CATMODULE "xslt"
@@ -175,7 +176,13 @@
thread_mutex_unlock(&xsltlock);
if (string)
{
- client_send_bytes (client, string, len);
+ const char *http = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nContent-Length: ";
+ unsigned buf_len = len + strlen (http) + 20;
+
+ client->respcode = 200;
+ client->refbuf = refbuf_new (buf_len);
+ snprintf (client->refbuf->data, buf_len, "%s%d\r\n\r\n%s", http, len, string);
+ fserve_add_client (client, NULL);
xmlFree (string);
}
xmlFreeDoc(res);
More information about the commits
mailing list