diff --git a/src/avl/avl.h b/src/avl/avl.h index 71ab7a9b..af224a7e 100644 --- a/src/avl/avl.h +++ b/src/avl/avl.h @@ -2,7 +2,7 @@ * Copyright (C) 1995 by Sam Rushing */ -/* $Id: avl.h,v 1.1 2001/09/10 02:28:03 jack Exp $ */ +/* $Id: avl.h,v 1.2 2002/02/11 09:11:18 msmith Exp $ */ #ifndef __AVL_H #define __AVL_H @@ -11,6 +11,8 @@ extern "C" { #endif +#include "thread.h" + typedef struct avl_node_tag { void * key; struct avl_node_tag * left; diff --git a/src/connection.c b/src/connection.c index 5292f790..1b2a1ba8 100644 --- a/src/connection.c +++ b/src/connection.c @@ -336,6 +336,8 @@ static void *_handle_connection(void *arg) } if (parser->req_type == httpp_req_source) { + char *contenttype; + printf("DEBUG: source logging in\n"); stats_event_inc(NULL, "source_connections"); @@ -379,7 +381,22 @@ static void *_handle_connection(void *arg) stats_event_inc(NULL, "sources"); - source = source_create(con, parser, httpp_getvar(parser, HTTPP_VAR_URI), FORMAT_TYPE_VORBIS); + contenttype = httpp_getvar(parser, "content-type"); + + if (contenttype != NULL) { + format_type_t format = format_get_type(contenttype); + if(format < 0) { + WARN1("Content-type \"%s\" not supported, dropping source", contenttype); + continue; + } + else + source = source_create(con, parser, httpp_getvar(parser, HTTPP_VAR_URI), format); + } + else { + WARN0("No content-type header, cannot handle source"); + continue; + } + source->shutdown_rwlock = &_source_shutdown_rwlock; sock_set_blocking(con->sock, SOCK_NONBLOCK); diff --git a/src/format.c b/src/format.c index 9ffc044e..4088bb98 100644 --- a/src/format.c +++ b/src/format.c @@ -15,6 +15,16 @@ #include "format_vorbis.h" +format_type_t format_get_type(char *contenttype) +{ + if(strcmp(contenttype, "application/x-ogg") == 0) + return FORMAT_TYPE_VORBIS; + else if(strcmp(contenttype, "audio/mpeg") == 0) + return FORMAT_TYPE_MP3; + else + return -1; +} + format_plugin_t *format_get_plugin(format_type_t type, char *mount) { format_plugin_t *plugin; diff --git a/src/format.h b/src/format.h index d7963d63..f8a414eb 100644 --- a/src/format.h +++ b/src/format.h @@ -32,6 +32,7 @@ typedef struct _format_plugin_tag void *_state; } format_plugin_t; +format_type_t format_get_type(char *contenttype); format_plugin_t *format_get_plugin(format_type_t type, char *mount); #endif /* __FORMAT_H__ */ diff --git a/src/format_vorbis.c b/src/format_vorbis.c index 7e27b236..94bcfd0f 100644 --- a/src/format_vorbis.c +++ b/src/format_vorbis.c @@ -13,6 +13,7 @@ #include "refbuf.h" +#include "stats.h" #include "format.h" typedef struct _vstate_tag @@ -122,7 +123,11 @@ refbuf_t *format_vorbis_get_buffer(format_plugin_t *self, char *data, unsigned l } if (state->header >= 0) { - if (ogg_page_granulepos(&state->og) == 0) { + /* FIXME: In some streams (non-vorbis ogg streams), this could get + * extras pages beyond the header. We need to collect the pages + * here anyway, but they may have to be discarded later. + */ + if (ogg_page_granulepos(&state->og) <= 0) { state->header++; } else { /* we're done caching headers */ diff --git a/src/httpp/httpp.c b/src/httpp/httpp.c index 16db57e5..01f97624 100644 --- a/src/httpp/httpp.c +++ b/src/httpp/httpp.c @@ -62,10 +62,11 @@ int httpp_parse(http_parser_t *parser, char *http_data, unsigned long len) if (http_data == NULL) return 0; - /* make a local copy of the data */ - data = (char *)malloc(len); + /* make a local copy of the data, including 0 terminator */ + data = (char *)malloc(len+1); if (data == NULL) return 0; memcpy(data, http_data, len); + data[len] = 0; /* first we count how many lines there are ** and set up the line[] array @@ -77,14 +78,12 @@ int httpp_parse(http_parser_t *parser, char *http_data, unsigned long len) data[i] = '\0'; if (data[i] == '\n') { lines++; - if (i + 1 < len) - if (data[i + 1] == '\n' || data[i + 1] == '\r') { - data[i] = '\0'; - break; - } data[i] = '\0'; - if (i < len - 1) + if (i + 1 < len) { + if (data[i + 1] == '\n' || data[i + 1] == '\r') + break; line[lines] = &data[i + 1]; + } } } diff --git a/src/source.c b/src/source.c index 21ddba20..a231eec4 100644 --- a/src/source.c +++ b/src/source.c @@ -178,11 +178,11 @@ void *source_main(void *arg) /* we have a refbuf buffer, which a data block to be sent to ** all clients. if a client is not able to send the buffer - ** immediately, it should store it on it's queue for the next + ** immediately, it should store it on its queue for the next ** go around. ** ** instead of sending the current block, a client should send - ** all data in the cue, plus the current block, until either + ** all data in the queue, plus the current block, until either ** it runs out of data, or it hits a recoverable error like ** EAGAIN. this will allow a client that got slightly lagged ** to catch back up if it can diff --git a/src/stats.h b/src/stats.h index e656c9b9..2cffa71e 100644 --- a/src/stats.h +++ b/src/stats.h @@ -1,6 +1,10 @@ #ifndef __STATS_H__ #define __STATS_H__ +#include "connection.h" +#include "httpp.h" +#include "client.h" + typedef struct _stats_connection_tag { connection_t *con;