Example #1
0
int KItem::LuaCanEquip(Lua_State* L)
{
    assert(L);

    int nCanEquipPos = -1;
    int nCanEquip = false;

    KPlayer* pPlayer = g_pSO3World->m_PlayerSet.GetObj(g_pSO3World->m_dwClientPlayerID);
    KGLOG_PROCESS_ERROR(pPlayer);

    KG_PROCESS_ERROR(getGenre() == igEquipment);

    for (int i = 0; i < eitTotal; ++i)
    {
        if (pPlayer->m_ItemList.CanEquip(this, i) == ircSuccess)
        {
            nCanEquipPos = i;
            if (i == eitLeftRing)
                if (pPlayer->m_ItemList.GetItem(igEquipment, eitLeftRing))
                    if (pPlayer->m_ItemList.CanEquip(this, eitRightRing) == ircSuccess)
                        nCanEquipPos = eitRightRing;
            goto Exit1;
        }
    }
    goto Exit0;

Exit1:
    nCanEquip = true;
Exit0:
    Lua_PushBoolean(L, nCanEquip);
    Lua_PushNumber(L, nCanEquipPos);
    return 2;
}
Example #2
0
    void MP3InputStream::GetID3()
    {
        mpg123_id3v1 *v1;
        mpg123_id3v2 *v2;
        std::string k, v, t;
        char b[32];

        if (mpg123_id3(mh,&v1,&v2) == MPG123_OK)
        {
            if (v1)
            {
                t = "ID3v1";
                k = "title"; memcpy(b,v1->title,30); b[30] = 0; v = b; addTag(k,v,t);
                k = "artist"; memcpy(b,v1->artist,30); b[30] = 0; v = b; addTag(k,v,t);
                k = "album"; memcpy(b,v1->album,30); b[30] = 0; v = b; addTag(k,v,t);
                k = "comment"; memcpy(b,v1->comment,30); b[30] = 0; v = b; addTag(k,v,t);
                k = "year"; memcpy(b,v1->year,4); b[4] = 0; v = b; addTag(k,v,t);
                k = "genre"; v = getGenre(v1->genre); addTag(k,v,t);
            }

            if (v2)
            {
                t = "ID3v2";
                k = "title"; GetMpg123String(v2->title,v); addTag(k,v,t);
                k = "artist"; GetMpg123String(v2->artist,v); addTag(k,v,t);
                k = "album"; GetMpg123String(v2->album,v); addTag(k,v,t);
                k = "year"; GetMpg123String(v2->year,v); addTag(k,v,t);
                k = "genre"; GetMpg123String(v2->genre,v); addTag(k,v,t);
                k = "comment"; GetMpg123String(v2->comment,v); addTag(k,v,t);
            }
        }
    }
