[xiph-cvs] cvs commit: icecast/src client.c client.h connection.c source.c source.h util.c
Michael Smith
msmith at xiph.org
Sun Mar 2 02:13:59 PST 2003
msmith 03/03/02 05:13:59
Modified: src client.c client.h connection.c source.c source.h
util.c
Log:
More features:
-- per mountpoint listener maxima
-- static configuration of mountpoint fallbacks
-- stream dumping (write incoming stream to disk)
Fixed some warnings that other people introduced.
Revision Changes Path
1.7 +11 -0 icecast/src/client.c
Index: client.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/client.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- client.c 14 Feb 2003 11:44:08 -0000 1.6
+++ client.c 2 Mar 2003 10:13:59 -0000 1.7
@@ -69,6 +69,17 @@
client_destroy(client);
}
+void client_send_504(client_t *client, char *message) {
+ int bytes;
+ client->respcode = 504;
+ bytes = sock_write(client->con->sock,
+ "HTTP/1.0 504 Server Full\r\n"
+ "Content-Type: text/html\r\n\r\n"
+ "<b>%s</b>\r\n", message);
+ if (bytes > 0) client->con->sent_bytes = bytes;
+ client_destroy(client);
+}
+
void client_send_401(client_t *client) {
int bytes = sock_write(client->con->sock,
"HTTP/1.0 401 Authentication Required\r\n"
<p><p>1.7 +1 -0 icecast/src/client.h
Index: client.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/client.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- client.h 31 Dec 2002 06:28:38 -0000 1.6
+++ client.h 2 Mar 2003 10:13:59 -0000 1.7
@@ -29,6 +29,7 @@
client_t *client_create(connection_t *con, http_parser_t *parser);
void client_destroy(client_t *client);
+void client_send_504(client_t *client, char *message);
void client_send_404(client_t *client, char *message);
void client_send_401(client_t *client);
void client_send_400(client_t *client, char *message);
<p><p>1.55 +27 -16 icecast/src/connection.c
Index: connection.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/connection.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- connection.c 24 Feb 2003 13:37:15 -0000 1.54
+++ connection.c 2 Mar 2003 10:13:59 -0000 1.55
@@ -296,6 +296,7 @@
int connection_create_source(client_t *client, connection_t *con, http_parser_t *parser, char *mount) {
source_t *source;
char *contenttype;
+ mount_proxy *mountproxy, *mountinfo = NULL;
/* check to make sure this source wouldn't
** be over the limit
@@ -310,6 +311,15 @@
global_unlock();
stats_event_inc(NULL, "sources");
+
+ mountproxy = config_get_config()->mounts;
+ while(mountproxy) {
+ if(!strcmp(mountproxy->mountname, mount)) {
+ mountinfo = mountproxy;
+ break;
+ }
+ mountproxy = mountproxy->next;
+ }
contenttype = httpp_getvar(parser, "content-type");
@@ -319,12 +329,13 @@
WARN1("Content-type \"%s\" not supported, dropping source", contenttype);
goto fail;
} else {
- source = source_create(client, con, parser, mount, format);
+ source = source_create(client, con, parser, mount,
+ format, mountinfo);
}
} else {
format_type_t format = FORMAT_TYPE_MP3;
ERROR0("No content-type header, falling back to backwards compatibility mode for icecast 1.x relays. Assuming content is mp3.");
- source = source_create(client, con, parser, mount, format);
+ source = source_create(client, con, parser, mount, format, mountinfo);
}
source->send_return = 1;
@@ -762,13 +773,8 @@
global_lock();
if (global.clients >= config_get_config()->client_limit) {
- client->respcode = 504;
- bytes = sock_write(client->con->sock,
- "HTTP/1.0 504 Server Full\r\n"
- "Content-Type: text/html\r\n\r\n"
- "<b>The server is already full. Try again later.</b>\r\n");
- if (bytes > 0) client->con->sent_bytes = bytes;
- client_destroy(client);
+ client_send_504(client,
+ "The server is already full. Try again later.");
global_unlock();
return;
}
@@ -781,18 +787,23 @@
global_lock();
if (global.clients >= config_get_config()->client_limit) {
- client->respcode = 504;
- bytes = sock_write(client->con->sock,
- "HTTP/1.0 504 Server Full\r\n"
- "Content-Type: text/html\r\n\r\n"
- "<b>The server is already full. Try again later.</b>\r\n");
- if (bytes > 0) client->con->sent_bytes = bytes;
- client_destroy(client);
+ client_send_504(client,
+ "The server is already full. Try again later.");
global_unlock();
avl_tree_unlock(global.source_tree);
return;
}
+ else if(source->max_listeners != -1 &&
+ source->listeners >= source->max_listeners)
+ {
+ client_send_504(client,
+ "Too many clients on this mountpoint. Try again later.");
+ global_unlock();
+ avl_tree_unlock(global.source_tree);
+ return;
+ }
global.clients++;
+ source->listeners++;
global_unlock();
client->format_data = source->format->create_client_data(
<p><p>1.39 +34 -2 icecast/src/source.c
Index: source.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/source.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- source.c 27 Feb 2003 03:01:12 -0000 1.38
+++ source.c 2 Mar 2003 10:13:59 -0000 1.39
@@ -3,6 +3,7 @@
#include <string.h>
#include <sys/types.h>
#include <ogg/ogg.h>
+#include <errno.h>
#ifndef _WIN32
#include <unistd.h>
@@ -55,7 +56,8 @@
void *info, int type);
source_t *source_create(client_t *client, connection_t *con,
- http_parser_t *parser, const char *mount, format_type_t type)
+ http_parser_t *parser, const char *mount, format_type_t type,
+ mount_proxy *mountinfo)
{
int i = 0;
source_t *src;
@@ -73,6 +75,8 @@
src->num_yp_directories = 0;
src->listeners = 0;
src->send_return = 0;
+ src->dumpfilename = NULL;
+ src->dumpfile = NULL;
src->audio_info = util_dict_new();
for (i=0;i<config_get_config()->num_yp_directories;i++) {
if (config_get_config()->yp_url[i]) {
@@ -86,6 +90,20 @@
}
}
+ if(mountinfo != NULL) {
+ src->fallback_mount = mountinfo->fallback_mount;
+ src->max_listeners = mountinfo->max_listeners;
+ src->dumpfilename = mountinfo->dumpfile;
+ }
+
+ if(src->dumpfilename != NULL) {
+ src->dumpfile = fopen(src->dumpfilename, "ab");
+ if(src->dumpfile == NULL) {
+ WARN2("Cannot open dump file \"%s\" for appending: %s, disabling.",
+ src->dumpfilename, strerror(errno));
+ }
+ }
+
return src;
}
@@ -170,7 +188,6 @@
int listeners = 0;
int i=0;
int suppress_yp = 0;
- util_dict *audio_info;
char *ai;
long queue_limit = config_get_config()->queue_size_limit;
@@ -378,6 +395,18 @@
** to catch back up if it can
*/
+ /* First, stream dumping, if enabled */
+ if(source->dumpfile) {
+ if(fwrite(refbuf->data, 1, refbuf->len, source->dumpfile) !=
+ refbuf->len)
+ {
+ WARN1("Write to dump file failed, disabling: %s",
+ strerror(errno));
+ fclose(source->dumpfile);
+ source->dumpfile = NULL;
+ }
+ }
+
/* acquire read lock on client_tree */
avl_tree_rlock(source->client_tree);
@@ -585,6 +614,9 @@
avl_tree_wlock(global.source_tree);
avl_delete(global.source_tree, source, source_free_source);
avl_tree_unlock(global.source_tree);
+
+ if(source->dumpfile)
+ fclose(source->dumpfile);
thread_exit(0);
<p><p>1.10 +9 -1 icecast/src/source.h
Index: source.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/source.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- source.h 26 Feb 2003 23:52:23 -0000 1.9
+++ source.h 2 Mar 2003 10:13:59 -0000 1.10
@@ -6,6 +6,8 @@
#include "util.h"
#include "format.h"
+#include <stdio.h>
+
typedef struct source_tag
{
client_t *client;
@@ -29,13 +31,19 @@
rwlock_t *shutdown_rwlock;
ypdata_t *ypdata[MAX_YP_DIRECTORIES];
util_dict *audio_info;
+
+ char *dumpfilename; /* Name of a file to dump incoming stream to */
+ FILE *dumpfile;
+
int num_yp_directories;
long listeners;
long max_listeners;
int send_return;
} source_t;
-source_t *source_create(client_t *client, connection_t *con, http_parser_t *parser, const char *mount, format_type_t type);
+source_t *source_create(client_t *client, connection_t *con,
+ http_parser_t *parser, const char *mount, format_type_t type,
+ mount_proxy *mountinfo);
source_t *source_find_mount(const char *mount);
int source_compare_sources(void *arg, void *a, void *b);
int source_free_source(void *key);
<p><p>1.18 +2 -0 icecast/src/util.c
Index: util.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/util.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- util.c 26 Feb 2003 23:52:23 -0000 1.17
+++ util.c 2 Mar 2003 10:13:59 -0000 1.18
@@ -414,6 +414,7 @@
return dict->val;
dict = dict->next;
}
+ return NULL;
}
int util_dict_set(util_dict *dict, const char *key, const char *val)
@@ -521,3 +522,4 @@
return res;
}
+
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list