00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifdef HAVE_CONFIG_H
00033 #include "config.h"
00034 #endif
00035
00036 #ifdef HAVE_STDIO_H
00037 #include <stdio.h>
00038 #else
00039 #error need stdio.h
00040 #endif
00041
00042 #ifdef HAVE_STRING_H
00043 #include <string.h>
00044 #else
00045 #error need string.h
00046 #endif
00047
00048 #ifdef HAVE_MATH_H
00049 #include <math.h>
00050 #else
00051 #error need math.h
00052 #endif
00053
00054
00055 #include "Exception.h"
00056 #include "Source.h"
00057 #include "Sink.h"
00058 #include "Util.h"
00059 #include "ShoutCast.h"
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 static const char fileid[] = "$Id: ShoutCast.cpp,v 1.3 2002/05/28 12:35:41 darkeye Exp $";
00071
00072
00073
00074
00075
00076 #define STRBUF_SIZE 32
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 void
00088 ShoutCast :: init ( const char * irc,
00089 const char * aim,
00090 const char * icq )
00091 throw ( Exception )
00092 {
00093 this->irc = irc ? Util::strDup( irc) : 0;
00094 this->aim = aim ? Util::strDup( aim) : 0;
00095 this->icq = icq ? Util::strDup( icq) : 0;
00096 }
00097
00098
00099
00100
00101
00102 void
00103 ShoutCast :: strip ( void ) throw ( Exception )
00104 {
00105 if ( irc ) {
00106 delete[] irc;
00107 }
00108 if ( aim ) {
00109 delete[] aim;
00110 }
00111 if ( icq ) {
00112 delete[] icq;
00113 }
00114 }
00115
00116
00117
00118
00119
00120 bool
00121 ShoutCast :: sendLogin ( void ) throw ( Exception )
00122 {
00123 Sink * sink = getSink();
00124 Source * source = getSocket();
00125 const char * str;
00126 char resp[STRBUF_SIZE];
00127 unsigned int len;
00128
00129 if ( !source->isOpen() ) {
00130 return false;
00131 }
00132 if ( !sink->isOpen() ) {
00133 return false;
00134 }
00135
00136
00137 str = getPassword();
00138 sink->write( str, strlen( str));
00139 str = "\n";
00140 sink->write( str, strlen( str));
00141 sink->flush();
00142
00143
00144 if ( getName() ) {
00145 str = "icy-name:";
00146 sink->write( str, strlen( str));
00147 str = getName();
00148 sink->write( str, strlen( str));
00149 }
00150
00151 if ( getUrl() ) {
00152 str = "\nicy-url:";
00153 sink->write( str, strlen( str));
00154 str = getUrl();
00155 sink->write( str, strlen( str));
00156 }
00157
00158 if ( getGenre() ) {
00159 str = "\nicy-genre:";
00160 sink->write( str, strlen( str));
00161 str = getGenre();
00162 sink->write( str, strlen( str));
00163 }
00164
00165 if ( getIrc() ) {
00166 str = "\nicy-irc:";
00167 sink->write( str, strlen( str));
00168 str = getIrc();
00169 sink->write( str, strlen( str));
00170 }
00171
00172 if ( getAim() ) {
00173 str = "\nicy-aim:";
00174 sink->write( str, strlen( str));
00175 str = getAim();
00176 sink->write( str, strlen( str));
00177 }
00178
00179 if ( getIcq() ) {
00180 str = "\nicy-icq:";
00181 sink->write( str, strlen( str));
00182 str = getIcq();
00183 sink->write( str, strlen( str));
00184 }
00185
00186 str = "\nicy-br:";
00187 sink->write( str, strlen( str));
00188 if ( log10(getBitRate()) >= (STRBUF_SIZE-2) ) {
00189 throw Exception( __FILE__, __LINE__,
00190 "bitrate does not fit string buffer", getBitRate());
00191 }
00192 sprintf( resp, "%d", getBitRate());
00193 sink->write( resp, strlen( resp));
00194
00195 str = "\nicy-pub:";
00196 sink->write( str, strlen( str));
00197 str = getIsPublic() ? "1" : "0";
00198 sink->write( str, strlen( str));
00199
00200 str = "\n\n";
00201 sink->write( str, strlen( str));
00202 sink->flush();
00203
00204
00205 len = source->read( resp, STRBUF_SIZE);
00206 if ( len < 2 || resp[0] != 'O' || resp[1] != 'K' ) {
00207 return false;
00208 }
00209
00210
00211 while ( source->canRead( 0, 0) &&
00212 (len = source->read( resp, STRBUF_SIZE)) ) {
00213 ;
00214 }
00215
00216 return true;
00217 }
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238