1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2024-09-15 04:08:07 -04:00

added some reconnect logic

fixed a buffer overflow on large id3tags
use pclose for popen'd file handles


git-svn-id: https://svn.xiph.org/trunk/ezstream@10589 0101bb08-14d6-0310-b084-bc0e0c8e3800
This commit is contained in:
oddsock 2005-12-14 21:13:25 +00:00
parent e48b3b61aa
commit 480000c33a
3 changed files with 72 additions and 54 deletions

View File

@ -2,4 +2,4 @@
AUTOMAKE_OPTIONS = foreign AUTOMAKE_OPTIONS = foreign
EXTRA_DIST = ezstream_m3u.xml ezstream_mp3.xml ezstream_vorbis.xml ezstream_reencoding_example.xml EXTRA_DIST = ezstream_mp3.xml ezstream_reencoding_example_mp3.xml ezstream_reencoding_example_theora.xml ezstream_reencoding_example_vorbis.xml ezstream_vorbis.xml

View File

@ -1,4 +1,4 @@
AC_INIT([ezstream], [0.2.0], [oddsock@xiph.org]) AC_INIT([ezstream], [0.2.1], [oddsock@xiph.org])
AC_PREREQ(2.54) AC_PREREQ(2.54)
AC_CONFIG_SRCDIR(src/ezstream.c) AC_CONFIG_SRCDIR(src/ezstream.c)

View File

@ -13,6 +13,7 @@
#include "configfile.h" #include "configfile.h"
#ifndef WIN32 #ifndef WIN32
#include <libgen.h> #include <libgen.h>
#include <unistd.h>
#endif #endif
#include <vorbis/vorbisfile.h> #include <vorbis/vorbisfile.h>
@ -32,6 +33,8 @@ void hup_handler(int sig)
#ifdef WIN32 #ifdef WIN32
#define STRNCASECMP strnicmp #define STRNCASECMP strnicmp
#define popen _popen #define popen _popen
#define pclose _pclose
#define snprintf _snprintf
#else #else
#define STRNCASECMP strncasecmp #define STRNCASECMP strncasecmp
#endif #endif
@ -198,6 +201,8 @@ char * processMetadata(shout_t *shout, char *extension, char *fileName) {
char *songInfo = NULL; char *songInfo = NULL;
int songLen = 0; int songLen = 0;
ID3Tag id3tag; ID3Tag id3tag;
char temptrackName[31];
char tempartistName[31];
filepstream = fopen(fileName, "rb"); filepstream = fopen(fileName, "rb");
if (filepstream == NULL) { if (filepstream == NULL) {
@ -213,11 +218,16 @@ char * processMetadata(shout_t *shout, char *extension, char *fileName) {
fread(&id3tag, 1, 127, filepstream); fread(&id3tag, 1, 127, filepstream);
if (!strncmp(id3tag.tag, "TAG", strlen("TAG"))) { if (!strncmp(id3tag.tag, "TAG", strlen("TAG"))) {
/* We have an Id3 tag */ /* We have an Id3 tag */
songLen = strlen(id3tag.artistName) + strlen(" - ") + strlen(id3tag.trackName); memset(temptrackName, '\000', sizeof(temptrackName));
memset(tempartistName, '\000', sizeof(tempartistName));
snprintf(temptrackName, sizeof(temptrackName)-1, "%s", id3tag.trackName);
snprintf(tempartistName, sizeof(tempartistName)-1, "%s", id3tag.artistName);
songLen = sizeof(tempartistName) + strlen(" - ") + sizeof(temptrackName) + 1;
songInfo = (char *)malloc(songLen); songInfo = (char *)malloc(songLen);
memset(songInfo, '\000', songLen); memset(songInfo, '\000', songLen);
sprintf(songInfo, "%s - %s", id3tag.artistName, id3tag.trackName); snprintf(songInfo, songLen-1, "%s - %s", tempartistName, temptrackName);
} }
} }
} }
@ -290,7 +300,7 @@ char * processMetadata(shout_t *shout, char *extension, char *fileName) {
return songInfo; return songInfo;
} }
FILE *openResource(shout_t *shout, char *fileName) FILE *openResource(shout_t *shout, char *fileName, int *popenFlag)
{ {
FILE *filep = NULL; FILE *filep = NULL;
@ -314,12 +324,14 @@ FILE *openResource(shout_t *shout, char *fileName)
} }
pMetadata = processMetadata(shout, extension, fileName); pMetadata = processMetadata(shout, extension, fileName);
*popenFlag = 0;
if (pezConfig->reencode) { if (pezConfig->reencode) {
/* Lets set the metadata first */ /* Lets set the metadata first */
if (strlen(extension) > 0) { if (strlen(extension) > 0) {
pCommandString = buildCommandString(extension, fileName, pMetadata); pCommandString = buildCommandString(extension, fileName, pMetadata);
/* Open up the decode/encode loop using popen() */ /* Open up the decode/encode loop using popen() */
filep = popen(pCommandString, "r"); filep = popen(pCommandString, "r");
*popenFlag = 1;
#ifdef WIN32 #ifdef WIN32
_setmode(_fileno(filep), _O_BINARY ); _setmode(_fileno(filep), _O_BINARY );
#endif #endif
@ -348,12 +360,13 @@ FILE *openResource(shout_t *shout, char *fileName)
int streamFile(shout_t *shout, char *fileName) { int streamFile(shout_t *shout, char *fileName) {
FILE *filepstream = NULL; FILE *filepstream = NULL;
char buff[4096]; char buff[4096];
long read, ret, total; long read, ret = 0, total;
int popenFlag = 0;
printf("Streaming %s\n", fileName); printf("Streaming %s\n", fileName);
filepstream = openResource(shout, fileName); filepstream = openResource(shout, fileName, &popenFlag);
if (!filepstream) { if (!filepstream) {
printf("Cannot open %s\n", fileName); printf("Cannot open %s\n", fileName);
return 0; return 0;
@ -394,7 +407,13 @@ int streamFile(shout_t *shout, char *fileName) {
shout_sync(shout); shout_sync(shout);
} }
if (popenFlag) {
printf("Closing via pclose\n");
pclose(filepstream);
}
else {
fclose(filepstream); fclose(filepstream);
}
filepstream = NULL; filepstream = NULL;
return ret; return ret;
} }
@ -403,7 +422,6 @@ int streamPlaylist(shout_t *shout, char *fileName) {
char streamFileName[8096] = ""; char streamFileName[8096] = "";
char lastStreamFileName[8096] = ""; char lastStreamFileName[8096] = "";
int loop = 1; int loop = 1;
int ret = 1;
filep = fopen(fileName, "r"); filep = fopen(fileName, "r");
if (filep == 0) { if (filep == 0) {