Example #3
0
Meta::TrackPtr UpnpCache::getTrack( const KIO::UDSEntry &entry, bool refresh )
{
    QMutexLocker lock( &m_cacheMutex );

    // a little indirection to get the nicely formatted track uidUrl
    Meta::UpnpTrackPtr track( new Meta::UpnpTrack( m_collection ) );
    track->setUidUrl( entry.stringValue( KIO::UPNP_ID ) );

    // if we have a reference ID search for that
    // in either case the original ID (refID) becomes our UID URL instead of the UPNP_ID
    if( entry.contains( KIO::UPNP_REF_ID ) ) {
        track->setUidUrl( entry.stringValue( KIO::UPNP_REF_ID ) );
    }

    QString uidUrl = track->uidUrl();
    if( m_trackMap.contains( uidUrl ) && !refresh ) {
        return m_trackMap[uidUrl];
    }

    // UDS_NAME is the plain ASCII, relative path prefixed name
    // but UDS_DISPLAY_NAME is the unicode, 'file' name.
    track->setTitle( entry.stringValue( KIO::UDSEntry::UDS_DISPLAY_NAME ) );
    track->setPlayableUrl( entry.stringValue(KIO::UDSEntry::UDS_TARGET_URL) );
    track->setTrackNumber( entry.stringValue(KIO::UPNP_TRACK_NUMBER).toInt() );
    // TODO validate and then convert to kbps
    track->setBitrate( entry.stringValue( KIO::UPNP_BITRATE ).toInt() / 1024 );
    track->setLength( duration( entry.stringValue( KIO::UPNP_DURATION ) ) );

    Meta::UpnpArtistPtr artist = Meta::UpnpArtistPtr::staticCast( getArtist( entry.stringValue( KIO::UPNP_ARTIST ) ) );
    artist->addTrack( track );
    track->setArtist( artist );

    Meta::UpnpAlbumPtr album = Meta::UpnpAlbumPtr::staticCast( getAlbum( entry.stringValue( KIO::UPNP_ALBUM ), artist->name() ) );
    album->setAlbumArtist( artist );
    album->addTrack( track );
    track->setAlbum( album );
    // album art
    if( ! album->imageLocation().isValid() )
        album->setAlbumArtUrl( entry.stringValue( KIO::UPNP_ALBUMART_URI ) );

    Meta::UpnpGenrePtr genre = Meta::UpnpGenrePtr::staticCast( getGenre( entry.stringValue( KIO::UPNP_GENRE ) ) );
    genre->addTrack( track );
    track->setGenre( genre );


    // TODO this is plain WRONG! the UPNP_DATE will not have year of the album
    // it will have year of addition to the collection
    //QString yearStr = yearForDate( entry.stringValue( KIO::UPNP_DATE ) );
    //
    //Meta::UpnpYearPtr year = Meta::UpnpYearPtr::staticCast( getYear( yearStr ) );
    //year->addTrack( track );
    //track->setYear( year );

    m_trackMap.insert( uidUrl, Meta::TrackPtr::staticCast( track ) );
    return Meta::TrackPtr::staticCast( track );
}
Example #4
0
CMP3Info CMP3ID3::getMP3Info(){
	CMP3Info mp3;
	mp3.setTitle(getTitle());
	mp3.setArtist(getArtist());
	mp3.setAlbum(getAlbum());
	mp3.setYear(getYear());
	mp3.setTrack(getTrack());
	mp3.setGenre(getGenre());
	mp3.setComment(getComment());
	return mp3;
}
Example #5
0
/**
 * Prints the given list of movies to stdout
 * @param list The list to print
 */
void printMovieData(MovieNodeType *list) {

	puts("List of movies");
	while (list != NULL) {
		printf("Title: %s     Year: %d     Genre: %s\n", list->data->title,
				list->data->year, getGenre(list->data->genre));
		list = list->next;

	}

	puts("");

}
void MusicData::setSong(const skrillex::Song& song)
{
	m_song = song;

	if (!getSong().empty())
		m_tier = Tier_S;

	if (!getArtist().empty())
		m_tier = static_cast<Tier>(m_tier + Tier_A);

	if (!getGenre().empty())
		m_tier = static_cast<Tier>(m_tier + Tier_G);
}
Example #7
0
/**
 * Output the given list of moviesto the file specified by the outputFile global
 * variable
 * @param list The list to output
 */
