Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

IceCast.cpp

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 
00003    Copyright (c) 2000 Tyrell Corporation. All rights reserved.
00004 
00005    Tyrell DarkIce
00006 
00007    File     : IceCast.cpp
00008    Version  : $Revision: 1.10 $
00009    Author   : $Author: darkeye $
00010    Location : $Source: /cvsroot/darkice/darkice/src/IceCast.cpp,v $
00011    
00012    Copyright notice:
00013 
00014     This program is free software; you can redistribute it and/or
00015     modify it under the terms of the GNU General Public License  
00016     as published by the Free Software Foundation; either version 2
00017     of the License, or (at your option) any later version.
00018    
00019     This program is distributed in the hope that it will be useful,
00020     but WITHOUT ANY WARRANTY; without even the implied warranty of 
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
00022     GNU General Public License for more details.
00023    
00024     You should have received a copy of the GNU General Public License
00025     along with this program; if not, write to the Free Software
00026     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 
00028 ------------------------------------------------------------------------------*/
00029 
00030 /* ============================================================ include files */
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 /* ===================================================  local data structures */
00063 
00064 
00065 /* ================================================  local constants & macros */
00066 
00067 /*------------------------------------------------------------------------------
00068  *  File identity
00069  *----------------------------------------------------------------------------*/
00070 static const char fileid[] = "$Id: IceCast.cpp,v 1.10 2002/05/28 12:35:41 darkeye Exp $";
00071 
00072 
00073 /*------------------------------------------------------------------------------
00074  *  Size of string conversion buffer
00075  *----------------------------------------------------------------------------*/
00076 #define STRBUF_SIZE         32
00077 
00078 
00079 /* ===============================================  local function prototypes */
00080 
00081 
00082 /* =============================================================  module code */
00083 
00084 /*------------------------------------------------------------------------------
00085  *  Initialize the object
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  *  De-initialize the object
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  *  Log in to the IceCast server
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     /* send the request, a string like:
00135      * "SOURCE <password> /<mountpoint>\n" */
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     /* send the x-audiocast headers */
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     /* read the anticipated response: "OK" */
00200     len = source->read( resp, STRBUF_SIZE);
00201     if ( len < 2 || resp[0] != 'O' || resp[1] != 'K' ) {
00202         return false;
00203     }
00204 
00205     /* suck anything that the other side has to say */
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   $Source: /cvsroot/darkice/darkice/src/IceCast.cpp,v $
00220 
00221   $Log: IceCast.cpp,v $
00222   Revision 1.10  2002/05/28 12:35:41  darkeye
00223   code cleanup: compiles under gcc-c++ 3.1, using -pedantic option
00224 
00225   Revision 1.9  2001/11/20 09:06:18  darkeye
00226   fixed public stream reporting
00227 
00228   Revision 1.8  2001/09/14 19:31:06  darkeye
00229   added IceCast2 / vorbis support
00230 
00231   Revision 1.7  2001/09/09 11:27:31  darkeye
00232   added support for ShoutCast servers
00233 
00234   Revision 1.6  2001/08/30 17:25:56  darkeye
00235   renamed configure.h to config.h
00236 
00237   Revision 1.5  2001/08/29 21:08:30  darkeye
00238   made some description options in the darkice config file optional
00239 
00240   Revision 1.4  2000/11/12 14:54:50  darkeye
00241   added kdoc-style documentation comments
00242 
00243   Revision 1.3  2000/11/10 20:14:11  darkeye
00244   added support for remote dump file
00245 
00246   Revision 1.2  2000/11/05 14:08:28  darkeye
00247   changed builting to an automake / autoconf environment
00248 
00249   Revision 1.1.1.1  2000/11/05 10:05:52  darkeye
00250   initial version
00251 
00252   
00253 ------------------------------------------------------------------------------*/
00254 

Generated on Thu Apr 14 13:59:12 2005 for DarkIce by  doxygen 1.4.1