2007-02-24 19:25:07 -05:00
|
|
|
/*
|
|
|
|
* ezstream - source client for Icecast with external en-/decoder support
|
|
|
|
* Copyright (C) 2003, 2004, 2005, 2006 Ed Zaleski <oddsock@oddsock.org>
|
2015-01-07 17:44:44 -05:00
|
|
|
* Copyright (C) 2007, 2009, 2015 Moritz Grimm <mgrimm@mrsserver.net>
|
2007-02-24 19:25:07 -05:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-03-04 10:16:36 -05:00
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
2007-02-24 19:25:07 -05:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2004-01-30 12:19:45 -05:00
|
|
|
|
2015-04-22 13:29:20 -04:00
|
|
|
#include "compat.h"
|
|
|
|
|
2009-03-18 05:10:28 -04:00
|
|
|
#include "ezstream.h"
|
|
|
|
|
2007-02-24 19:25:07 -05:00
|
|
|
#ifdef HAVE_SIGNAL_H
|
|
|
|
# include <signal.h>
|
|
|
|
#endif
|
2009-03-18 05:10:28 -04:00
|
|
|
|
2004-01-30 12:19:45 -05:00
|
|
|
#include <shout/shout.h>
|
2007-02-24 19:25:07 -05:00
|
|
|
|
2015-04-22 13:29:20 -04:00
|
|
|
#include "cfg.h"
|
2007-03-03 11:13:08 -05:00
|
|
|
#include "configfile.h"
|
2015-04-22 13:29:20 -04:00
|
|
|
#include "log.h"
|
2007-03-08 09:39:00 -05:00
|
|
|
#include "metadata.h"
|
2007-02-24 19:25:07 -05:00
|
|
|
#include "playlist.h"
|
|
|
|
#include "util.h"
|
2007-08-02 14:48:26 -04:00
|
|
|
#include "xalloc.h"
|
2007-02-24 19:25:07 -05:00
|
|
|
|
2007-03-01 19:57:11 -05:00
|
|
|
#define STREAM_DONE 0
|
|
|
|
#define STREAM_CONT 1
|
|
|
|
#define STREAM_SKIP 2
|
|
|
|
#define STREAM_SERVERR 3
|
2007-03-08 21:30:29 -05:00
|
|
|
#define STREAM_UPDMDATA 4
|
2007-03-01 19:57:11 -05:00
|
|
|
|
2007-03-08 21:30:29 -05:00
|
|
|
int metadataFromProgram;
|
2004-01-30 12:19:45 -05:00
|
|
|
|
Various cleanups and auto-fu tweaks.
* Make Makefile.am files look alike as much as possible.
* Remove debug: target and don't mess with the users DEBUG environment
variable: Autoconf checks for -g and automatically adds it to CFLAGS, which
is overridden by the user's $DEBUG. If the user didn't specify one, "make
install" will strip the resulting binaries and leave the debugging symbols
intact otherwise.
* Remove profile: target, as it is quite pointless in Ezstream. Also, the user
can add profiling flags via the $DEBUG variable as well.
* Remove -ffast-math and -fsigned-char from gcc, and enable two additional
warnings instead.
* Unconfuse Solaris compiler flags (unfortunately, the configure script still
fails in the libshout check with some obscure linker error): Do not force
-x04 and -fast optimizations, let the user decide (it doesn't matter for
Ezstream anyways.) Remove -xgc92, which is deprecated and actually makes
the resulting binary run slower on SPARC. Also remove -fsimple, which does
not help and has the potential of causing trouble, and don't enable verbose
warnings just to disable them afterwards with -w. Leave only -v for verbose
warnings.
* Const'ify getFormat*() functions and blankString, and squelch a few const-
related warnings.
* Squelch a signedness warning and fix two ;; syntax errors.
* Add a snapshot target to Makefile.am that creates a tarball of the form
ezstream-snapshot-YYYYMMDD.tar.gz.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12562 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-25 09:00:15 -05:00
|
|
|
EZCONFIG *pezConfig = NULL;
|
|
|
|
playlist_t *playlist = NULL;
|
|
|
|
int playlistMode = 0;
|
2009-08-29 05:36:18 -04:00
|
|
|
unsigned int resource_errors = 0;
|
2004-04-21 09:48:22 -04:00
|
|
|
|
2007-02-24 19:25:07 -05:00
|
|
|
#ifdef HAVE_SIGNALS
|
2007-08-04 13:04:50 -04:00
|
|
|
const int ezstream_signals[] = {
|
|
|
|
SIGTERM, SIGINT, SIGHUP, SIGUSR1, SIGUSR2
|
|
|
|
};
|
2007-02-25 11:00:41 -05:00
|
|
|
|
|
|
|
volatile sig_atomic_t rereadPlaylist = 0;
|
|
|
|
volatile sig_atomic_t rereadPlaylist_notify = 0;
|
|
|
|
volatile sig_atomic_t skipTrack = 0;
|
2007-03-09 08:43:26 -05:00
|
|
|
volatile sig_atomic_t queryMetadata = 0;
|
2007-08-04 13:04:50 -04:00
|
|
|
volatile sig_atomic_t quit = 0;
|
2004-07-18 23:12:31 -04:00
|
|
|
#else
|
2007-02-25 11:00:41 -05:00
|
|
|
int rereadPlaylist = 0;
|
|
|
|
int rereadPlaylist_notify = 0;
|
|
|
|
int skipTrack = 0;
|
2007-03-08 21:30:29 -05:00
|
|
|
int queryMetadata = 0;
|
2007-08-04 13:04:50 -04:00
|
|
|
int quit = 0;
|
2007-02-24 19:25:07 -05:00
|
|
|
#endif /* HAVE_SIGNALS */
|
2004-01-30 12:19:45 -05:00
|
|
|
|
|
|
|
typedef struct tag_ID3Tag {
|
2007-08-31 07:47:54 -04:00
|
|
|
char tag[3];
|
|
|
|
char trackName[30];
|
|
|
|
char artistName[30];
|
|
|
|
char albumName[30];
|
|
|
|
char year[3];
|
|
|
|
char comment[30];
|
|
|
|
char genre;
|
2004-01-30 12:19:45 -05:00
|
|
|
} ID3Tag;
|
|
|
|
|
2009-03-15 13:18:56 -04:00
|
|
|
int urlParse(const char *, char **, unsigned short *, char **);
|
2015-01-07 16:49:09 -05:00
|
|
|
char * shellQuote(const char *);
|
|
|
|
char * replaceString(const char *, const char *, const char *);
|
2007-03-09 21:27:48 -05:00
|
|
|
char * buildCommandString(const char *, const char *, metadata_t *);
|
2007-03-10 14:03:07 -05:00
|
|
|
char * getMetadataString(const char *, metadata_t *);
|
2007-03-09 21:27:48 -05:00
|
|
|
metadata_t * getMetadata(const char *);
|
|
|
|
int setMetadata(shout_t *, metadata_t *, char **);
|
2007-08-23 09:48:42 -04:00
|
|
|
FILE * openResource(shout_t *, const char *, int *, metadata_t **,
|
2009-03-16 16:22:56 -04:00
|
|
|
int *, long *);
|
2007-03-09 21:27:48 -05:00
|
|
|
int reconnectServer(shout_t *, int);
|
2009-03-16 16:22:56 -04:00
|
|
|
const char * getTimeString(long);
|
2007-03-10 16:18:21 -05:00
|
|
|
int sendStream(shout_t *, FILE *, const char *, int, const char *,
|
2007-08-31 07:47:54 -04:00
|
|
|
struct timeval *);
|
2007-03-09 21:27:48 -05:00
|
|
|
int streamFile(shout_t *, const char *);
|
|
|
|
int streamPlaylist(shout_t *, const char *);
|
2007-08-08 09:15:04 -04:00
|
|
|
int ez_shutdown(int);
|
2004-01-30 12:19:45 -05:00
|
|
|
|
2007-03-03 07:42:50 -05:00
|
|
|
#ifdef HAVE_SIGNALS
|
2007-12-01 11:02:55 -05:00
|
|
|
void sig_handler(int);
|
|
|
|
|
|
|
|
# ifndef SIG_IGN
|
|
|
|
# define SIG_IGN (void (*)(int))1
|
|
|
|
# endif /* !SIG_IGN */
|
2007-03-03 07:42:50 -05:00
|
|
|
|
2007-03-01 09:50:14 -05:00
|
|
|
void
|
|
|
|
sig_handler(int sig)
|
|
|
|
{
|
|
|
|
switch (sig) {
|
2007-08-04 13:04:50 -04:00
|
|
|
case SIGTERM:
|
|
|
|
case SIGINT:
|
|
|
|
quit = 1;
|
|
|
|
break;
|
2007-03-01 09:50:14 -05:00
|
|
|
case SIGHUP:
|
|
|
|
rereadPlaylist = 1;
|
|
|
|
rereadPlaylist_notify = 1;
|
|
|
|
break;
|
|
|
|
case SIGUSR1:
|
|
|
|
skipTrack = 1;
|
|
|
|
break;
|
2007-03-08 21:30:29 -05:00
|
|
|
case SIGUSR2:
|
|
|
|
queryMetadata = 1;
|
|
|
|
break;
|
2007-03-01 09:50:14 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-03-03 07:42:50 -05:00
|
|
|
#endif /* HAVE_SIGNALS */
|
2007-03-01 09:50:14 -05:00
|
|
|
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
int
|
2009-03-15 13:18:56 -04:00
|
|
|
urlParse(const char *url, char **hostname, unsigned short *port,
|
|
|
|
char **mountname)
|
2004-01-30 12:19:45 -05:00
|
|
|
{
|
2009-03-15 13:18:56 -04:00
|
|
|
const char *p1, *p2, *p3;
|
2007-03-02 07:52:10 -05:00
|
|
|
char tmpPort[6] = "";
|
|
|
|
size_t hostsiz, mountsiz;
|
|
|
|
const char *errstr;
|
2004-01-30 12:19:45 -05:00
|
|
|
|
2007-03-02 07:52:10 -05:00
|
|
|
if (strncmp(url, "http://", strlen("http://")) != 0) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("invalid <url>: not an HTTP address");
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
return (0);
|
2007-03-02 07:52:10 -05:00
|
|
|
}
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
|
2009-03-15 13:18:56 -04:00
|
|
|
p1 = url + strlen("http://");
|
2004-01-30 12:19:45 -05:00
|
|
|
p2 = strchr(p1, ':');
|
2007-03-02 07:52:10 -05:00
|
|
|
if (p2 == NULL) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("invalid <url>: missing port");
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
return (0);
|
2007-03-02 07:52:10 -05:00
|
|
|
}
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
hostsiz = (p2 - p1) + 1;
|
2015-04-22 13:29:20 -04:00
|
|
|
if (hostsiz <= 1) {
|
|
|
|
log_error("invalid <url>: missing host");
|
|
|
|
return (0);
|
|
|
|
}
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
*hostname = xmalloc(hostsiz);
|
|
|
|
strlcpy(*hostname, p1, hostsiz);
|
|
|
|
|
2004-01-30 12:19:45 -05:00
|
|
|
p2++;
|
|
|
|
p3 = strchr(p2, '/');
|
2007-03-02 07:52:10 -05:00
|
|
|
if (p3 == NULL || p3 - p2 >= (int)sizeof(tmpPort)) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("invalid <url>: mountpoint missing, or port number too long");
|
2007-03-02 07:52:10 -05:00
|
|
|
xfree(*hostname);
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
return (0);
|
2007-03-02 07:52:10 -05:00
|
|
|
}
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
|
2009-03-15 13:18:56 -04:00
|
|
|
strlcpy(tmpPort, p2, (p3 - p2) + 1UL);
|
|
|
|
*port = (unsigned short)strtonum(tmpPort, 1LL, (long long)USHRT_MAX, &errstr);
|
2007-03-02 07:52:10 -05:00
|
|
|
if (errstr) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("invalid <url>: port: %s is %s", tmpPort, errstr);
|
2007-03-02 07:52:10 -05:00
|
|
|
xfree(*hostname);
|
|
|
|
return (0);
|
|
|
|
}
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
|
|
|
|
mountsiz = strlen(p3) + 1;
|
|
|
|
*mountname = xmalloc(mountsiz);
|
|
|
|
strlcpy(*mountname, p3, mountsiz);
|
|
|
|
|
|
|
|
return (1);
|
2004-01-30 12:19:45 -05:00
|
|
|
}
|
|
|
|
|
2015-01-07 16:49:09 -05:00
|
|
|
#define SHELLQUOTE_INLEN_MAX 8191UL
|
|
|
|
|
|
|
|
char *
|
|
|
|
shellQuote(const char *in)
|
|
|
|
{
|
|
|
|
char *out, *out_p;
|
|
|
|
size_t out_len;
|
|
|
|
const char *in_p;
|
|
|
|
|
|
|
|
out_len = (strlen(in) > SHELLQUOTE_INLEN_MAX)
|
|
|
|
? SHELLQUOTE_INLEN_MAX
|
|
|
|
: strlen(in);
|
|
|
|
out_len = out_len * 2 + 2;
|
|
|
|
out = xcalloc(out_len + 1, sizeof(char));
|
|
|
|
|
|
|
|
out_p = out;
|
|
|
|
in_p = in;
|
|
|
|
|
|
|
|
*out_p++ = '\'';
|
|
|
|
out_len--;
|
|
|
|
while (*in_p && out_len > 2) {
|
|
|
|
switch (*in_p) {
|
|
|
|
case '\'':
|
|
|
|
case '\\':
|
|
|
|
*out_p++ = '\\';
|
|
|
|
out_len--;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*out_p++ = *in_p++;
|
|
|
|
out_len--;
|
|
|
|
}
|
|
|
|
*out_p++ = '\'';
|
|
|
|
|
|
|
|
return (out);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
replaceString(const char *source, const char *from, const char *to)
|
2004-07-18 23:12:31 -04:00
|
|
|
{
|
2015-01-07 16:49:09 -05:00
|
|
|
char *to_quoted, *dest;
|
|
|
|
size_t dest_size;
|
|
|
|
const char *p1, *p2;
|
|
|
|
|
|
|
|
to_quoted = shellQuote(to);
|
|
|
|
dest_size = strlen(source) + strlen(to_quoted) + 1;
|
|
|
|
dest = xcalloc(dest_size, sizeof(char));
|
2007-02-24 21:36:40 -05:00
|
|
|
|
2015-01-07 16:49:09 -05:00
|
|
|
p1 = source;
|
2007-02-24 21:36:40 -05:00
|
|
|
p2 = strstr(p1, from);
|
|
|
|
if (p2 != NULL) {
|
2009-03-15 13:18:56 -04:00
|
|
|
strncat(dest, p1, (size_t)(p2 - p1));
|
2015-01-07 16:49:09 -05:00
|
|
|
strlcat(dest, to_quoted, dest_size);
|
2007-02-24 21:36:40 -05:00
|
|
|
p1 = p2 + strlen(from);
|
2004-07-18 23:12:31 -04:00
|
|
|
}
|
2015-01-07 16:49:09 -05:00
|
|
|
strlcat(dest, p1, dest_size);
|
|
|
|
|
|
|
|
xfree(to_quoted);
|
|
|
|
|
|
|
|
return (dest);
|
2004-07-18 23:12:31 -04:00
|
|
|
}
|
|
|
|
|
2007-03-08 09:39:00 -05:00
|
|
|
char *
|
2007-02-24 21:36:40 -05:00
|
|
|
buildCommandString(const char *extension, const char *fileName,
|
2007-03-09 21:27:48 -05:00
|
|
|
metadata_t *mdata)
|
2004-07-18 23:12:31 -04:00
|
|
|
{
|
|
|
|
char *commandString = NULL;
|
2007-02-24 21:36:40 -05:00
|
|
|
size_t commandStringLen = 0;
|
|
|
|
char *encoder = NULL;
|
|
|
|
char *decoder = NULL;
|
|
|
|
char *newDecoder = NULL;
|
|
|
|
char *newEncoder = NULL;
|
2009-03-15 07:05:44 -04:00
|
|
|
char *localTitle = UTF8toCHAR(metadata_get_title(mdata),
|
|
|
|
ICONV_REPLACE);
|
|
|
|
char *localArtist = UTF8toCHAR(metadata_get_artist(mdata),
|
|
|
|
ICONV_REPLACE);
|
|
|
|
char *localMetaString = UTF8toCHAR(metadata_get_string(mdata),
|
|
|
|
ICONV_REPLACE);
|
2007-02-24 21:36:40 -05:00
|
|
|
|
|
|
|
decoder = xstrdup(getFormatDecoder(extension));
|
2004-07-18 23:12:31 -04:00
|
|
|
if (strlen(decoder) == 0) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("cannot decode: %s: unknown file extension %s",
|
|
|
|
fileName, extension);
|
2009-03-15 07:05:44 -04:00
|
|
|
xfree(localTitle);
|
|
|
|
xfree(localArtist);
|
|
|
|
xfree(localMetaString);
|
2007-02-24 21:36:40 -05:00
|
|
|
xfree(decoder);
|
|
|
|
return (NULL);
|
2004-07-18 23:12:31 -04:00
|
|
|
}
|
2015-01-07 16:49:09 -05:00
|
|
|
newDecoder = replaceString(decoder, TRACK_PLACEHOLDER, fileName);
|
2007-03-10 14:03:07 -05:00
|
|
|
if (strstr(decoder, ARTIST_PLACEHOLDER) != NULL) {
|
2015-01-07 16:49:09 -05:00
|
|
|
char *tmpStr = replaceString(newDecoder, ARTIST_PLACEHOLDER,
|
|
|
|
localArtist);
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(newDecoder);
|
|
|
|
newDecoder = tmpStr;
|
|
|
|
}
|
|
|
|
if (strstr(decoder, TITLE_PLACEHOLDER) != NULL) {
|
2015-01-07 16:49:09 -05:00
|
|
|
char *tmpStr = replaceString(newDecoder, TITLE_PLACEHOLDER,
|
|
|
|
localTitle);
|
2007-02-24 21:36:40 -05:00
|
|
|
xfree(newDecoder);
|
|
|
|
newDecoder = tmpStr;
|
|
|
|
}
|
2007-03-10 14:03:07 -05:00
|
|
|
/*
|
|
|
|
* if meta
|
|
|
|
* if (prog && format)
|
|
|
|
* metatoformat
|
|
|
|
* else
|
|
|
|
* if (!prog && title)
|
|
|
|
* emptymeta
|
|
|
|
* else
|
|
|
|
* replacemeta
|
|
|
|
*/
|
|
|
|
if (strstr(decoder, METADATA_PLACEHOLDER) != NULL) {
|
|
|
|
if (metadataFromProgram && pezConfig->metadataFormat != NULL) {
|
|
|
|
char *mdataString = getMetadataString(pezConfig->metadataFormat, mdata);
|
2015-01-07 16:49:09 -05:00
|
|
|
char *tmpStr = replaceString(newDecoder,
|
|
|
|
METADATA_PLACEHOLDER, mdataString);
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(newDecoder);
|
|
|
|
xfree(mdataString);
|
|
|
|
newDecoder = tmpStr;
|
|
|
|
} else {
|
|
|
|
if (!metadataFromProgram && strstr(decoder, TITLE_PLACEHOLDER) != NULL) {
|
2015-01-07 16:49:09 -05:00
|
|
|
char *tmpStr = replaceString(newDecoder,
|
|
|
|
METADATA_PLACEHOLDER, "");
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(newDecoder);
|
|
|
|
newDecoder = tmpStr;
|
|
|
|
} else {
|
2015-01-07 16:49:09 -05:00
|
|
|
char *tmpStr = replaceString(newDecoder,
|
|
|
|
METADATA_PLACEHOLDER, localMetaString);
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(newDecoder);
|
|
|
|
newDecoder = tmpStr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-07-18 23:12:31 -04:00
|
|
|
|
2007-02-24 21:36:40 -05:00
|
|
|
encoder = xstrdup(getFormatEncoder(pezConfig->format));
|
2004-12-21 20:49:56 -05:00
|
|
|
if (strlen(encoder) == 0) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_notice("passing through%s%s data from the decoder",
|
|
|
|
(strcmp(pezConfig->format, THEORA_FORMAT) != 0) ? " (unsupported) " : " ",
|
|
|
|
pezConfig->format);
|
2004-12-21 20:49:56 -05:00
|
|
|
commandStringLen = strlen(newDecoder) + 1;
|
2007-07-24 11:29:16 -04:00
|
|
|
commandString = xcalloc(commandStringLen, sizeof(char));
|
2007-02-24 21:36:40 -05:00
|
|
|
strlcpy(commandString, newDecoder, commandStringLen);
|
2009-03-15 07:05:44 -04:00
|
|
|
xfree(localTitle);
|
|
|
|
xfree(localArtist);
|
|
|
|
xfree(localMetaString);
|
2007-02-24 21:36:40 -05:00
|
|
|
xfree(decoder);
|
|
|
|
xfree(encoder);
|
|
|
|
xfree(newDecoder);
|
|
|
|
return (commandString);
|
2004-12-21 20:49:56 -05:00
|
|
|
}
|
|
|
|
|
2015-01-07 16:49:09 -05:00
|
|
|
newEncoder = replaceString(encoder, ARTIST_PLACEHOLDER, localArtist);
|
2007-03-10 14:03:07 -05:00
|
|
|
if (strstr(encoder, TITLE_PLACEHOLDER) != NULL) {
|
2015-01-07 16:49:09 -05:00
|
|
|
char *tmpStr = replaceString(newEncoder, TITLE_PLACEHOLDER,
|
|
|
|
localTitle);
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(newEncoder);
|
|
|
|
newEncoder = tmpStr;
|
|
|
|
}
|
|
|
|
if (strstr(encoder, METADATA_PLACEHOLDER) != NULL) {
|
|
|
|
if (metadataFromProgram && pezConfig->metadataFormat != NULL) {
|
|
|
|
char *mdataString = getMetadataString(pezConfig->metadataFormat, mdata);
|
2015-01-07 16:49:09 -05:00
|
|
|
char *tmpStr = replaceString(newEncoder,
|
|
|
|
METADATA_PLACEHOLDER, mdataString);
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(newEncoder);
|
|
|
|
xfree(mdataString);
|
|
|
|
newEncoder = tmpStr;
|
|
|
|
} else {
|
|
|
|
if (!metadataFromProgram && strstr(encoder, TITLE_PLACEHOLDER) != NULL) {
|
2015-01-07 16:49:09 -05:00
|
|
|
char *tmpStr = replaceString(newEncoder,
|
|
|
|
METADATA_PLACEHOLDER, "");
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(newEncoder);
|
|
|
|
newEncoder = tmpStr;
|
|
|
|
} else {
|
2015-01-07 16:49:09 -05:00
|
|
|
char *tmpStr = replaceString(newEncoder,
|
|
|
|
METADATA_PLACEHOLDER, localMetaString);
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(newEncoder);
|
|
|
|
newEncoder = tmpStr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-07-18 23:12:31 -04:00
|
|
|
|
2007-02-24 21:36:40 -05:00
|
|
|
commandStringLen = strlen(newDecoder) + strlen(" | ") +
|
2015-04-13 17:28:21 -04:00
|
|
|
strlen(newEncoder) + 1;
|
2007-07-24 11:29:16 -04:00
|
|
|
commandString = xcalloc(commandStringLen, sizeof(char));
|
2007-02-24 21:36:40 -05:00
|
|
|
snprintf(commandString, commandStringLen, "%s | %s", newDecoder,
|
2015-04-13 17:28:21 -04:00
|
|
|
newEncoder);
|
2007-02-24 21:36:40 -05:00
|
|
|
|
2009-03-15 07:05:44 -04:00
|
|
|
xfree(localTitle);
|
|
|
|
xfree(localArtist);
|
|
|
|
xfree(localMetaString);
|
2007-02-24 21:36:40 -05:00
|
|
|
xfree(decoder);
|
|
|
|
xfree(encoder);
|
|
|
|
xfree(newDecoder);
|
|
|
|
xfree(newEncoder);
|
|
|
|
|
|
|
|
return (commandString);
|
2004-07-18 23:12:31 -04:00
|
|
|
}
|
2005-12-14 16:13:25 -05:00
|
|
|
|
2007-03-10 14:03:07 -05:00
|
|
|
char *
|
|
|
|
getMetadataString(const char *format, metadata_t *mdata)
|
|
|
|
{
|
|
|
|
char *tmp, *str;
|
|
|
|
|
|
|
|
if (format == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
str = xstrdup(format);
|
|
|
|
|
|
|
|
if (strstr(format, ARTIST_PLACEHOLDER) != NULL) {
|
2015-01-07 16:49:09 -05:00
|
|
|
tmp = replaceString(str, ARTIST_PLACEHOLDER,
|
|
|
|
metadata_get_artist(mdata));
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(str);
|
|
|
|
str = tmp;
|
|
|
|
}
|
|
|
|
if (strstr(format, TITLE_PLACEHOLDER) != NULL) {
|
2015-01-07 16:49:09 -05:00
|
|
|
tmp = replaceString(str, TITLE_PLACEHOLDER,
|
|
|
|
metadata_get_title(mdata));
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(str);
|
|
|
|
str = tmp;
|
|
|
|
}
|
|
|
|
if (strstr(format, STRING_PLACEHOLDER) != NULL) {
|
2015-01-07 16:49:09 -05:00
|
|
|
tmp = replaceString(str, STRING_PLACEHOLDER,
|
|
|
|
metadata_get_string(mdata));
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(str);
|
|
|
|
str = tmp;
|
|
|
|
}
|
|
|
|
if (strstr(format, TRACK_PLACEHOLDER) != NULL) {
|
2015-01-07 16:49:09 -05:00
|
|
|
tmp = replaceString(str, TRACK_PLACEHOLDER,
|
|
|
|
metadata_get_filename(mdata));
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(str);
|
|
|
|
str = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (str);
|
|
|
|
}
|
|
|
|
|
2007-03-09 21:27:48 -05:00
|
|
|
metadata_t *
|
|
|
|
getMetadata(const char *fileName)
|
2007-02-24 22:10:13 -05:00
|
|
|
{
|
2007-03-09 21:27:48 -05:00
|
|
|
metadata_t *mdata;
|
2004-07-18 23:12:31 -04:00
|
|
|
|
2007-03-08 21:30:29 -05:00
|
|
|
if (metadataFromProgram) {
|
2015-04-16 08:27:39 -04:00
|
|
|
if ((mdata = metadata_program(fileName, cfg_normalize_strings())) == NULL)
|
2007-03-08 21:30:29 -05:00
|
|
|
return (NULL);
|
|
|
|
|
2007-03-09 21:27:48 -05:00
|
|
|
if (!metadata_program_update(mdata, METADATA_ALL)) {
|
2007-03-08 21:30:29 -05:00
|
|
|
metadata_free(&mdata);
|
2007-03-09 21:27:48 -05:00
|
|
|
return (NULL);
|
2007-03-08 21:30:29 -05:00
|
|
|
}
|
|
|
|
} else {
|
2015-04-16 08:27:39 -04:00
|
|
|
if ((mdata = metadata_file(fileName, cfg_normalize_strings())) == NULL)
|
2007-03-08 21:30:29 -05:00
|
|
|
return (NULL);
|
2007-02-24 22:10:13 -05:00
|
|
|
|
2007-03-08 21:30:29 -05:00
|
|
|
if (!metadata_file_update(mdata)) {
|
|
|
|
metadata_free(&mdata);
|
2007-03-09 21:27:48 -05:00
|
|
|
return (NULL);
|
2007-03-08 21:30:29 -05:00
|
|
|
}
|
2004-07-18 23:12:31 -04:00
|
|
|
}
|
2007-03-08 21:30:29 -05:00
|
|
|
|
2007-03-09 21:27:48 -05:00
|
|
|
return (mdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
setMetadata(shout_t *shout, metadata_t *mdata, char **mdata_copy)
|
|
|
|
{
|
|
|
|
shout_metadata_t *shout_mdata = NULL;
|
2007-08-30 07:31:33 -04:00
|
|
|
char *songInfo;
|
|
|
|
const char *artist, *title;
|
2007-03-09 21:27:48 -05:00
|
|
|
int ret = SHOUTERR_SUCCESS;
|
|
|
|
|
2015-04-16 08:27:39 -04:00
|
|
|
if (cfg_no_metadata_updates())
|
2015-01-03 17:19:28 -05:00
|
|
|
return (SHOUTERR_SUCCESS);
|
|
|
|
|
2007-03-09 21:27:48 -05:00
|
|
|
if (mdata == NULL)
|
|
|
|
return 1;
|
2004-07-18 23:12:31 -04:00
|
|
|
|
2007-03-08 09:39:00 -05:00
|
|
|
if ((shout_mdata = shout_metadata_new()) == NULL) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_syserr(ALERT, ENOMEM, "shout_metadata_new");
|
2007-02-24 22:10:13 -05:00
|
|
|
exit(1);
|
2004-07-18 23:12:31 -04:00
|
|
|
}
|
2007-03-09 21:27:48 -05:00
|
|
|
|
2007-08-30 07:31:33 -04:00
|
|
|
artist = metadata_get_artist(mdata);
|
|
|
|
title = metadata_get_title(mdata);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can do this, because we know how libshout works. This adds
|
|
|
|
* "charset=UTF-8" to the HTTP metadata update request and has the
|
|
|
|
* desired effect of letting newer-than-2.3.1 versions of Icecast know
|
|
|
|
* which encoding we're using.
|
|
|
|
*/
|
|
|
|
if (shout_metadata_add(shout_mdata, "charset", "UTF-8") != SHOUTERR_SUCCESS) {
|
|
|
|
/* Assume SHOUTERR_MALLOC */
|
2015-04-22 13:29:20 -04:00
|
|
|
log_syserr(ALERT, ENOMEM, "shout_metadata_add");
|
2007-08-30 07:31:33 -04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2007-03-10 14:03:07 -05:00
|
|
|
if ((songInfo = getMetadataString(pezConfig->metadataFormat, mdata)) == NULL) {
|
2007-08-30 07:31:33 -04:00
|
|
|
if (artist[0] == '\0' && title[0] == '\0')
|
2007-03-10 14:03:07 -05:00
|
|
|
songInfo = xstrdup(metadata_get_string(mdata));
|
|
|
|
else
|
|
|
|
songInfo = metadata_assemble_string(mdata);
|
2007-08-30 07:31:33 -04:00
|
|
|
if (artist[0] != '\0' && title[0] != '\0') {
|
|
|
|
if (shout_metadata_add(shout_mdata, "artist", artist) != SHOUTERR_SUCCESS) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_syserr(ALERT, ENOMEM,
|
|
|
|
"shout_metadata_add");
|
2007-08-30 07:31:33 -04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (shout_metadata_add(shout_mdata, "title", title) != SHOUTERR_SUCCESS) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_syserr(ALERT, ENOMEM,
|
|
|
|
"shout_metadata_add");
|
2007-08-30 07:31:33 -04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (shout_metadata_add(shout_mdata, "song", songInfo) != SHOUTERR_SUCCESS) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_syserr(ALERT, ENOMEM,
|
|
|
|
"shout_metadata_add");
|
2007-08-30 07:31:33 -04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (shout_metadata_add(shout_mdata, "song", songInfo) != SHOUTERR_SUCCESS) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_syserr(ALERT, ENOMEM, "shout_metadata_add");
|
2007-03-09 21:27:48 -05:00
|
|
|
exit(1);
|
|
|
|
}
|
2007-08-30 07:31:33 -04:00
|
|
|
|
2007-03-09 21:27:48 -05:00
|
|
|
if ((ret = shout_set_metadata(shout, shout_mdata)) != SHOUTERR_SUCCESS)
|
2015-04-22 13:29:20 -04:00
|
|
|
log_warning("shout_set_metadata: %s", shout_get_error(shout));
|
2007-08-30 07:31:33 -04:00
|
|
|
|
2007-03-08 09:39:00 -05:00
|
|
|
shout_metadata_free(shout_mdata);
|
2007-08-30 07:31:33 -04:00
|
|
|
|
|
|
|
if (ret == SHOUTERR_SUCCESS) {
|
|
|
|
if (mdata_copy != NULL && *mdata_copy == NULL)
|
|
|
|
*mdata_copy = xstrdup(songInfo);
|
|
|
|
}
|
2007-02-24 22:10:13 -05:00
|
|
|
|
2007-03-09 21:27:48 -05:00
|
|
|
xfree(songInfo);
|
|
|
|
return (ret);
|
2004-07-18 23:12:31 -04:00
|
|
|
}
|
|
|
|
|
2007-02-24 22:49:30 -05:00
|
|
|
FILE *
|
|
|
|
openResource(shout_t *shout, const char *fileName, int *popenFlag,
|
2009-03-16 16:22:56 -04:00
|
|
|
metadata_t **mdata_p, int *isStdin, long *songLen)
|
2004-07-18 23:12:31 -04:00
|
|
|
{
|
2007-03-09 21:27:48 -05:00
|
|
|
FILE *filep = NULL;
|
|
|
|
char extension[25];
|
|
|
|
char *p = NULL;
|
|
|
|
char *pCommandString = NULL;
|
|
|
|
metadata_t *mdata;
|
2005-12-14 16:13:25 -05:00
|
|
|
|
2007-10-16 10:28:23 -04:00
|
|
|
if (mdata_p != NULL)
|
|
|
|
*mdata_p = NULL;
|
2007-10-16 10:46:37 -04:00
|
|
|
if (songLen != NULL)
|
|
|
|
*songLen = 0;
|
2007-10-16 10:28:23 -04:00
|
|
|
|
2007-02-24 22:49:30 -05:00
|
|
|
if (strcmp(fileName, "stdin") == 0) {
|
2007-03-09 21:27:48 -05:00
|
|
|
if (metadataFromProgram) {
|
|
|
|
if ((mdata = getMetadata(pezConfig->metadataProgram)) == NULL)
|
|
|
|
return (NULL);
|
2007-08-23 09:48:42 -04:00
|
|
|
if (setMetadata(shout, mdata, NULL) != SHOUTERR_SUCCESS) {
|
2007-03-09 21:27:48 -05:00
|
|
|
metadata_free(&mdata);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2007-08-23 09:48:42 -04:00
|
|
|
if (mdata_p != NULL)
|
|
|
|
*mdata_p = mdata;
|
|
|
|
else
|
|
|
|
metadata_free(&mdata);
|
2007-03-09 21:27:48 -05:00
|
|
|
}
|
2007-03-08 21:30:29 -05:00
|
|
|
|
2007-02-24 22:49:30 -05:00
|
|
|
if (isStdin != NULL)
|
|
|
|
*isStdin = 1;
|
2004-07-18 23:12:31 -04:00
|
|
|
filep = stdin;
|
2007-02-24 22:49:30 -05:00
|
|
|
return (filep);
|
2004-01-30 12:19:45 -05:00
|
|
|
}
|
2007-03-09 21:27:48 -05:00
|
|
|
|
2007-02-24 22:49:30 -05:00
|
|
|
if (isStdin != NULL)
|
|
|
|
*isStdin = 0;
|
|
|
|
|
|
|
|
extension[0] = '\0';
|
2007-03-08 09:39:00 -05:00
|
|
|
p = strrchr(fileName, '.');
|
|
|
|
if (p != NULL)
|
|
|
|
strlcpy(extension, p, sizeof(extension));
|
|
|
|
for (p = extension; *p != '\0'; p++)
|
|
|
|
*p = tolower((int)*p);
|
|
|
|
|
|
|
|
if (strlen(extension) == 0) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("%s: cannot determine file type", fileName);
|
2007-03-08 09:39:00 -05:00
|
|
|
return (filep);
|
|
|
|
}
|
|
|
|
|
2007-03-09 21:27:48 -05:00
|
|
|
if (metadataFromProgram) {
|
|
|
|
if ((mdata = getMetadata(pezConfig->metadataProgram)) == NULL)
|
|
|
|
return (NULL);
|
|
|
|
} else {
|
|
|
|
if ((mdata = getMetadata(fileName)) == NULL)
|
|
|
|
return (NULL);
|
|
|
|
}
|
2007-03-10 16:18:21 -05:00
|
|
|
if (songLen != NULL)
|
|
|
|
*songLen = metadata_get_length(mdata);
|
2007-02-24 22:49:30 -05:00
|
|
|
|
|
|
|
*popenFlag = 0;
|
|
|
|
if (pezConfig->reencode) {
|
2007-07-24 09:04:01 -04:00
|
|
|
int stderr_fd = -1;
|
2007-03-08 09:39:00 -05:00
|
|
|
|
2007-03-09 21:27:48 -05:00
|
|
|
pCommandString = buildCommandString(extension, fileName, mdata);
|
2007-08-23 09:48:42 -04:00
|
|
|
if (mdata_p != NULL)
|
|
|
|
*mdata_p = mdata;
|
|
|
|
else
|
|
|
|
metadata_free(&mdata);
|
2015-04-22 13:29:20 -04:00
|
|
|
log_info("running command: %s", pCommandString);
|
2007-03-08 09:39:00 -05:00
|
|
|
|
2015-04-16 08:27:39 -04:00
|
|
|
if (cfg_quiet_stderr()) {
|
2007-03-08 09:39:00 -05:00
|
|
|
int fd;
|
|
|
|
|
2007-07-24 09:04:01 -04:00
|
|
|
stderr_fd = dup(fileno(stderr));
|
2007-03-08 09:39:00 -05:00
|
|
|
if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) == -1) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_alert("%s: %s", _PATH_DEVNULL,
|
|
|
|
strerror(errno));
|
2007-03-08 09:39:00 -05:00
|
|
|
exit(1);
|
2007-02-28 20:22:06 -05:00
|
|
|
}
|
|
|
|
|
2007-03-08 09:39:00 -05:00
|
|
|
dup2(fd, fileno(stderr));
|
|
|
|
if (fd > 2)
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
fflush(NULL);
|
|
|
|
errno = 0;
|
|
|
|
if ((filep = popen(pCommandString, "r")) == NULL) {
|
|
|
|
/* popen() does not set errno reliably ... */
|
|
|
|
if (errno)
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("execution error: %s: %s",
|
|
|
|
pCommandString, strerror(errno));
|
2007-03-08 09:39:00 -05:00
|
|
|
else
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("execution error: %s",
|
|
|
|
pCommandString);
|
2007-03-08 09:39:00 -05:00
|
|
|
} else {
|
|
|
|
*popenFlag = 1;
|
|
|
|
}
|
|
|
|
xfree(pCommandString);
|
2007-02-28 20:22:06 -05:00
|
|
|
|
2015-04-16 08:27:39 -04:00
|
|
|
if (cfg_quiet_stderr())
|
2007-03-08 09:39:00 -05:00
|
|
|
dup2(stderr_fd, fileno(stderr));
|
2007-07-24 09:04:01 -04:00
|
|
|
|
|
|
|
if (stderr_fd > 2)
|
|
|
|
close(stderr_fd);
|
2004-07-18 23:12:31 -04:00
|
|
|
|
2007-02-24 22:49:30 -05:00
|
|
|
return (filep);
|
2007-08-23 09:48:42 -04:00
|
|
|
}
|
2007-02-24 22:49:30 -05:00
|
|
|
|
2007-08-23 09:48:42 -04:00
|
|
|
if (mdata_p != NULL)
|
|
|
|
*mdata_p = mdata;
|
|
|
|
else
|
|
|
|
metadata_free(&mdata);
|
2007-02-24 22:49:30 -05:00
|
|
|
|
2015-04-22 13:29:20 -04:00
|
|
|
if ((filep = fopen(fileName, "rb")) == NULL) {
|
|
|
|
log_error("%s: %s", fileName, strerror(errno));
|
|
|
|
return (NULL);
|
|
|
|
}
|
2007-02-24 22:49:30 -05:00
|
|
|
|
|
|
|
return (filep);
|
2004-07-18 23:12:31 -04:00
|
|
|
}
|
|
|
|
|
2007-03-01 19:57:11 -05:00
|
|
|
int
|
|
|
|
reconnectServer(shout_t *shout, int closeConn)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
int close_conn = closeConn;
|
|
|
|
|
2015-04-22 13:29:20 -04:00
|
|
|
log_warning("%s: connection lost", pezConfig->URL);
|
2007-03-01 19:57:11 -05:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (++i) {
|
|
|
|
if (pezConfig->reconnectAttempts > 0)
|
2015-04-22 13:29:20 -04:00
|
|
|
log_notice("reconnect: %s: attempt #%u/%u ...",
|
|
|
|
pezConfig->URL, i, pezConfig->reconnectAttempts);
|
2007-03-01 19:57:11 -05:00
|
|
|
else
|
2015-04-22 13:29:20 -04:00
|
|
|
log_notice("reconnect: %s: attempt #%u ...",
|
|
|
|
pezConfig->URL, i);
|
2007-03-01 19:57:11 -05:00
|
|
|
|
|
|
|
if (close_conn == 0)
|
|
|
|
close_conn = 1;
|
|
|
|
else
|
|
|
|
shout_close(shout);
|
|
|
|
if (shout_open(shout) == SHOUTERR_SUCCESS) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_notice("reconnect: %s: success",
|
|
|
|
pezConfig->URL);
|
2007-03-01 19:57:11 -05:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2015-04-22 13:29:20 -04:00
|
|
|
log_warning("reconnect failed: %s: %s",
|
|
|
|
pezConfig->URL, shout_get_error(shout));
|
2007-03-01 19:57:11 -05:00
|
|
|
|
|
|
|
if (pezConfig->reconnectAttempts > 0 &&
|
|
|
|
i >= pezConfig->reconnectAttempts)
|
|
|
|
break;
|
|
|
|
|
2007-08-04 13:04:50 -04:00
|
|
|
if (quit)
|
|
|
|
return (0);
|
|
|
|
else
|
|
|
|
sleep(5);
|
2007-03-01 19:57:11 -05:00
|
|
|
};
|
|
|
|
|
2015-04-22 13:29:20 -04:00
|
|
|
log_warning("reconnect failed: giving up");
|
2007-03-01 19:57:11 -05:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2007-03-10 16:18:21 -05:00
|
|
|
const char *
|
2009-03-16 16:22:56 -04:00
|
|
|
getTimeString(long seconds)
|
2007-03-10 16:18:21 -05:00
|
|
|
{
|
|
|
|
static char str[20];
|
2009-03-16 16:22:56 -04:00
|
|
|
long secs, mins, hours;
|
2007-03-10 16:18:21 -05:00
|
|
|
|
|
|
|
if (seconds < 0)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
secs = seconds;
|
|
|
|
hours = secs / 3600;
|
|
|
|
secs %= 3600;
|
|
|
|
mins = secs / 60;
|
|
|
|
secs %= 60;
|
|
|
|
|
2009-03-16 16:22:56 -04:00
|
|
|
snprintf(str, sizeof(str), "%ldh%02ldm%02lds", hours, mins, secs);
|
2007-03-10 16:18:21 -05:00
|
|
|
return ((const char *)str);
|
|
|
|
}
|
|
|
|
|
2007-02-24 22:49:30 -05:00
|
|
|
int
|
2007-02-25 13:28:05 -05:00
|
|
|
sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
|
2007-08-31 07:47:54 -04:00
|
|
|
int isStdin, const char *songLenStr, struct timeval *tv)
|
2007-02-24 22:49:30 -05:00
|
|
|
{
|
|
|
|
unsigned char buff[4096];
|
2009-03-15 13:18:56 -04:00
|
|
|
size_t bytes_read, total, oldTotal;
|
2007-03-01 19:57:11 -05:00
|
|
|
int ret;
|
2007-02-24 22:49:30 -05:00
|
|
|
double kbps = -1.0;
|
2007-08-31 07:47:54 -04:00
|
|
|
struct timeval timeStamp, *startTime = tv;
|
2010-06-21 14:39:26 -04:00
|
|
|
struct timeval callTime, currentTime;
|
2007-02-24 22:49:30 -05:00
|
|
|
|
2010-06-21 14:39:26 -04:00
|
|
|
ez_gettimeofday((void *)&callTime);
|
|
|
|
|
2007-02-25 13:28:05 -05:00
|
|
|
timeStamp.tv_sec = startTime->tv_sec;
|
|
|
|
timeStamp.tv_usec = startTime->tv_usec;
|
2007-02-24 22:49:30 -05:00
|
|
|
|
|
|
|
total = oldTotal = 0;
|
2007-03-01 19:57:11 -05:00
|
|
|
ret = STREAM_DONE;
|
2009-03-16 16:22:56 -04:00
|
|
|
while ((bytes_read = fread(buff, 1UL, sizeof(buff), filepstream)) > 0) {
|
2007-03-01 19:57:11 -05:00
|
|
|
if (shout_get_connected(shout) != SHOUTERR_CONNECTED &&
|
|
|
|
reconnectServer(shout, 0) == 0) {
|
|
|
|
ret = STREAM_SERVERR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-08 21:30:29 -05:00
|
|
|
shout_sync(shout);
|
|
|
|
|
2009-03-15 13:18:56 -04:00
|
|
|
if (shout_send(shout, buff, bytes_read) != SHOUTERR_SUCCESS) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("shout_send: %s", shout_get_error(shout));
|
2007-03-08 21:30:29 -05:00
|
|
|
if (reconnectServer(shout, 1))
|
|
|
|
break;
|
|
|
|
else {
|
|
|
|
ret = STREAM_SERVERR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-04 13:04:50 -04:00
|
|
|
if (quit)
|
|
|
|
break;
|
2007-02-25 13:28:05 -05:00
|
|
|
if (rereadPlaylist_notify) {
|
|
|
|
rereadPlaylist_notify = 0;
|
2007-02-28 16:26:16 -05:00
|
|
|
if (!pezConfig->fileNameIsProgram)
|
2015-04-22 13:29:20 -04:00
|
|
|
log_notice("HUP signal received: playlist re-read scheduled");
|
2007-02-25 13:28:05 -05:00
|
|
|
}
|
|
|
|
if (skipTrack) {
|
|
|
|
skipTrack = 0;
|
2007-03-01 19:57:11 -05:00
|
|
|
ret = STREAM_SKIP;
|
2007-02-25 13:28:05 -05:00
|
|
|
break;
|
|
|
|
}
|
2010-06-21 14:39:26 -04:00
|
|
|
|
|
|
|
ez_gettimeofday((void *)¤tTime);
|
|
|
|
|
|
|
|
if (queryMetadata ||
|
|
|
|
(pezConfig->metadataRefreshInterval != -1
|
2015-04-13 17:28:21 -04:00
|
|
|
&& (currentTime.tv_sec - callTime.tv_sec
|
|
|
|
>= pezConfig->metadataRefreshInterval)
|
|
|
|
)
|
|
|
|
) {
|
2007-03-08 21:30:29 -05:00
|
|
|
queryMetadata = 0;
|
|
|
|
if (metadataFromProgram) {
|
|
|
|
ret = STREAM_UPDMDATA;
|
2007-03-01 19:57:11 -05:00
|
|
|
break;
|
2004-01-30 12:19:45 -05:00
|
|
|
}
|
2007-02-24 22:49:30 -05:00
|
|
|
}
|
|
|
|
|
2009-03-15 13:18:56 -04:00
|
|
|
total += bytes_read;
|
2015-04-16 08:27:39 -04:00
|
|
|
if (cfg_quiet_stderr() && cfg_verbosity()) {
|
2010-06-21 14:39:26 -04:00
|
|
|
double oldTime, newTime;
|
2007-02-24 22:49:30 -05:00
|
|
|
|
2007-02-28 16:26:16 -05:00
|
|
|
if (!isStdin && playlistMode) {
|
|
|
|
if (pezConfig->fileNameIsProgram) {
|
|
|
|
char *tmp = xstrdup(pezConfig->fileName);
|
2015-04-15 17:16:12 -04:00
|
|
|
printf(" [%s]", basename(tmp));
|
2007-02-28 16:26:16 -05:00
|
|
|
xfree(tmp);
|
|
|
|
} else
|
|
|
|
printf(" [%4lu/%-4lu]",
|
2015-04-13 17:28:21 -04:00
|
|
|
playlist_get_position(playlist),
|
|
|
|
playlist_get_num_items(playlist));
|
2007-02-28 16:26:16 -05:00
|
|
|
}
|
2007-02-24 22:49:30 -05:00
|
|
|
|
|
|
|
oldTime = (double)timeStamp.tv_sec
|
2015-04-13 17:28:21 -04:00
|
|
|
+ (double)timeStamp.tv_usec / 1000000.0;
|
2010-06-21 14:39:26 -04:00
|
|
|
newTime = (double)currentTime.tv_sec
|
2015-04-13 17:28:21 -04:00
|
|
|
+ (double)currentTime.tv_usec / 1000000.0;
|
2007-03-10 16:18:21 -05:00
|
|
|
if (songLenStr == NULL)
|
|
|
|
printf(" [ %s]",
|
2015-04-13 17:28:21 -04:00
|
|
|
getTimeString(currentTime.tv_sec -
|
|
|
|
startTime->tv_sec));
|
2007-03-10 16:18:21 -05:00
|
|
|
else
|
|
|
|
printf(" [ %s/%s]",
|
2015-04-13 17:28:21 -04:00
|
|
|
getTimeString(currentTime.tv_sec -
|
|
|
|
startTime->tv_sec),
|
|
|
|
songLenStr);
|
2007-02-24 22:49:30 -05:00
|
|
|
if (newTime - oldTime >= 1.0) {
|
2010-06-21 14:39:26 -04:00
|
|
|
kbps = (((double)(total - oldTotal)
|
2015-04-13 17:28:21 -04:00
|
|
|
/ (newTime - oldTime)) * 8.0) / 1000.0;
|
2010-06-21 14:39:26 -04:00
|
|
|
timeStamp.tv_sec = currentTime.tv_sec;
|
|
|
|
timeStamp.tv_usec = currentTime.tv_usec;
|
2007-02-24 22:49:30 -05:00
|
|
|
oldTotal = total;
|
|
|
|
}
|
|
|
|
if (kbps < 0)
|
|
|
|
printf(" ");
|
|
|
|
else
|
|
|
|
printf(" [%8.2f kbps]", kbps);
|
|
|
|
|
|
|
|
printf(" \r");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
2004-01-30 12:19:45 -05:00
|
|
|
}
|
2007-02-25 11:00:41 -05:00
|
|
|
if (ferror(filepstream)) {
|
|
|
|
if (errno == EINTR) {
|
|
|
|
clearerr(filepstream);
|
2007-03-01 19:57:11 -05:00
|
|
|
ret = STREAM_CONT;
|
2007-10-16 10:44:42 -04:00
|
|
|
} else if (errno == EBADF && isStdin)
|
2015-04-22 13:29:20 -04:00
|
|
|
log_notice("no (more) data available on standard input");
|
2007-10-16 10:44:42 -04:00
|
|
|
else
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("sendStream: %s: %s", fileName,
|
|
|
|
strerror(errno));
|
2007-02-25 13:28:05 -05:00
|
|
|
}
|
|
|
|
|
2007-02-28 16:26:16 -05:00
|
|
|
return (ret);
|
2007-02-25 13:28:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
streamFile(shout_t *shout, const char *fileName)
|
|
|
|
{
|
|
|
|
FILE *filepstream = NULL;
|
|
|
|
int popenFlag = 0;
|
2007-08-23 09:48:42 -04:00
|
|
|
char *songLenStr = NULL;
|
2007-02-25 13:28:05 -05:00
|
|
|
int isStdin = 0;
|
2009-03-16 16:22:56 -04:00
|
|
|
int ret, retval = 0;
|
|
|
|
long songLen;
|
2007-08-23 09:48:42 -04:00
|
|
|
metadata_t *mdata;
|
2007-02-25 13:28:05 -05:00
|
|
|
struct timeval startTime;
|
|
|
|
|
2015-04-13 17:28:21 -04:00
|
|
|
if ((filepstream = openResource(shout, fileName, &popenFlag, &mdata, &isStdin, &songLen))
|
2009-08-29 05:36:18 -04:00
|
|
|
== NULL) {
|
|
|
|
if (++resource_errors > 100) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("too many errors; giving up");
|
2009-08-29 05:36:18 -04:00
|
|
|
return (0);
|
|
|
|
}
|
2009-08-22 06:03:45 -04:00
|
|
|
/* Continue with next resource on failure: */
|
|
|
|
return (1);
|
2009-08-29 05:36:18 -04:00
|
|
|
}
|
|
|
|
resource_errors = 0;
|
2007-02-25 13:28:05 -05:00
|
|
|
|
2007-08-23 09:48:42 -04:00
|
|
|
if (mdata != NULL) {
|
2007-08-24 07:57:09 -04:00
|
|
|
char *tmp, *metaData;
|
2007-08-23 09:48:42 -04:00
|
|
|
|
2007-08-24 07:57:09 -04:00
|
|
|
tmp = metadata_assemble_string(mdata);
|
2007-10-18 03:39:18 -04:00
|
|
|
if ((metaData = UTF8toCHAR(tmp, ICONV_REPLACE)) == NULL)
|
|
|
|
metaData = xstrdup("(unknown title)");
|
2007-08-24 07:57:09 -04:00
|
|
|
xfree(tmp);
|
2015-04-22 13:29:20 -04:00
|
|
|
log_notice("streaming: %s (%s)", metaData, fileName);
|
2007-02-25 13:28:05 -05:00
|
|
|
xfree(metaData);
|
2007-08-23 09:48:42 -04:00
|
|
|
|
|
|
|
/* MP3 streams are special, so set the metadata explicitly: */
|
|
|
|
if (strcmp(pezConfig->format, MP3_FORMAT) == 0)
|
|
|
|
setMetadata(shout, mdata, NULL);
|
|
|
|
|
|
|
|
metadata_free(&mdata);
|
2007-10-18 03:39:18 -04:00
|
|
|
} else if (isStdin)
|
2015-04-22 13:29:20 -04:00
|
|
|
log_notice("streaming: standard input");
|
2007-02-25 13:28:05 -05:00
|
|
|
|
2007-10-16 10:51:21 -04:00
|
|
|
if (songLen > 0)
|
2007-03-10 16:18:21 -05:00
|
|
|
songLenStr = xstrdup(getTimeString(songLen));
|
2007-08-31 07:47:54 -04:00
|
|
|
ez_gettimeofday((void *)&startTime);
|
2007-02-25 13:28:05 -05:00
|
|
|
do {
|
|
|
|
ret = sendStream(shout, filepstream, fileName, isStdin,
|
2015-04-13 17:28:21 -04:00
|
|
|
songLenStr, &startTime);
|
2007-08-04 13:04:50 -04:00
|
|
|
if (quit)
|
|
|
|
break;
|
2007-03-01 19:57:11 -05:00
|
|
|
if (ret != STREAM_DONE) {
|
2007-03-08 21:30:29 -05:00
|
|
|
if ((skipTrack && rereadPlaylist) ||
|
|
|
|
(skipTrack && queryMetadata)) {
|
2007-02-25 13:28:05 -05:00
|
|
|
skipTrack = 0;
|
2007-03-08 21:30:29 -05:00
|
|
|
ret = STREAM_CONT;
|
|
|
|
}
|
|
|
|
if (queryMetadata && rereadPlaylist) {
|
|
|
|
queryMetadata = 0;
|
|
|
|
ret = STREAM_CONT;
|
2007-02-25 13:28:05 -05:00
|
|
|
}
|
2007-03-01 19:57:11 -05:00
|
|
|
if (ret == STREAM_SKIP || skipTrack) {
|
2007-02-25 13:28:05 -05:00
|
|
|
skipTrack = 0;
|
2015-04-22 13:29:20 -04:00
|
|
|
if (!isStdin)
|
|
|
|
log_notice("USR1 signal received: skipping current track");
|
2007-02-25 13:28:05 -05:00
|
|
|
retval = 1;
|
2007-03-01 19:57:11 -05:00
|
|
|
ret = STREAM_DONE;
|
|
|
|
}
|
2007-03-08 21:30:29 -05:00
|
|
|
if (ret == STREAM_UPDMDATA || queryMetadata) {
|
|
|
|
queryMetadata = 0;
|
2015-04-16 08:27:39 -04:00
|
|
|
if (cfg_no_metadata_updates())
|
2015-01-03 17:19:28 -05:00
|
|
|
continue;
|
2007-03-08 21:30:29 -05:00
|
|
|
if (metadataFromProgram) {
|
2007-03-09 21:27:48 -05:00
|
|
|
char *mdataStr = NULL;
|
2007-08-23 09:48:42 -04:00
|
|
|
metadata_t *prog_mdata;
|
2007-03-08 21:30:29 -05:00
|
|
|
|
2015-04-22 13:29:20 -04:00
|
|
|
log_info("running metadata program: %s",
|
|
|
|
pezConfig->metadataProgram);
|
2007-08-23 09:48:42 -04:00
|
|
|
if ((prog_mdata = getMetadata(pezConfig->metadataProgram)) == NULL) {
|
2007-03-09 21:27:48 -05:00
|
|
|
retval = 0;
|
|
|
|
ret = STREAM_DONE;
|
|
|
|
continue;
|
|
|
|
}
|
2007-08-23 09:48:42 -04:00
|
|
|
if (setMetadata(shout, prog_mdata, &mdataStr) != SHOUTERR_SUCCESS) {
|
2007-03-08 21:30:29 -05:00
|
|
|
retval = 0;
|
|
|
|
ret = STREAM_DONE;
|
2007-03-09 21:27:48 -05:00
|
|
|
continue;
|
2007-03-08 21:30:29 -05:00
|
|
|
}
|
2007-08-23 09:48:42 -04:00
|
|
|
metadata_free(&prog_mdata);
|
2015-04-22 13:29:20 -04:00
|
|
|
log_info("new metadata: %s", mdataStr);
|
2007-03-08 21:30:29 -05:00
|
|
|
xfree(mdataStr);
|
|
|
|
}
|
|
|
|
}
|
2007-03-01 19:57:11 -05:00
|
|
|
if (ret == STREAM_SERVERR) {
|
|
|
|
retval = 0;
|
|
|
|
ret = STREAM_DONE;
|
2007-02-25 13:28:05 -05:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
retval = 1;
|
2007-03-08 21:30:29 -05:00
|
|
|
} while (ret != STREAM_DONE);
|
2007-02-24 22:49:30 -05:00
|
|
|
|
|
|
|
if (popenFlag)
|
2005-12-14 16:13:25 -05:00
|
|
|
pclose(filepstream);
|
2015-01-02 18:08:12 -05:00
|
|
|
else if (!isStdin)
|
2005-12-14 16:13:25 -05:00
|
|
|
fclose(filepstream);
|
2007-02-24 22:49:30 -05:00
|
|
|
|
2007-03-10 16:18:21 -05:00
|
|
|
if (songLenStr != NULL)
|
|
|
|
xfree(songLenStr);
|
|
|
|
|
2007-02-24 22:49:30 -05:00
|
|
|
return (retval);
|
2004-01-30 12:19:45 -05:00
|
|
|
}
|
2007-02-24 19:25:07 -05:00
|
|
|
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
int
|
|
|
|
streamPlaylist(shout_t *shout, const char *fileName)
|
|
|
|
{
|
|
|
|
const char *song;
|
2007-03-08 16:38:12 -05:00
|
|
|
char lastSong[PATH_MAX];
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
|
|
|
|
if (playlist == NULL) {
|
2007-02-28 16:26:16 -05:00
|
|
|
if (pezConfig->fileNameIsProgram) {
|
|
|
|
if ((playlist = playlist_program(fileName)) == NULL)
|
|
|
|
return (0);
|
|
|
|
} else {
|
|
|
|
if ((playlist = playlist_read(fileName)) == NULL)
|
|
|
|
return (0);
|
2015-04-22 13:29:20 -04:00
|
|
|
if (playlist_get_num_items(playlist) == 0)
|
|
|
|
log_notice("%s: playlist empty", fileName);
|
2007-02-28 16:26:16 -05:00
|
|
|
}
|
2007-09-14 03:01:18 -04:00
|
|
|
} else {
|
2007-02-28 16:26:16 -05:00
|
|
|
/*
|
|
|
|
* XXX: This preserves traditional behavior, however,
|
|
|
|
* rereading the playlist after each walkthrough seems a
|
|
|
|
* bit more logical.
|
|
|
|
*/
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
playlist_rewind(playlist);
|
2007-09-14 03:01:18 -04:00
|
|
|
}
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
|
2007-02-28 16:26:16 -05:00
|
|
|
if (!pezConfig->fileNameIsProgram && pezConfig->shuffle)
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
playlist_shuffle(playlist);
|
|
|
|
|
|
|
|
while ((song = playlist_get_next(playlist)) != NULL) {
|
|
|
|
strlcpy(lastSong, song, sizeof(lastSong));
|
|
|
|
if (!streamFile(shout, song))
|
|
|
|
return (0);
|
2007-08-04 13:04:50 -04:00
|
|
|
if (quit)
|
|
|
|
break;
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
if (rereadPlaylist) {
|
|
|
|
rereadPlaylist = rereadPlaylist_notify = 0;
|
2007-02-28 16:26:16 -05:00
|
|
|
if (pezConfig->fileNameIsProgram)
|
|
|
|
continue;
|
2015-04-22 13:29:20 -04:00
|
|
|
log_notice("rereading playlist");
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
if (!playlist_reread(&playlist))
|
|
|
|
return (0);
|
|
|
|
if (pezConfig->shuffle)
|
|
|
|
playlist_shuffle(playlist);
|
|
|
|
else {
|
|
|
|
playlist_goto_entry(playlist, lastSong);
|
|
|
|
playlist_skip_next(playlist);
|
2004-01-30 12:19:45 -05:00
|
|
|
}
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
continue;
|
2004-07-18 23:12:31 -04:00
|
|
|
}
|
2004-01-30 12:19:45 -05:00
|
|
|
}
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
|
2007-03-08 21:30:29 -05:00
|
|
|
return (1);
|
2004-01-30 12:19:45 -05:00
|
|
|
}
|
|
|
|
|
2007-08-02 14:48:26 -04:00
|
|
|
int
|
2007-08-08 09:15:04 -04:00
|
|
|
ez_shutdown(int exitval)
|
2007-08-02 14:48:26 -04:00
|
|
|
{
|
|
|
|
shout_shutdown();
|
|
|
|
playlist_shutdown();
|
2007-08-04 13:04:50 -04:00
|
|
|
freeConfig(pezConfig);
|
2015-04-16 13:22:58 -04:00
|
|
|
log_exit();
|
2007-08-02 14:48:26 -04:00
|
|
|
|
|
|
|
return (exitval);
|
|
|
|
}
|
|
|
|
|
2007-02-24 19:25:07 -05:00
|
|
|
int
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
main(int argc, char *argv[])
|
2004-01-30 12:19:45 -05:00
|
|
|
{
|
2015-04-16 08:27:39 -04:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
const char *configFile;
|
|
|
|
const char *playlistFile;
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
char *host = NULL;
|
2009-03-15 13:18:56 -04:00
|
|
|
unsigned short port = 0;
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
char *mount = NULL;
|
|
|
|
shout_t *shout;
|
|
|
|
extern char *optarg;
|
|
|
|
extern int optind;
|
2007-02-25 11:00:41 -05:00
|
|
|
#ifdef HAVE_SIGNALS
|
|
|
|
struct sigaction act;
|
2007-02-28 08:53:58 -05:00
|
|
|
unsigned int i;
|
2007-02-25 11:00:41 -05:00
|
|
|
#endif
|
2015-04-16 08:27:39 -04:00
|
|
|
ret = 1;
|
|
|
|
if (0 > cfg_cmdline_parse(argc, argv, &ret))
|
|
|
|
return (ret);
|
2015-04-16 13:22:58 -04:00
|
|
|
log_init();
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
|
2007-08-02 14:48:26 -04:00
|
|
|
playlist_init();
|
|
|
|
shout_init();
|
|
|
|
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
pezConfig = getEZConfig();
|
2004-01-30 12:19:45 -05:00
|
|
|
|
2015-04-16 08:27:39 -04:00
|
|
|
playlistFile = cfg_shuffle_file();
|
|
|
|
if (playlistFile) {
|
2009-08-30 17:55:24 -04:00
|
|
|
playlist_t *pl;
|
|
|
|
const char *entry;
|
|
|
|
|
2015-04-15 18:08:43 -04:00
|
|
|
if (0 == strcmp(playlistFile, "-"))
|
2009-08-30 17:55:24 -04:00
|
|
|
pl = playlist_read(NULL);
|
2015-04-15 18:08:43 -04:00
|
|
|
else
|
|
|
|
pl = playlist_read(playlistFile);
|
|
|
|
|
|
|
|
if (pl == NULL)
|
|
|
|
return (ez_shutdown(1));
|
2009-08-30 17:55:24 -04:00
|
|
|
|
|
|
|
playlist_shuffle(pl);
|
|
|
|
while ((entry = playlist_get_next(pl)) != NULL)
|
|
|
|
printf("%s\n", entry);
|
|
|
|
|
|
|
|
playlist_free(&pl);
|
|
|
|
|
|
|
|
return (ez_shutdown(0));
|
|
|
|
}
|
|
|
|
|
2015-04-16 08:27:39 -04:00
|
|
|
configFile = cfg_config_file();
|
|
|
|
{
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
/*
|
|
|
|
* Attempt to open configFile here for a more meaningful error
|
2007-02-28 10:35:07 -05:00
|
|
|
* message. Where possible, do it with stat() and check for
|
|
|
|
* safe config file permissions.
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
*/
|
2007-02-28 10:35:07 -05:00
|
|
|
#ifdef HAVE_STAT
|
2015-04-16 08:27:39 -04:00
|
|
|
struct stat st;
|
2007-02-28 10:35:07 -05:00
|
|
|
|
|
|
|
if (stat(configFile, &st) == -1) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("%s: %s", configFile, strerror(errno));
|
2007-08-08 09:15:04 -04:00
|
|
|
return (ez_shutdown(2));
|
2007-02-28 10:35:07 -05:00
|
|
|
}
|
2015-04-16 08:27:39 -04:00
|
|
|
if (cfg_verbosity() && (st.st_mode & (S_IRGRP | S_IROTH)))
|
2015-04-22 13:29:20 -04:00
|
|
|
log_warning("%s: group and/or world readable",
|
|
|
|
configFile);
|
2007-02-28 10:35:07 -05:00
|
|
|
if (st.st_mode & (S_IWGRP | S_IWOTH)) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("%s: group and/or world writeable",
|
|
|
|
configFile);
|
2007-08-08 09:15:04 -04:00
|
|
|
return (ez_shutdown(2));
|
2007-02-28 10:35:07 -05:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
FILE *tmp;
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
|
|
|
|
if ((tmp = fopen(configFile, "r")) == NULL) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("%s: %s", configFile, strerror(errno));
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
usage();
|
2007-08-08 09:15:04 -04:00
|
|
|
return (ez_shutdown(2));
|
2007-02-28 10:35:07 -05:00
|
|
|
}
|
|
|
|
fclose(tmp);
|
|
|
|
#endif /* HAVE_STAT */
|
2004-01-30 12:19:45 -05:00
|
|
|
}
|
2004-07-18 23:12:31 -04:00
|
|
|
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
if (!parseConfig(configFile))
|
2007-08-08 09:15:04 -04:00
|
|
|
return (ez_shutdown(2));
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
|
|
|
|
if (pezConfig->URL == NULL) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("%s: missing <url>", configFile);
|
2007-08-08 09:15:04 -04:00
|
|
|
return (ez_shutdown(2));
|
2004-01-30 12:19:45 -05:00
|
|
|
}
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
if (!urlParse(pezConfig->URL, &host, &port, &mount)) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("%s: <url>: must be of the form ``http://server:port/mountpoint''",
|
|
|
|
configFile);
|
2007-08-08 09:15:04 -04:00
|
|
|
return (ez_shutdown(2));
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
}
|
2007-03-02 07:52:10 -05:00
|
|
|
if (pezConfig->password == NULL) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("%s: <sourcepassword> missing", configFile);
|
2007-08-08 09:15:04 -04:00
|
|
|
return (ez_shutdown(2));
|
2004-01-30 12:19:45 -05:00
|
|
|
}
|
2007-03-02 07:52:10 -05:00
|
|
|
if (pezConfig->fileName == NULL) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("%s: <filename> missing", configFile);
|
2007-08-08 09:15:04 -04:00
|
|
|
return (ez_shutdown(2));
|
2004-01-30 12:19:45 -05:00
|
|
|
}
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
if (pezConfig->format == NULL) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("%s: <format> missing or unsupported value",
|
|
|
|
configFile);
|
2004-01-30 12:19:45 -05:00
|
|
|
}
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
|
2007-08-22 11:15:49 -04:00
|
|
|
if ((shout = stream_setup(host, port, mount)) == NULL)
|
2007-08-08 09:15:04 -04:00
|
|
|
return (ez_shutdown(1));
|
2004-01-30 12:19:45 -05:00
|
|
|
|
2007-03-08 21:30:29 -05:00
|
|
|
if (pezConfig->metadataProgram != NULL)
|
|
|
|
metadataFromProgram = 1;
|
|
|
|
else
|
|
|
|
metadataFromProgram = 0;
|
|
|
|
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
#ifdef HAVE_SIGNALS
|
2007-02-25 11:00:41 -05:00
|
|
|
memset(&act, 0, sizeof(act));
|
|
|
|
act.sa_handler = sig_handler;
|
|
|
|
# ifdef SA_RESTART
|
|
|
|
act.sa_flags = SA_RESTART;
|
|
|
|
# endif
|
2007-02-28 08:53:58 -05:00
|
|
|
for (i = 0; i < sizeof(ezstream_signals) / sizeof(int); i++) {
|
|
|
|
if (sigaction(ezstream_signals[i], &act, NULL) == -1) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_syserr(ERROR, errno, "sigaction");
|
2007-08-08 09:15:04 -04:00
|
|
|
return (ez_shutdown(1));
|
2007-02-28 08:53:58 -05:00
|
|
|
}
|
|
|
|
}
|
2007-12-01 11:02:55 -05:00
|
|
|
/*
|
|
|
|
* Ignore SIGPIPE, which has been seen to give a long-running ezstream
|
|
|
|
* process trouble. EOF and/or EPIPE are also easier to handle.
|
|
|
|
*/
|
|
|
|
act.sa_handler = SIG_IGN;
|
|
|
|
if (sigaction(SIGPIPE, &act, NULL) == -1) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_syserr(ERROR, errno, "sigaction");
|
2007-12-01 11:02:55 -05:00
|
|
|
return (ez_shutdown(1));
|
|
|
|
}
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
#endif /* HAVE_SIGNALS */
|
|
|
|
|
|
|
|
if (shout_open(shout) == SHOUTERR_SUCCESS) {
|
2015-04-16 08:27:39 -04:00
|
|
|
int cont;
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
|
2015-04-22 13:29:20 -04:00
|
|
|
log_notice("connected: http://%s:%hu%s", host, port, mount);
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
|
2007-02-28 16:26:16 -05:00
|
|
|
if (pezConfig->fileNameIsProgram ||
|
2007-08-13 23:32:13 -04:00
|
|
|
strrcasecmp(pezConfig->fileName, ".m3u") == 0 ||
|
|
|
|
strrcasecmp(pezConfig->fileName, ".txt") == 0)
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
playlistMode = 1;
|
|
|
|
else
|
|
|
|
playlistMode = 0;
|
|
|
|
|
|
|
|
do {
|
2007-07-15 20:32:17 -04:00
|
|
|
if (playlistMode) {
|
2015-04-16 08:27:39 -04:00
|
|
|
cont = streamPlaylist(shout, pezConfig->fileName);
|
2007-07-15 20:32:17 -04:00
|
|
|
} else {
|
2015-04-16 08:27:39 -04:00
|
|
|
cont = streamFile(shout, pezConfig->fileName);
|
2007-02-28 16:48:01 -05:00
|
|
|
}
|
2007-08-04 13:04:50 -04:00
|
|
|
if (quit)
|
|
|
|
break;
|
2007-07-15 20:32:17 -04:00
|
|
|
if (pezConfig->streamOnce)
|
|
|
|
break;
|
2015-04-16 08:27:39 -04:00
|
|
|
} while (cont);
|
2007-08-02 14:48:26 -04:00
|
|
|
|
|
|
|
shout_close(shout);
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
} else
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("connection failed: http://%s:%hu%s: %s",
|
2015-04-13 17:28:21 -04:00
|
|
|
host, port, mount, shout_get_error(shout));
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
|
2015-04-22 13:29:20 -04:00
|
|
|
if (quit) {
|
|
|
|
if (cfg_quiet_stderr() && cfg_verbosity())
|
|
|
|
printf("\r");
|
|
|
|
log_notice("INT or TERM signal received");
|
|
|
|
}
|
2007-08-04 13:04:50 -04:00
|
|
|
|
2015-04-22 13:29:20 -04:00
|
|
|
log_info("exiting");
|
2007-02-28 16:26:16 -05:00
|
|
|
|
Merge changes to main(), urlParse() and streamPlaylist(). In main():
* Install the signal handler as late as possible.
* Add new command line options: -v (verbose, use twice for even more verbose
output) and -q (quiet, redirect standard error output from external de-/
encoders to /dev/null.)
* It is now an error to supply more than one -c parameter. This prevents
unexpected results.
* Add a stern warning when ezstream is running as root. Just Don't Do It.
Leaving the configfile writeable to others by accident could mean instant
root compromise.
* Before handing the config file over to libxml, try to open it ourselves
first. The error message from strerror() is a lot more helpful than the
cryption I/O error printed by libxml.
* Don't preallocate memory for urlParse().
* Fix command line error messages, they seem to be for a different program
than Ezstream.
* More terse libshout error messages, just print which function failed.
I consider these errors of questionable value for an end user, but at least
a knowledgeable one will know instantly what went wrong.
* Case insensitive matching of playlist file extensions.
* Print the address, port and mountpoint that Ezstream is actually trying to
connect to, instead of what the user supplied. That should make it easier
to spot reasons for connect failures (e.g. typos.)
Changes in urlParse():
* Let urlParse() allocate memory for hostname and mountpoint, as it knows
how much memory is actually required.
* Fix a buffer overflow of the tmpPort buffer by adding checks and using safe
string functions.
* Let the caller print an error message, instead of having the same printf()
twice in urlParse().
The streamPlaylist() function has been rewritten to use the new playlist_*()
routines. Apart from the added playlist shuffle feature no functional change.
git-svn-id: https://svn.xiph.org/trunk/ezstream@12552 0101bb08-14d6-0310-b084-bc0e0c8e3800
2007-02-24 20:14:36 -05:00
|
|
|
xfree(host);
|
|
|
|
xfree(mount);
|
2007-08-02 14:48:26 -04:00
|
|
|
playlist_free(&playlist);
|
2004-01-30 12:19:45 -05:00
|
|
|
|
2007-08-08 09:15:04 -04:00
|
|
|
return (ez_shutdown(0));
|
2004-01-30 12:19:45 -05:00
|
|
|
}
|