void dumpList(MovieNodeType *list) {

	if (list == NULL) {
		return;
	}

	unsigned char bytes[MAX_BYTES];

	fprintf(outputFile, "     ------------ LIST ------------\n");
	fprintf(outputFile, "      -- head:    ");
	convertToBytes((int) list, bytes);
	dumpBytes(bytes, MAX_BYTES);

	while (list != NULL) {

		fprintf(outputFile, "     -----------  node addr:  ");
		convertToBytes((int) list, bytes);
		dumpBytes(bytes, MAX_BYTES);

		fprintf(outputFile, "     -----------              data:  ");
		convertToBytes((int) list->data, bytes);
		dumpBytes(bytes, MAX_BYTES);

		fprintf(outputFile,
				"     -----------                     -- title: %s\n",
				list->data->title);
		fprintf(outputFile,
				"     -----------                     -- year:  %d\n",
				list->data->year);
		fprintf(outputFile,
				"     -----------                     -- genre: %s\n",
				getGenre(list->data->genre));

		fprintf(outputFile, "     -----------              prev:  ");
		convertToBytes((int) list->prev, bytes);
		dumpBytes(bytes, MAX_BYTES);

		fprintf(outputFile, "     -----------              next:  ");
		convertToBytes((int) list->next, bytes);
		dumpBytes(bytes, MAX_BYTES);

		list = list->next;
	}

	fprintf(outputFile, "     -------- END OF LIST --------\n");

}
void MainWindow::setupMusicsView()
{
  QStringList headers;
  auto app = (Application*) qApp;

  headers << "Musica" << "Artista" << "Album" << "Tempo" << "Genero";

  ui->musicsView->setColumnCount(5);
  ui->musicsView->setRowCount(app->library->count());
  ui->musicsView->setHorizontalHeaderLabels(headers);

  // Lista todas as músicas da biblioteca.
  for (int i = 0; i < app->library->count(); ++i)
  {
    auto music = app->library->music(i);

    ui->musicsView->setItem(i, 0, new QTableWidgetItem(music.getName()));
    ui->musicsView->setItem(i, 1, new QTableWidgetItem(music.getArtist()));
    ui->musicsView->setItem(i, 2, new QTableWidgetItem(music.getAlbum()));
    ui->musicsView->setItem(i, 3, new QTableWidgetItem(music.getDuration().toString()));
    ui->musicsView->setItem(i, 4, new QTableWidgetItem(music.getGenre()));
  }
}
Example #9
0
/*------------------------------------------------------------------------------
 *  Log in to the IceCast2 server
 *----------------------------------------------------------------------------*/
bool
IceCast2 :: sendLogin ( void )                           throw ( Exception )
{
    Sink          * sink   = getSink();
    Source        * source = getSocket();
    const char    * str;
    char            resp[STRBUF_SIZE];
    unsigned int    len;
    unsigned int    lenExpected;

    if ( !source->isOpen() ) {
        return false;
    }
    if ( !sink->isOpen() ) {
        return false;
    }

    // send the request, a string like:
    // "SOURCE <mountpoint> ICE/1.0"
    str = "SOURCE /";
    sink->write( str, strlen( str));
    str = getMountPoint();
    sink->write( str, strlen( str));
    str = " HTTP/1.0";
    sink->write( str, strlen( str));

    // send the content type, Ogg Vorbis
    str = "\nContent-type: ";
    sink->write( str, strlen( str));
    switch ( format ) {
        case mp3:
            str = "audio/mpeg";
            break;

        case oggVorbis:
            str = "application/x-ogg";
            break;

        default:
            throw Exception( __FILE__, __LINE__,
                             "unsupported stream format", format);
            break;
    }
    sink->write( str, strlen( str));

    // send the authentication info
    str = "\nAuthorization: Basic ";
    sink->write( str, strlen(str));
    {
        // send source:<password> encoded as base64
        char        * source = "source:";
        const char  * pwd    = getPassword();
        char        * tmp    = new char[Util::strLen(source) +
                                        Util::strLen(pwd) + 1];
        Util::strCpy( tmp, source);
        Util::strCat( tmp, pwd);
        char  * base64 = Util::base64Encode( tmp);
        delete[] tmp;
        sink->write( base64, strlen(base64));
        delete[] base64;
    }

    // send user agent info
    str = "\nUser-Agent: DarkIce/" VERSION " (http://darkice.sourceforge.net/)";
    sink->write( str, strlen( str));

    // send the ice- headers
    str = "\nice-bitrate: ";
    sink->write( str, strlen( str));
    if ( log10(getBitRate()) >= (STRBUF_SIZE-2) ) {
        throw Exception( __FILE__, __LINE__,
                         "bitrate does not fit string buffer", getBitRate());
    }
    sprintf( resp, "%d", getBitRate());
    sink->write( resp, strlen( resp));

    str = "\nice-public: ";
    sink->write( str, strlen( str));
    str = getIsPublic() ? "1" : "0";
    sink->write( str, strlen( str));

    if ( getName() ) {
        str = "\nice-name: ";
        sink->write( str, strlen( str));
        str = getName();
        sink->write( str, strlen( str));
    }

    if ( getDescription() ) {
        str = "\nice-description: ";
        sink->write( str, strlen( str));
        str = getDescription();
        sink->write( str, strlen( str));
    }

    if ( getUrl() ) {
        str = "\nice-url: ";
        sink->write( str, strlen( str));
        str = getUrl();
        sink->write( str, strlen( str));
    }

    if ( getGenre() ) {
        str = "\nice-genre: ";
        sink->write( str, strlen( str));
        str = getGenre();
        sink->write( str, strlen( str));
    }

    str = "\n\n";
    sink->write( str, strlen( str));
    sink->flush();

    // read the response, expected response begins with responseOK
    lenExpected = Util::strLen( responseOK);
    if ( (len = source->read( resp, STRBUF_SIZE-1)) < lenExpected ) {
        return false;
    }
    resp[lenExpected] = 0;
    if ( !Util::strEq( resp, responseOK) ) {
        return false;
    }
    
    // suck anything that the other side has to say
    while ( source->canRead( 0, 0) && 
           (len = source->read( resp, STRBUF_SIZE-1)) );

    return true;
}
Example #10
0
/*------------------------------------------------------------------------------
 *  Log in to the IceCast server
 *----------------------------------------------------------------------------*/
