Send ShoutCast icy name in one write. Refactor icy headers send. Fixes #76, #78

This commit is contained in:
alban.peignier@gmail.com 2013-04-04 04:56:31 +00:00
parent 5dd930ab82
commit be34bc4a37
1 changed files with 27 additions and 39 deletions

View File

@ -76,7 +76,7 @@ static const char fileid[] = "$Id$";
* Size of string conversion buffer * Size of string conversion buffer
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
#define STRBUF_SIZE 32 #define STRBUF_SIZE 32
#define HEADERLINE_LENGTH 50
/* =============================================== local function prototypes */ /* =============================================== local function prototypes */
@ -134,7 +134,7 @@ ShoutCast :: sendLogin ( void ) throw ( Exception )
unsigned int len; unsigned int len;
bool needsMountPoint = false; bool needsMountPoint = false;
const char * mountPoint = getMountPoint(); const char * mountPoint = getMountPoint();
char header_line[HEADERLINE_LENGTH+2]; // ... + \n + \0
if ( !source->isOpen() ) { if ( !source->isOpen() ) {
return false; return false;
@ -200,62 +200,50 @@ ShoutCast :: sendLogin ( void ) throw ( Exception )
/* send the icy headers */ /* send the icy headers */
if ( getName() ) { if ( getName() ) {
str = "icy-name:"; snprintf(header_line, HEADERLINE_LENGTH, "icy-name:%s", getName());
sink->write( str, strlen( str)); strcat(header_line, "\n");
str = getName(); sink->write( header_line, strlen( header_line));
sink->write( str, strlen( str));
} }
if ( getUrl() ) { if ( getUrl() ) {
str = "\nicy-url:"; snprintf(header_line, HEADERLINE_LENGTH, "icy-url:%s", getUrl());
sink->write( str, strlen( str)); strcat(header_line, "\n");
str = getUrl(); sink->write( header_line, strlen( header_line));
sink->write( str, strlen( str));
} }
if ( getGenre() ) { if ( getGenre() ) {
str = "\nicy-genre:"; snprintf(header_line, HEADERLINE_LENGTH, "icy-genre:%s", getGenre());
sink->write( str, strlen( str)); strcat(header_line, "\n");
str = getGenre(); sink->write( header_line, strlen( header_line));
sink->write( str, strlen( str));
} }
if ( getIrc() ) { if ( getIrc() ) {
str = "\nicy-irc:"; snprintf(header_line, HEADERLINE_LENGTH, "icy-irc:%s", getIrc());
sink->write( str, strlen( str)); strcat(header_line, "\n");
str = getIrc(); sink->write( header_line, strlen( header_line));
sink->write( str, strlen( str));
} }
if ( getAim() ) { if ( getAim() ) {
str = "\nicy-aim:"; snprintf(header_line, HEADERLINE_LENGTH, "icy-aim:%s", getAim());
sink->write( str, strlen( str)); strcat(header_line, "\n");
str = getAim(); sink->write( header_line, strlen( header_line));
sink->write( str, strlen( str));
} }
if ( getIcq() ) { if ( getIcq() ) {
str = "\nicy-icq:"; snprintf(header_line, HEADERLINE_LENGTH, "icy-icq:%s", getIcq());
sink->write( str, strlen( str)); strcat(header_line, "\n");
str = getIcq(); sink->write( header_line, strlen( header_line));
sink->write( str, strlen( str));
} }
str = "\nicy-br:"; snprintf(header_line, HEADERLINE_LENGTH, "icy-br:%d", getBitRate());
sink->write( str, strlen( str)); strcat(header_line, "\n");
if ( log10(getBitRate()) >= (STRBUF_SIZE-2) ) { sink->write( header_line, strlen( header_line));
throw Exception( __FILE__, __LINE__,
"bitrate does not fit string buffer", getBitRate());
}
sprintf( resp, "%d", getBitRate());
sink->write( resp, strlen( resp));
str = "\nicy-pub:"; snprintf(header_line, HEADERLINE_LENGTH, "icy-pub:%s", getIsPublic() ? "1" : "0");
sink->write( str, strlen( str)); strcat(header_line, "\n");
str = getIsPublic() ? "1" : "0"; sink->write( header_line, strlen( header_line));
sink->write( str, strlen( str));
str = "\n\n"; str = "\n";
sink->write( str, strlen( str)); sink->write( str, strlen( str));
sink->flush(); sink->flush();