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 "IceCast.h"
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 static const char fileid[] = "$Id: IceCast.cpp,v 1.10 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 IceCast :: init ( const char * mountPoint,
00089 const char * description,
00090 const char * remoteDumpFile )
00091 throw ( Exception )
00092 {
00093 this->mountPoint = Util::strDup( mountPoint);
00094 this->description = description ? Util::strDup( description) : 0;
00095 this->remoteDumpFile = remoteDumpFile ? Util::strDup( remoteDumpFile) : 0;
00096 }
00097
00098
00099
00100
00101
00102 void
00103 IceCast :: strip ( void ) throw ( Exception )
00104 {
00105 delete[] mountPoint;
00106 if ( description ) {
00107 delete[] description;
00108 }
00109 if ( remoteDumpFile ) {
00110 delete[] remoteDumpFile;
00111 }
00112 }
00113
00114
00115
00116
00117
00118 bool
00119 IceCast :: sendLogin ( void ) throw ( Exception )
00120 {
00121 Sink * sink = getSink();
00122 Source * source = getSocket();
00123 const char * str;
00124 char resp[STRBUF_SIZE];
00125 unsigned int len;
00126
00127 if ( !source->isOpen() ) {
00128 return false;
00129 }
00130 if ( !sink->isOpen() ) {
00131 return false;
00132 }
00133
00134
00135
00136 str = "SOURCE ";
00137 sink->write( str, strlen( str));
00138 str = getPassword();
00139 sink->write( str, strlen( str));
00140 str = " /";
00141 sink->write( str, strlen( str));
00142 str = getMountPoint();
00143 sink->write( str, strlen( str));
00144
00145
00146 str = "\nx-audiocast-bitrate: ";
00147 sink->write( str, strlen( str));
00148 if ( log10(getBitRate()) >= (STRBUF_SIZE-2) ) {
00149 throw Exception( __FILE__, __LINE__,
00150 "bitrate does not fit string buffer", getBitRate());
00151 }
00152 sprintf( resp, "%d", getBitRate());
00153 sink->write( resp, strlen( resp));
00154
00155 str = "\nx-audiocast-public: ";
00156 sink->write( str, strlen( str));
00157 str = getIsPublic() ? "1" : "0";
00158 sink->write( str, strlen( str));
00159
00160 if ( getName() ) {
00161 str = "\nx-audiocast-name: ";
00162 sink->write( str, strlen( str));
00163 str = getName();
00164 sink->write( str, strlen( str));
00165 }
00166
00167 if ( getDescription() ) {
00168 str = "\nx-audiocast-description: ";
00169 sink->write( str, strlen( str));
00170 str = getDescription();
00171 sink->write( str, strlen( str));
00172 }
00173
00174 if ( getUrl() ) {
00175 str = "\nx-audiocast-url: ";
00176 sink->write( str, strlen( str));
00177 str = getUrl();
00178 sink->write( str, strlen( str));
00179 }
00180
00181 if ( getGenre() ) {
00182 str = "\nx-audiocast-genre: ";
00183 sink->write( str, strlen( str));
00184 str = getGenre();
00185 sink->write( str, strlen( str));
00186 }
00187
00188 if ( getRemoteDumpFile() ) {
00189 str = "\nx-audiocast-dumpfile: ";
00190 sink->write( str, strlen( str));
00191 str = getRemoteDumpFile();
00192 sink->write( str, strlen( str));
00193 }
00194
00195 str = "\n\n";
00196 sink->write( str, strlen( str));
00197 sink->flush();
00198
00199
00200 len = source->read( resp, STRBUF_SIZE);
00201 if ( len < 2 || resp[0] != 'O' || resp[1] != 'K' ) {
00202 return false;
00203 }
00204
00205
00206 while ( source->canRead( 0, 0) &&
00207 (len = source->read( resp, STRBUF_SIZE)) ) {
00208 ;
00209 }
00210
00211
00212 return true;
00213 }
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254