bool
IceCast :: sendLogin ( void )                           throw ( Exception )
{
    Sink          * sink   = getSink();
    Source        * source = getSocket();
    const char    * str;
    char            resp[STRBUF_SIZE];
    unsigned int    len;

    if ( !source->isOpen() ) {
        return false;
    }
    if ( !sink->isOpen() ) {
        return false;
    }

    /* send the request, a string like:
     * "SOURCE <password> /<mountpoint>\n" */
    str = "SOURCE ";
    sink->write( str, strlen( str));
    str = getPassword();
    sink->write( str, strlen( str));
    str = " /";
    sink->write( str, strlen( str));
    str = getMountPoint();
    sink->write( str, strlen( str));

    /* send the x-audiocast headers */
    str = "\nx-audiocast-bitrate: ";
    sink->write( str, strlen( str));
    if ( log10(getBitRate()) >= (STRBUF_SIZE-2) ) {
        throw Exception( __FILE__, __LINE__,
                         "bitrate does not fit string buffer", getBitRate());
    }
    sprintf( resp, "%d", getBitRate());
    sink->write( resp, strlen( resp));

    str = "\nx-audiocast-public: ";
    sink->write( str, strlen( str));
    str = getIsPublic() ? "1" : "0";
    sink->write( str, strlen( str));

    if ( getName() ) {
        str = "\nx-audiocast-name: ";
        sink->write( str, strlen( str));
        str = getName();
        sink->write( str, strlen( str));
    }

    if ( getDescription() ) {
        str = "\nx-audiocast-description: ";
        sink->write( str, strlen( str));
        str = getDescription();
        sink->write( str, strlen( str));
    }

    if ( getUrl() ) {
        str = "\nx-audiocast-url: ";
        sink->write( str, strlen( str));
        str = getUrl();
        sink->write( str, strlen( str));
    }

    if ( getGenre() ) {
        str = "\nx-audiocast-genre: ";
        sink->write( str, strlen( str));
        str = getGenre();
        sink->write( str, strlen( str));
    }

    if ( getRemoteDumpFile() ) {
        str = "\nx-audiocast-dumpfile: ";
        sink->write( str, strlen( str));
        str = getRemoteDumpFile();
        sink->write( str, strlen( str));
    }

    str = "\n\n";
    sink->write( str, strlen( str));
    sink->flush();

    /* read the anticipated response: "OK" */
    len = source->read( resp, STRBUF_SIZE);
    if ( len < 2 || resp[0] != 'O' || resp[1] != 'K' ) {
        return false;
    }

    /* suck anything that the other side has to say */
    while ( source->canRead( 0, 0) && 
           (len = source->read( resp, STRBUF_SIZE)) ) {
        ;
    }


    return true;
}
Example #11
0
void Method::setGenericParam() {
    m_genericParam = popGenericNameList();
    if(m_genericParam != NULL && getGenre() == EGENRE::_DELEGATE) {
        compilerError(ERR_NOT_SUPPORTED_YET, "Generic delegates are not supported yet");
    }
}
Example #12
0
void BrowseThread::populateModel() {
    m_path_mutex.lock();
    MDir thisPath = m_path;
    BrowseTableModel* thisModelObserver = m_model_observer;
    m_path_mutex.unlock();

    // Refresh the name filters in case we loaded new SoundSource plugins.
    QStringList nameFilters(SoundSourceProxy::getSupportedFileNamePatterns());

    QDirIterator fileIt(thisPath.dir().absolutePath(), nameFilters,
                        QDir::Files | QDir::NoDotAndDotDot);

    // remove all rows
    // This is a blocking operation
    // see signal/slot connection in BrowseTableModel
    emit(clearModel(thisModelObserver));

    QList< QList<QStandardItem*> > rows;

    int row = 0;
    // Iterate over the files
    while (fileIt.hasNext()) {
        // If a user quickly jumps through the folders
        // the current task becomes "dirty"
        m_path_mutex.lock();
        MDir newPath = m_path;
        m_path_mutex.unlock();

        if (thisPath.dir() != newPath.dir()) {
            qDebug() << "Abort populateModel()";
            return populateModel();
        }

        QString filepath = fileIt.next();
        auto pTrack = Track::newTemporary(filepath, thisPath.token());
        SoundSourceProxy(pTrack).updateTrackFromSource();

        QList<QStandardItem*> row_data;

        QStandardItem* item = new QStandardItem("0");
        item->setData("0", Qt::UserRole);
        row_data.insert(COLUMN_PREVIEW, item);

        item = new QStandardItem(pTrack->getFileName());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_FILENAME, item);

        item = new QStandardItem(pTrack->getArtist());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_ARTIST, item);

        item = new QStandardItem(pTrack->getTitle());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_TITLE, item);

        item = new QStandardItem(pTrack->getAlbum());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_ALBUM, item);

        item = new QStandardItem(pTrack->getAlbumArtist());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_ALBUMARTIST, item);

        item = new QStandardItem(pTrack->getTrackNumber());
        item->setToolTip(item->text());
        item->setData(item->text().toInt(), Qt::UserRole);
        row_data.insert(COLUMN_TRACK_NUMBER, item);

        const QString year(pTrack->getYear());
        item = new YearItem(year);
        item->setToolTip(year);
        // The year column is sorted according to the numeric calendar year
        item->setData(mixxx::TrackMetadata::parseCalendarYear(year), Qt::UserRole);
        row_data.insert(COLUMN_YEAR, item);

        item = new QStandardItem(pTrack->getGenre());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_GENRE, item);

        item = new QStandardItem(pTrack->getComposer());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_COMPOSER, item);

        item = new QStandardItem(pTrack->getGrouping());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_GROUPING, item);

        item = new QStandardItem(pTrack->getComment());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_COMMENT, item);

        QString duration = pTrack->getDurationText(mixxx::Duration::Precision::SECONDS);
        item = new QStandardItem(duration);
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_DURATION, item);

        item = new QStandardItem(pTrack->getBpmText());
        item->setToolTip(item->text());
        item->setData(pTrack->getBpm(), Qt::UserRole);
        row_data.insert(COLUMN_BPM, item);

        item = new QStandardItem(pTrack->getKeyText());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_KEY, item);

        item = new QStandardItem(pTrack->getType());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_TYPE, item);

        item = new QStandardItem(pTrack->getBitrateText());
        item->setToolTip(item->text());
        item->setData(pTrack->getBitrate(), Qt::UserRole);
        row_data.insert(COLUMN_BITRATE, item);

        QString location = pTrack->getLocation();
        QString nativeLocation = QDir::toNativeSeparators(location);
        item = new QStandardItem(nativeLocation);
        item->setToolTip(nativeLocation);
        item->setData(location, Qt::UserRole);
        row_data.insert(COLUMN_NATIVELOCATION, item);

        QDateTime modifiedTime = pTrack->getFileModifiedTime().toLocalTime();
        item = new QStandardItem(modifiedTime.toString(Qt::DefaultLocaleShortDate));
        item->setToolTip(item->text());
        item->setData(modifiedTime, Qt::UserRole);
        row_data.insert(COLUMN_FILE_MODIFIED_TIME, item);

        QDateTime creationTime = pTrack->getFileCreationTime().toLocalTime();
        item = new QStandardItem(creationTime.toString(Qt::DefaultLocaleShortDate));
        item->setToolTip(item->text());
        item->setData(creationTime, Qt::UserRole);
        row_data.insert(COLUMN_FILE_CREATION_TIME, item);

        const mixxx::ReplayGain replayGain(pTrack->getReplayGain());
        item = new QStandardItem(
                mixxx::ReplayGain::ratioToString(replayGain.getRatio()));
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_REPLAYGAIN, item);

        rows.append(row_data);
        ++row;
        // If 10 tracks have been analyzed, send it to GUI
        // Will limit GUI freezing
        if (row % 10 == 0) {
            // this is a blocking operation
            emit(rowsAppended(rows, thisModelObserver));
            qDebug() << "Append " << rows.count() << " from " << filepath;
            rows.clear();
        }
        // Sleep additionally for 10ms which prevents us from GUI freezes
        msleep(20);
    }
    emit(rowsAppended(rows, thisModelObserver));
    qDebug() << "Append last " << rows.count();
}
Example #13
0
/*------------------------------------------------------------------------------
 *  Log in to the ShoutCast server using the icy login scheme
 *----------------------------------------------------------------------------*/
