QString getTitle() { if ( Type != 2 ) return ""; URL_FILE *uFile = url_fopen(curF.toUtf8().data(),""); if (!uFile) return ""; char *data = new char[_DATA_BUFF]; url_fread(data,1,_DATA_BUFF,uFile); url_fclose(uFile); char *t = getICYTitle(data,_DATA_BUFF); QString t2 = t; delete[] t; delete[] data; return t2; }
QString InternetFormatSupport( const char* address ) { loadCURL(); if ( !CURLloaded ) return ""; mpg123_handle *mus = mpg123_new(NULL, NULL); mpg123_open_feed( mus ); URL_FILE *f = url_fopen( address ); if ( !f ) { unloadCURL(); return ""; } char *data; int _DATA_BUFF; if ( !getDataBuff( f, url_fread, _DATA_BUFF, &data ) ) { url_fclose(f); unloadCURL(); return ""; } int bread = url_fread(data+10, 1, _DATA_BUFF-10, f); mpg123_decode( mus, (const unsigned char*)data, bread, 0,0,0 ); bool loaded = getMusInfo( mus, 0,0,0,0,0, -1, "" ); mpg123_close(mus); mpg123_delete(mus); delete[] data; url_fclose(f); unloadCURL(); if ( loaded ) return plugName; else return ""; }
/* Small main program to retrive from a url using fgets and fread saving the * output to two test files (note the fgets method will corrupt binary files if * they contain 0 chars */ int main(int argc, char *argv[]) { URL_FILE *handle; FILE *outf; int nread; char buffer[256]; const char *url; if(argc < 2) { url="http://192.168.7.3/testfile";/* default to testurl */ } else { url=argv[1];/* use passed url */ } /* copy from url line by line with fgets */ outf=fopen("fgets.test","w+"); if(!outf) { perror("couldn't open fgets output file\n"); return 1; } handle = url_fopen(url, "r"); if(!handle) { printf("couldn't url_fopen()\n"); fclose(outf); return 2; } while(!url_feof(handle)) { url_fgets(buffer,sizeof(buffer),handle); fwrite(buffer,1,strlen(buffer),outf); } url_fclose(handle); fclose(outf); /* Copy from url with fread */ outf=fopen("fread.test","w+"); if(!outf) { perror("couldn't open fread output file\n"); return 1; } handle = url_fopen("testfile", "r"); if(!handle) { printf("couldn't url_fopen()\n"); fclose(outf); return 2; } do { nread = url_fread(buffer, 1,sizeof(buffer), handle); fwrite(buffer,1,nread,outf); } while(nread); url_fclose(handle); fclose(outf); /* Test rewind */ outf=fopen("rewind.test","w+"); if(!outf) { perror("couldn't open fread output file\n"); return 1; } handle = url_fopen("testfile", "r"); if(!handle) { printf("couldn't url_fopen()\n"); fclose(outf); return 2; } nread = url_fread(buffer, 1,sizeof(buffer), handle); fwrite(buffer,1,nread,outf); url_rewind(handle); buffer[0]='\n'; fwrite(buffer,1,1,outf); nread = url_fread(buffer, 1,sizeof(buffer), handle); fwrite(buffer,1,nread,outf); url_fclose(handle); fclose(outf); return 0;/* all done */ }
int db_input_wrapper(char* buf, int max_size, int db) { int retval=0; int c=0; int err=0; int* domd=NULL; url_t* db_url=NULL; #ifdef WITH_MHASH char* tmp=NULL; MHASH* md=NULL; void* key=NULL; int keylen; #endif FILE** db_filep=NULL; #ifdef WITH_ZLIB gzFile* db_gzp=NULL; #endif switch(db) { case DB_OLD: { db_url=conf->db_in_url; domd=&(conf->do_dboldmd); #ifdef WITH_MHASH md=&(conf->dboldmd); #endif db_filep=&(conf->db_in); #ifdef WITH_ZLIB db_gzp=&(conf->db_gzin); #endif break; } case DB_NEW: { db_url=conf->db_new_url; domd=&(conf->do_dbnewmd); #ifdef WITH_MHASH md=&(conf->dbnewmd); #endif db_filep=&(conf->db_new); #ifdef WITH_ZLIB db_gzp=&(conf->db_gznew); #endif break; } } #ifdef WITH_CURL switch (db_url->type) { case url_http: case url_https: case url_ftp: { retval=url_fread(buf,1,max_size,(URL_FILE *)*db_filep); break; } default: #endif /* WITH CURL */ /* Read a character at a time until we are doing md */ #ifdef WITH_ZLIB if((*db_gzp==NULL)&&(*domd)){ retval=fread(buf,1,max_size,*db_filep); } if((*db_gzp!=NULL)&&(*domd)){ if(gzeof(*db_gzp)){ retval=0; buf[0]='\0'; }else { if((retval=gzread(*db_gzp,buf,max_size))<0){ error(0,_("gzread() failed: gzerr=%s!\n"),gzerror(*db_gzp,&err)); retval=0; buf[0]='\0'; } else { /* gzread returns 0 even if uncompressed bytes were read*/ error(240,"nread=%d,strlen(buf)=%lu,errno=%s,gzerr=%s\n", retval,(unsigned long)strnlen((char*)buf, max_size), strerror(errno),gzerror(*db_gzp,&err)); if(retval==0){ retval=strnlen((char*)buf, max_size); } } } } if((*db_gzp!=NULL)&&!(*domd)){ c=gzgetc(*db_gzp); retval= (c==EOF) ? 0 : (buf[0] = c,1); } if((*db_gzp==NULL)&&!(*domd)){ c=fgetc(*db_filep); if(c==(unsigned char)'\037'){ c=fgetc(*db_filep); if(c==(unsigned char)'\213'){ /* We got gzip header. */ error(255,"Got Gzip header. Handling..\n"); lseek(fileno(*db_filep),0L,SEEK_SET); *db_gzp=gzdopen(fileno(*db_filep),"rb"); c=gzgetc(*db_gzp); error(255,"First character after gzip header is: %c(%#X)\n",c,c); if(c==-1) { int xx; error(0,"Error reading gzipped file: %s\n",gzerror(*db_gzp,&xx)); exit(EXIT_FAILURE); } }else { /* False alarm */ ungetc(c,*db_filep); } } retval= (c==EOF) ? 0 : (buf[0] = c,1); } #else /* WITH_ZLIB */ #ifdef WITH_MHASH if(*domd){ retval=fread(buf,1,max_size,*db_filep); }else { c=fgetc(*db_filep); retval= (c==EOF) ? 0 : (buf[0] = c,1); } #else /* WITH_MHASH */ retval=fread(buf,1,max_size,*db_filep); #endif /* WITH_MHASH */ #endif /* WITH_ZLIB */ #ifdef WITH_MHASH if(*domd){ if(!*md){ if((key=get_db_key())!=NULL){ keylen=get_db_key_len(); if( (*md= mhash_hmac_init(conf->dbhmactype, key, keylen, mhash_get_hash_pblock(conf->dbhmactype)))== MHASH_FAILED){ error(0, "mhash_hmac_init() failed for db check. Aborting\n"); exit(EXIT_FAILURE); } } else { *domd=0; } } /* FIXME This does not handle the case that @@end_config is on buffer boundary. */ if (*domd!=0) { if((tmp=strnstr(buf,"@@end_db",retval))!=NULL){ /* We have end of db don't feed the last line to mhash */ mhash(*md,(void*)buf,tmp-buf); /* We don't want to come here again after the *md has been deinited by db_readline_file() */ *domd=0; } else { mhash(*md,(void*)buf,retval); } } } #endif #ifdef WITH_CURL } #endif /* WITH CURL */ return retval; }
void play( const char *fileE, int ) { if ( Type != 0 && Type != 2 ) return ERROR2( "Wtyczka obsługuje tylko odczyt plików i strumienia internetowego!" ); if ( Type == 2 ) { QString tmp = loadCURL(); if ( !CURLloaded ) return ERROR2( "Nie można załadować biblioteki: "+QMPInternetf+libExt+"\n"+tmp ); } if ( fileE != curF ) clrPos(); clrSet(); QString BLAD; if ( Type == 0 ) BLAD = "Błąd odczytu pliku!"; else if ( Type == 2 ) BLAD = "Nie można otworzyć strumienia internetowego!"; musicfile = mpg123_new(NULL, NULL); if ( Type == 0 ) { fd = qmp_open( fileE, O_RDONLY|O_BINARY ); mpg123_open_fd( musicfile, fd ); } if ( Type == 2 ) { title = "Czekaj, trwa otwieranie..."; mpg123_open_feed( musicfile ); f = url_fopen(fileE,0,1); if ( !f ) return ERROR(BLAD); if ( !getDataBuff( f, url_fread, _DATA_BUFF, &data, &bolStop ) ) return ERROR(BLAD); url_fread(data+10, 1, _DATA_BUFF-10, f); if ( getNetInfo( f, FILE_SIZE ) > 0.0 ) knownSize = true; mpg123_decode( musicfile, (const unsigned char*)data, _DATA_BUFF, 0,0,0 ); } if ( !musicfile ) return ERROR(BLAD); curF = fileE; if ( !MP3Update() ) return ERROR(BLAD); if ( Type == 2 && title.isEmpty() ) title = fileE; if ( Type == 2 || ( Type == 0 && fileE[0] == '/' && fileE[1] == '/' ) ) QOut->useQMPBuffer(); QOut->Init( AudioInfo( rate, 16, chn ), true, 0, fileE, /*title*/Title ); if ( *QOut->PlErr ) { *QOut->PlErr = false; return ERROR("Błąd zwraca wtyczka wyjściowa!"); } IsPlaying = true; size_t bDecoded = 0; audio_buffer = new char[BUF_SIZE]; TMPint = 0; int musErr = 0; for(;;) { if ( bolStop ) break; if ( !IsPaused ) { if ( !*QOut->mustReset ) { if ( doSeek ) { mpg123_seek( musicfile, doSeek, SEEK_SET ); QOut->control( QOUT_NEXT_READ ); doSeek = 0; } musErr = mpg123_read( musicfile, (unsigned char*)audio_buffer, BUF_SIZE, &bDecoded ); if ( musErr == MPG123_DONE ) break; if ( musErr == MPG123_ERR && !searchParts ) break; QOut->Play( audio_buffer, bDecoded, pltime, false ); MP3Update2( bDecoded ); if ( musErr == MPG123_NEED_MORE && Type != 0 ) { int bread = url_fread( data, 1, _DATA_BUFF, f ); if ( ( !bread && !wait4Data ) || ( !bread && url_feof(f) ) ) break; else if ( !bread ) MYsleep( 25 ); mpg123_decode( musicfile, (const unsigned char*)data, bread, NULL, 0, NULL ); } } else QOut->Play(0,0,pltime,true); } else QOut->Play(0,0,pltime,true); } STOP(); }