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"
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
#include "cmdline.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
|
|
|
|
2015-05-26 17:40:48 -04:00
|
|
|
playlist_t playlist;
|
|
|
|
int playlistMode;
|
|
|
|
unsigned int resource_errors;
|
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
|
|
|
|
2015-05-26 17:40:48 -04:00
|
|
|
volatile sig_atomic_t rereadPlaylist;
|
|
|
|
volatile sig_atomic_t rereadPlaylist_notify;
|
|
|
|
volatile sig_atomic_t skipTrack;
|
|
|
|
volatile sig_atomic_t queryMetadata;
|
|
|
|
volatile sig_atomic_t quit;
|
2004-07-18 23:12:31 -04:00
|
|
|
#else
|
2015-05-26 17:40:48 -04:00
|
|
|
int rereadPlaylist;
|
|
|
|
int rereadPlaylist_notify;
|
|
|
|
int skipTrack;
|
|
|
|
int queryMetadata;
|
|
|
|
int quit;
|
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 *);
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
char * buildReencodeCommand(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 *);
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
int streamPlaylist(shout_t *);
|
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 *
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
buildReencodeCommand(const char *extension, const char *fileName,
|
|
|
|
metadata_t *mdata)
|
2004-07-18 23:12:31 -04:00
|
|
|
{
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
cfg_decoder_t decoder;
|
|
|
|
cfg_encoder_t encoder;
|
|
|
|
char *dec_str, *enc_str;
|
|
|
|
char *commandString;
|
|
|
|
size_t commandStringLen;
|
|
|
|
char *localTitle, *localArtist, *localMetaString;
|
|
|
|
|
|
|
|
decoder = cfg_decoder_find(extension);
|
|
|
|
if (!decoder) {
|
|
|
|
log_error("cannot decode: %s: unsupported file extension %s",
|
2015-04-22 13:29:20 -04:00
|
|
|
fileName, extension);
|
2007-02-24 21:36:40 -05:00
|
|
|
return (NULL);
|
2004-07-18 23:12:31 -04:00
|
|
|
}
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
encoder = cfg_encoder_get(cfg_get_stream_encoder());
|
|
|
|
if (!encoder) {
|
|
|
|
log_error("cannot encode: %s: unknown encoder",
|
|
|
|
cfg_get_stream_encoder());
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
localTitle = UTF8toCHAR(metadata_get_title(mdata), ICONV_REPLACE);
|
|
|
|
localArtist = UTF8toCHAR(metadata_get_artist(mdata), ICONV_REPLACE);
|
|
|
|
localMetaString = UTF8toCHAR(metadata_get_string(mdata),
|
|
|
|
ICONV_REPLACE);
|
|
|
|
|
|
|
|
dec_str = replaceString(cfg_decoder_get_program(decoder),
|
|
|
|
PLACEHOLDER_TRACK, fileName);
|
|
|
|
if (strstr(dec_str, PLACEHOLDER_ARTIST) != NULL) {
|
|
|
|
char *tmpStr = replaceString(dec_str, PLACEHOLDER_ARTIST,
|
2015-01-07 16:49:09 -05:00
|
|
|
localArtist);
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
xfree(dec_str);
|
|
|
|
dec_str = tmpStr;
|
2007-03-10 14:03:07 -05:00
|
|
|
}
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (strstr(dec_str, PLACEHOLDER_TITLE) != NULL) {
|
|
|
|
char *tmpStr = replaceString(dec_str, PLACEHOLDER_TITLE,
|
2015-01-07 16:49:09 -05:00
|
|
|
localTitle);
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
xfree(dec_str);
|
|
|
|
dec_str = tmpStr;
|
2007-02-24 21:36:40 -05:00
|
|
|
}
|
2007-03-10 14:03:07 -05:00
|
|
|
/*
|
|
|
|
* if meta
|
|
|
|
* if (prog && format)
|
|
|
|
* metatoformat
|
|
|
|
* else
|
|
|
|
* if (!prog && title)
|
|
|
|
* emptymeta
|
|
|
|
* else
|
|
|
|
* replacemeta
|
|
|
|
*/
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (strstr(dec_str, PLACEHOLDER_METADATA) != NULL) {
|
|
|
|
if (cfg_get_metadata_program() &&
|
|
|
|
cfg_get_metadata_format_str()) {
|
|
|
|
char *mdataString = getMetadataString(cfg_get_metadata_format_str(),
|
|
|
|
mdata);
|
|
|
|
char *tmpStr = replaceString(dec_str,
|
|
|
|
PLACEHOLDER_METADATA, mdataString);
|
|
|
|
xfree(dec_str);
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(mdataString);
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
dec_str = tmpStr;
|
2007-03-10 14:03:07 -05:00
|
|
|
} else {
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (!cfg_get_metadata_program() &&
|
|
|
|
strstr(dec_str, PLACEHOLDER_TITLE) != NULL) {
|
|
|
|
char *tmpStr = replaceString(dec_str,
|
|
|
|
PLACEHOLDER_METADATA, "");
|
|
|
|
xfree(dec_str);
|
|
|
|
dec_str = tmpStr;
|
2007-03-10 14:03:07 -05:00
|
|
|
} else {
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
char *tmpStr = replaceString(dec_str,
|
|
|
|
PLACEHOLDER_METADATA, localMetaString);
|
|
|
|
xfree(dec_str);
|
|
|
|
dec_str = tmpStr;
|
2007-03-10 14:03:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-07-18 23:12:31 -04:00
|
|
|
|
2015-05-21 18:20:54 -04:00
|
|
|
if (!cfg_encoder_get_program(encoder))
|
|
|
|
return (dec_str);
|
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
enc_str = replaceString(cfg_encoder_get_program(encoder),
|
|
|
|
PLACEHOLDER_ARTIST, localArtist);
|
|
|
|
if (strstr(enc_str, PLACEHOLDER_TITLE) != NULL) {
|
|
|
|
char *tmpStr = replaceString(enc_str, PLACEHOLDER_TITLE,
|
2015-01-07 16:49:09 -05:00
|
|
|
localTitle);
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
xfree(enc_str);
|
|
|
|
enc_str = tmpStr;
|
2007-03-10 14:03:07 -05:00
|
|
|
}
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (strstr(enc_str, PLACEHOLDER_METADATA) != NULL) {
|
|
|
|
if (cfg_get_metadata_program() &&
|
|
|
|
cfg_get_metadata_format_str()) {
|
|
|
|
char *mdataString = getMetadataString(cfg_get_metadata_format_str(),
|
|
|
|
mdata);
|
|
|
|
char *tmpStr = replaceString(enc_str,
|
|
|
|
PLACEHOLDER_METADATA, mdataString);
|
|
|
|
xfree(enc_str);
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(mdataString);
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
enc_str = tmpStr;
|
2007-03-10 14:03:07 -05:00
|
|
|
} else {
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (!cfg_get_metadata_program() &&
|
|
|
|
strstr(enc_str, PLACEHOLDER_TITLE) != NULL) {
|
|
|
|
char *tmpStr = replaceString(enc_str,
|
|
|
|
PLACEHOLDER_METADATA, "");
|
|
|
|
xfree(enc_str);
|
|
|
|
enc_str = tmpStr;
|
2007-03-10 14:03:07 -05:00
|
|
|
} else {
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
char *tmpStr = replaceString(enc_str,
|
|
|
|
PLACEHOLDER_METADATA, localMetaString);
|
|
|
|
xfree(enc_str);
|
|
|
|
enc_str = tmpStr;
|
2007-03-10 14:03:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-07-18 23:12:31 -04:00
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
commandStringLen = strlen(dec_str) + strlen(" | ") +
|
|
|
|
strlen(enc_str) + 1;
|
2007-07-24 11:29:16 -04:00
|
|
|
commandString = xcalloc(commandStringLen, sizeof(char));
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
snprintf(commandString, commandStringLen, "%s | %s", dec_str,
|
|
|
|
enc_str);
|
2007-02-24 21:36:40 -05:00
|
|
|
|
2009-03-15 07:05:44 -04:00
|
|
|
xfree(localTitle);
|
|
|
|
xfree(localArtist);
|
|
|
|
xfree(localMetaString);
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
xfree(dec_str);
|
|
|
|
xfree(enc_str);
|
2007-02-24 21:36:40 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (strstr(format, PLACEHOLDER_ARTIST) != NULL) {
|
|
|
|
tmp = replaceString(str, PLACEHOLDER_ARTIST,
|
2015-01-07 16:49:09 -05:00
|
|
|
metadata_get_artist(mdata));
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(str);
|
|
|
|
str = tmp;
|
|
|
|
}
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (strstr(format, PLACEHOLDER_TITLE) != NULL) {
|
|
|
|
tmp = replaceString(str, PLACEHOLDER_TITLE,
|
2015-01-07 16:49:09 -05:00
|
|
|
metadata_get_title(mdata));
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(str);
|
|
|
|
str = tmp;
|
|
|
|
}
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (strstr(format, PLACEHOLDER_STRING) != NULL) {
|
|
|
|
tmp = replaceString(str, PLACEHOLDER_STRING,
|
2015-01-07 16:49:09 -05:00
|
|
|
metadata_get_string(mdata));
|
2007-03-10 14:03:07 -05:00
|
|
|
xfree(str);
|
|
|
|
str = tmp;
|
|
|
|
}
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (strstr(format, PLACEHOLDER_TRACK) != NULL) {
|
|
|
|
tmp = replaceString(str, PLACEHOLDER_TRACK,
|
2015-01-07 16:49:09 -05:00
|
|
|
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
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_metadata_program()) {
|
|
|
|
if (NULL == (mdata = metadata_program(fileName,
|
|
|
|
cfg_get_metadata_normalize_strings())))
|
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 {
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (NULL == (mdata = metadata_file(fileName,
|
|
|
|
cfg_get_metadata_normalize_strings())))
|
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;
|
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_metadata_no_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);
|
|
|
|
}
|
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
songInfo = getMetadataString(cfg_get_metadata_format_str(), mdata);
|
|
|
|
if (songInfo == 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) {
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_metadata_program()) {
|
|
|
|
if ((mdata = getMetadata(cfg_get_metadata_program())) == NULL)
|
2007-03-09 21:27:48 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_metadata_program()) {
|
|
|
|
if ((mdata = getMetadata(cfg_get_metadata_program())) == NULL)
|
2007-03-09 21:27:48 -05:00
|
|
|
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;
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_stream_encoder()) {
|
2007-07-24 09:04:01 -04:00
|
|
|
int stderr_fd = -1;
|
2007-03-08 09:39:00 -05:00
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
pCommandString = buildReencodeCommand(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
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_program_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
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_program_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;
|
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
log_warning("%s: connection lost", cfg_get_server_hostname());
|
2007-03-01 19:57:11 -05:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (++i) {
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_server_reconnect_attempts() > 0)
|
2015-04-22 13:29:20 -04:00
|
|
|
log_notice("reconnect: %s: attempt #%u/%u ...",
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
cfg_get_server_hostname(), i,
|
|
|
|
cfg_get_server_reconnect_attempts());
|
2007-03-01 19:57:11 -05:00
|
|
|
else
|
2015-04-22 13:29:20 -04:00
|
|
|
log_notice("reconnect: %s: attempt #%u ...",
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
cfg_get_server_hostname(), 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",
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
cfg_get_server_hostname());
|
2007-03-01 19:57:11 -05:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2015-04-22 13:29:20 -04:00
|
|
|
log_warning("reconnect failed: %s: %s",
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
cfg_get_server_hostname(), shout_get_error(shout));
|
2007-03-01 19:57:11 -05:00
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_server_reconnect_attempts() > 0 &&
|
|
|
|
i >= cfg_get_server_reconnect_attempts())
|
2007-03-01 19:57:11 -05:00
|
|
|
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;
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (CFG_MEDIA_PLAYLIST == cfg_get_media_type())
|
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 ||
|
2015-05-14 17:23:48 -04:00
|
|
|
(0 <= cfg_get_metadata_refresh_interval() &&
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
(currentTime.tv_sec - callTime.tv_sec >=
|
|
|
|
cfg_get_metadata_refresh_interval()))) {
|
2007-03-08 21:30:29 -05:00
|
|
|
queryMetadata = 0;
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_metadata_program()) {
|
2007-03-08 21:30:29 -05:00
|
|
|
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-05-12 11:35:04 -04:00
|
|
|
if (cfg_get_program_rtstatus_output()) {
|
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) {
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (CFG_MEDIA_PROGRAM == cfg_get_media_type()) {
|
|
|
|
char *tmp = xstrdup(cfg_get_media_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: */
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (CFG_STREAM_MP3 == cfg_get_stream_format())
|
2007-08-23 09:48:42 -04:00
|
|
|
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;
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_metadata_no_updates())
|
2015-01-03 17:19:28 -05:00
|
|
|
continue;
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_metadata_program()) {
|
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",
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
cfg_get_metadata_program());
|
|
|
|
if ((prog_mdata = getMetadata(cfg_get_metadata_program())) == 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
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
streamPlaylist(shout_t *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
|
|
|
{
|
|
|
|
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) {
|
2015-05-26 18:21:44 -04:00
|
|
|
switch (cfg_get_media_type()) {
|
|
|
|
case CFG_MEDIA_PROGRAM:
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if ((playlist = playlist_program(cfg_get_media_filename())) == NULL)
|
2007-02-28 16:26:16 -05:00
|
|
|
return (0);
|
2015-05-26 18:21:44 -04:00
|
|
|
break;
|
|
|
|
case CFG_MEDIA_STDIN:
|
|
|
|
if ((playlist = playlist_read(NULL)) == NULL)
|
|
|
|
return (0);
|
|
|
|
break;
|
|
|
|
default:
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if ((playlist = playlist_read(cfg_get_media_filename())) == NULL)
|
2007-02-28 16:26:16 -05:00
|
|
|
return (0);
|
2015-04-22 13:29:20 -04:00
|
|
|
if (playlist_get_num_items(playlist) == 0)
|
2015-05-26 18:21:44 -04:00
|
|
|
log_warning("%s: playlist empty",
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
cfg_get_media_filename());
|
2015-05-26 18:21:44 -04:00
|
|
|
break;
|
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
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (CFG_MEDIA_PROGRAM != cfg_get_media_type() &&
|
|
|
|
cfg_get_media_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;
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (CFG_MEDIA_PROGRAM == cfg_get_media_type())
|
2007-02-28 16:26:16 -05:00
|
|
|
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);
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_media_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);
|
|
|
|
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();
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
|
|
|
|
playlist_exit();
|
|
|
|
cfg_encoder_exit();
|
|
|
|
cfg_decoder_exit();
|
2015-04-16 13:22:58 -04:00
|
|
|
log_exit();
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
cfg_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;
|
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
|
|
|
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;
|
2015-05-14 17:28:08 -04:00
|
|
|
if (0 > cfg_init() ||
|
|
|
|
0 > cmdline_parse(argc, argv, &ret) ||
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
0 > log_init() ||
|
|
|
|
0 > cfg_decoder_init() ||
|
|
|
|
0 > cfg_encoder_init() ||
|
|
|
|
0 > playlist_init() ||
|
|
|
|
0 > cfg_reload())
|
2015-05-06 13:00:23 -04:00
|
|
|
return (ez_shutdown(ret));
|
2007-08-02 14:48:26 -04:00
|
|
|
shout_init();
|
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (!cfg_get_server_hostname() ||
|
|
|
|
!cfg_get_server_port()){
|
|
|
|
log_error("%s: missing server configuration",
|
|
|
|
cfg_get_program_config_file());
|
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
|
|
|
}
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (!cfg_get_server_password()) {
|
|
|
|
log_error("%s: <sourcepassword> missing",
|
|
|
|
cfg_get_program_config_file());
|
2007-08-08 09:15:04 -04:00
|
|
|
return (ez_shutdown(2));
|
2004-01-30 12:19:45 -05:00
|
|
|
}
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (!cfg_get_media_filename()) {
|
|
|
|
log_error("%s: <filename> missing",
|
|
|
|
cfg_get_program_config_file());
|
2007-08-08 09:15:04 -04:00
|
|
|
return (ez_shutdown(2));
|
2004-01-30 12:19:45 -05:00
|
|
|
}
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (CFG_STREAM_INVALID == cfg_get_stream_format()) {
|
2015-04-22 13:29:20 -04:00
|
|
|
log_error("%s: <format> missing or unsupported value",
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
cfg_get_program_config_file());
|
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
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
shout = stream_setup(cfg_get_server_hostname(),
|
|
|
|
cfg_get_server_port(), cfg_get_stream_mountpoint());
|
|
|
|
if (shout == NULL)
|
2007-08-08 09:15:04 -04:00
|
|
|
return (ez_shutdown(1));
|
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
|
|
|
#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
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
log_notice("connected: %s://%s:%u%s",
|
|
|
|
cfg_get_server_protocol_str(), cfg_get_server_hostname(),
|
|
|
|
cfg_get_server_port(), cfg_get_stream_mountpoint());
|
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
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (CFG_MEDIA_PROGRAM == cfg_get_media_type() ||
|
|
|
|
CFG_MEDIA_PLAYLIST == cfg_get_media_type() ||
|
|
|
|
(CFG_MEDIA_AUTODETECT == cfg_get_media_type() &&
|
|
|
|
(strrcasecmp(cfg_get_media_filename(), ".m3u") == 0 ||
|
|
|
|
strrcasecmp(cfg_get_media_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) {
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
cont = streamPlaylist(shout);
|
2007-07-15 20:32:17 -04:00
|
|
|
} else {
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
cont = streamFile(shout,
|
|
|
|
cfg_get_media_filename());
|
2007-02-28 16:48:01 -05:00
|
|
|
}
|
2007-08-04 13:04:50 -04:00
|
|
|
if (quit)
|
|
|
|
break;
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_media_stream_once())
|
2007-07-15 20:32:17 -04:00
|
|
|
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
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
log_error("connection failed: %s://%s:%u%s: %s",
|
|
|
|
cfg_get_server_protocol_str(), cfg_get_server_hostname(),
|
|
|
|
cfg_get_server_port(), cfg_get_stream_mountpoint(),
|
|
|
|
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) {
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_program_quiet_stderr() &&
|
|
|
|
cfg_get_program_verbosity())
|
2015-04-22 13:29:20 -04:00
|
|
|
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
|
|
|
|
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
|
|
|
}
|