bool
ShoutCast :: sendLogin ( void )                           throw ( Exception )
{
    Sink          * sink   = getSink();
    Source        * source = getSocket();
    const char    * str;
    char            resp[STRBUF_SIZE];
    unsigned int    len;

    if ( !source->isOpen() ) {
        return false;
    }
    if ( !sink->isOpen() ) {
        return false;
    }

    /* first line is the password in itself */
    str = getPassword();
    sink->write( str, strlen( str));
    str = "\n";
    sink->write( str, strlen( str));
    sink->flush();

    /* read the anticipated response: "OK" */
    len = source->read( resp, STRBUF_SIZE);
    reportEvent(8, "server response length: ", len);
    reportEvent(8, "server response: ", resp);
    if ( len < 2 || resp[0] != 'O' || resp[1] != 'K' ) {
        return false;
    }

    /* suck anything that the other side has to say */
    while ( source->canRead( 0, 0) && 
           (len = source->read( resp, STRBUF_SIZE)) ) {
        ;
    }

    /* send the icy headers */
    if ( getName() ) {
        str = "icy-name:";
        sink->write( str, strlen( str));
        str = getName();
        sink->write( str, strlen( str));
    }

    if ( getGenre() ) {
        str = "\nicy-genre:";
        sink->write( str, strlen( str));
        str = getGenre();
        sink->write( str, strlen( str));
    }

    str = "\nicy-pub:";
    sink->write( str, strlen( str));
    str = getIsPublic() ? "1" : "0";
    sink->write( str, strlen( str));

    str = "\nicy-br:";
    sink->write( str, strlen( str));
    if ( log10(getBitRate()) >= (STRBUF_SIZE-2) ) {
        throw Exception( __FILE__, __LINE__,
                         "bitrate does not fit string buffer", getBitRate());
    }
    sprintf( resp, "%d", getBitRate());
    sink->write( resp, strlen( resp));

    if ( getUrl() ) {
        str = "\nicy-url:";
        sink->write( str, strlen( str));
        str = getUrl();
        sink->write( str, strlen( str));
    }

    if ( getIrc() ) {
        str = "\nicy-irc:";
        sink->write( str, strlen( str));
        str = getIrc();
        sink->write( str, strlen( str));
    }

    if ( getIcq() ) {
        str = "\nicy-icq:";
        sink->write( str, strlen( str));
        str = getIcq();
        sink->write( str, strlen( str));
    }

    if ( getAim() ) {
        str = "\nicy-aim:";
        sink->write( str, strlen( str));
        str = getAim();
        sink->write( str, strlen( str));
    }

    str = "\n\n";
    sink->write( str, strlen( str));
    sink->flush();

    /* suck anything that the other side has to say */
    len = source->read( resp, STRBUF_SIZE);
    reportEvent(8, "server response length: ", len);
    reportEvent(8, "server response: ", resp);

    while ( source->canRead( 0, 0) && 
           (len = source->read( resp, STRBUF_SIZE)) ) {
        ;
    }

    return true;
}
Example #14
0
/*------------------------------------------------------------------------------
 *  Log in to the ShoutCast server using the icy login scheme
 *----------------------------------------------------------------------------*/
bool
ShoutCast :: sendLogin ( void )                           throw ( Exception )
{
    Sink          * sink   = getSink();
    Source        * source = getSocket();
    const char    * str;
    char            resp[STRBUF_SIZE];
    unsigned int    len;
    bool            needsMountPoint = false;
    const char    * mountPoint      = getMountPoint();


    if ( !source->isOpen() ) {
        return false;
    }
    if ( !sink->isOpen() ) {
        return false;
    }

    // We will add SOURCE only if really needed: if the mountPoint is not null
    // and is different of "/". This is to keep maximum compatibility with
    // NullSoft Shoutcast server.
    if (mountPoint != 0L
     && strlen(mountPoint) > 0 && 0 != strcmp("/", mountPoint)) {
        needsMountPoint = true;
    }

    std::ostringstream os;

    if (needsMountPoint) {
        os << "SOURCE ";
    }

    /* first line is the password in itself */
    os << getPassword();
    os << "\n";
 
    // send the mount point 
    if (needsMountPoint) {
        os << " ";
        if (strncmp("/", mountPoint, 1) != 0) {
            os << "/";
        }
        os << mountPoint;
        os << "\n";
    }

    str = os.str().c_str();

    // Ok, now we send login which will be different of classical Shoutcast
    // if mountPoint is not null and is different from "/" ...
    sink->write( str, strlen( str));
    sink->flush();

    /* read the anticipated response: "OK" */
    len = source->read( resp, STRBUF_SIZE);
    reportEvent(8, "server response length: ", len);
    reportEvent(8, "server response: ", resp);
    if ( len < 2 || resp[0] != 'O' || resp[1] != 'K' ) {
        return false;
    }

    /* suck anything that the other side has to say */
    while ( source->canRead( 0, 0) && 
           (len = source->read( resp, STRBUF_SIZE)) ) {
        ;
    }

    /* send the icy headers */
    if ( getName() ) {
        str = "icy-name:";
        sink->write( str, strlen( str));
        str = getName();
        sink->write( str, strlen( str));
    }

    if ( getUrl() ) {
        str = "\nicy-url:";
        sink->write( str, strlen( str));
        str = getUrl();
        sink->write( str, strlen( str));
    }

    if ( getGenre() ) {
        str = "\nicy-genre:";
        sink->write( str, strlen( str));
        str = getGenre();
        sink->write( str, strlen( str));
    }

    if ( getIrc() ) {
        str = "\nicy-irc:";
        sink->write( str, strlen( str));
        str = getIrc();
        sink->write( str, strlen( str));
    }

    if ( getAim() ) {
        str = "\nicy-aim:";
        sink->write( str, strlen( str));
        str = getAim();
        sink->write( str, strlen( str));
    }

    if ( getIcq() ) {
        str = "\nicy-icq:";
        sink->write( str, strlen( str));
        str = getIcq();
        sink->write( str, strlen( str));
    }

    str = "\nicy-br:";
    sink->write( str, strlen( str));
    if ( log10(getBitRate()) >= (STRBUF_SIZE-2) ) {
        throw Exception( __FILE__, __LINE__,
                         "bitrate does not fit string buffer", getBitRate());
    }
    sprintf( resp, "%d", getBitRate());
    sink->write( resp, strlen( resp));

    str = "\nicy-pub:";
    sink->write( str, strlen( str));
    str = getIsPublic() ? "1" : "0";
    sink->write( str, strlen( str));

    str = "\n\n";
    sink->write( str, strlen( str));
    sink->flush();

    return true;
}