1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2024-11-03 04:17:18 -05:00

Factor out command line parsing

This commit is contained in:
Moritz Grimm 2015-04-16 14:27:39 +02:00
parent 4062cc190a
commit 9bc65bf717
9 changed files with 441 additions and 302 deletions

View File

@ -3,7 +3,16 @@ AUTOMAKE_OPTIONS = 1.10 foreign subdir-objects
bin_PROGRAMS = ezstream
bin_SCRIPTS = ezstream-file.sh
noinst_HEADERS = \
cfg.h \
configfile.h \
ezstream.h \
metadata.h \
playlist.h \
util.h \
xalloc.h
ezstream_SOURCES = \
cfg.c \
configfile.c \
ezstream.c \
metadata.c \
@ -16,12 +25,4 @@ AM_CFLAGS = @EZ_CFLAGS@
AM_CPPFLAGS = @EZ_CPPFLAGS@ -I$(top_srcdir)/compat
AM_LDFLAGS = @EZ_LDFLAGS@
EXTRA_DIST = \
configfile.h \
ezstream.h \
metadata.h \
playlist.h \
util.h \
xalloc.h
CLEANFILES = core *.core *~ .*~

225
src/cfg.c Normal file
View File

@ -0,0 +1,225 @@
/*
* Copyright (c) 2015 Moritz Grimm <mgrimm@mrsserver.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
#include "compat.h"
#include <limits.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
#include "cfg.h"
#define OPTSTRING "c:hmnqs:Vv"
enum opt_vals {
OPT_CONFIGFILE = 'c',
OPT_HELP = 'h',
OPT_NOMETADATAUPDATE = 'm',
OPT_NORMALIZESTRINGS = 'n',
OPT_QUIETSTDERR = 'q',
OPT_SHUFFLEFILE = 's',
OPT_VERSION = 'V',
OPT_VERBOSE = 'v',
OPT_INVALID = '?'
};
static struct cfg {
char progname[PATH_MAX];
char config_file[PATH_MAX];
int no_metadata_updates;
int normalize_strings;
int quiet_stderr;
char shuffle_file[PATH_MAX];
unsigned int verbosity;
} cfg;
static void usage(void);
static void usage_help(void);
static void
_set_progname(const char *argv0)
{
#ifdef HAVE___PROGNAME
extern char *__progname;
(void)argv0;
snprintf(cfg.progname, sizeof(cfg.progname), "%s", __progname);
#else
if (argv0 == NULL) {
snprintf(cfg.progname, sizeof(cfg.progname), "ezstream");
} else {
const char *p = strrchr(argv0, '/');
if (p == NULL)
p = argv0;
else
p++;
snprintf(cfg.progname, sizeof(cfg.progname), "%s", p);
}
#endif /* HAVE___PROGNAME */
}
static void
usage(void)
{
fprintf(stderr, "usage: %s [-ghmnqVv] -c cfgfile\n",
cfg.progname);
fprintf(stderr, " %s [-ghV] -s file\n",
cfg.progname);
}
static void
usage_help(void)
{
fprintf(stderr, "\n");
fprintf(stderr, " -c cfgfile use XML configuration in cfgfile\n");
fprintf(stderr, " -h print this help and exit\n");
fprintf(stderr, " -m disable metadata updates\n");
fprintf(stderr, " -n normalize metadata strings\n");
fprintf(stderr, " -q suppress STDERR output from external en-/decoders\n");
fprintf(stderr, " -s file read lines from file, shuffle, print to STDOUT, then exit\n");
fprintf(stderr, " -V print the version number and exit\n");
fprintf(stderr, " -v verbose output (use twice for more effect)\n");
}
int
cfg_cmdline_parse(int argc, char *argv[], int *ret_p)
{
int ch;
memset(&cfg, 0, sizeof(cfg));
_set_progname(argv[0]);
for (;;) {
ch = getopt(argc, argv, OPTSTRING);
if (0 > ch)
break;
switch (ch) {
case OPT_CONFIGFILE:
if (cfg.config_file[0]) {
fprintf(stderr,
"option -%c may only be given once\n",
OPT_CONFIGFILE);
usage();
*ret_p = 2;
return (-1);
}
(void)snprintf(cfg.config_file,
sizeof(cfg.config_file), "%s", optarg);
break;
case OPT_HELP:
usage();
usage_help();
*ret_p = 0;
return (-1);
case OPT_NOMETADATAUPDATE:
cfg.no_metadata_updates = 1;
break;
case OPT_NORMALIZESTRINGS:
cfg.normalize_strings = 1;
break;
case OPT_QUIETSTDERR:
cfg.quiet_stderr = 1;
break;
case OPT_SHUFFLEFILE:
if (cfg.shuffle_file[0]) {
fprintf(stderr,
"option -%c may only be given once\n",
OPT_SHUFFLEFILE);
usage();
*ret_p = 2;
return (-1);
}
(void)snprintf(cfg.shuffle_file,
sizeof(cfg.shuffle_file), "%s", optarg);
break;
case OPT_VERSION:
fprintf(stdout, "%s version %s\n",
PACKAGE_NAME, PACKAGE_VERSION);
*ret_p = 0;
return (-1);
case OPT_VERBOSE:
cfg.verbosity++;
break;
case OPT_INVALID:
default:
usage();
*ret_p = 2;
return (-1);
}
}
argc -= optind;
argv += optind;
if ((!cfg.config_file[0] && !cfg.shuffle_file[0]) ||
(cfg.config_file[0] && cfg.shuffle_file[0])) {
fprintf(stderr, "either -%c or -%c must be provided\n",
OPT_CONFIGFILE, OPT_SHUFFLEFILE);
usage();
*ret_p = 2;
return (-1);
}
return (0);
}
const char *
cfg_progname(void)
{
return (cfg.progname);
}
const char *
cfg_config_file(void)
{
return (cfg.config_file);
}
int
cfg_no_metadata_updates(void)
{
return (cfg.no_metadata_updates);
}
int
cfg_normalize_strings(void)
{
return (cfg.normalize_strings);
}
int
cfg_quiet_stderr(void)
{
return (cfg.quiet_stderr);
}
const char *
cfg_shuffle_file(void)
{
return (cfg.shuffle_file[0] ? cfg.shuffle_file : NULL);
}
unsigned int
cfg_verbosity(void)
{
return (cfg.verbosity);
}

35
src/cfg.h Normal file
View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2015 Moritz Grimm <mgrimm@mrsserver.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef __CFG_H__
#define __CFG_H__
int cfg_cmdline_parse(int, char *[], int *);
const char *
cfg_progname(void);
const char *
cfg_config_file(void);
int cfg_no_metadata_updates(void);
int cfg_normalize_strings(void);
int cfg_quiet_stderr(void);
const char *
cfg_shuffle_file(void);
unsigned int
cfg_verbosity(void);
#endif /* __CFG_H__ */

View File

@ -21,12 +21,11 @@
#include "compat.h"
#include "cfg.h"
#include "configfile.h"
#include "util.h"
#include "xalloc.h"
extern char *__progname;
static EZCONFIG ezConfig;
static const char *blankString = "";
@ -590,7 +589,7 @@ parseConfig(const char *fileName)
return (1);
freeConfig(&ezConfig);
printf("%s: %u configuration error(s) in %s\n", __progname,
printf("%s: %u configuration error(s) in %s\n", cfg_progname(),
config_error, fileName);
return (0);

View File

@ -39,17 +39,6 @@
#define STREAM_SERVERR 3
#define STREAM_UPDMDATA 4
#ifdef HAVE___PROGNAME
extern char *__progname;
#else
char *__progname;
#endif /* HAVE___PROGNAME */
int nFlag;
int mFlag;
int qFlag;
int sFlag;
int vFlag;
int metadataFromProgram;
EZCONFIG *pezConfig = NULL;
@ -100,9 +89,6 @@ int sendStream(shout_t *, FILE *, const char *, int, const char *,
struct timeval *);
int streamFile(shout_t *, const char *);
int streamPlaylist(shout_t *, const char *);
char * getProgname(const char *);
void usage(void);
void usageHelp(void);
int ez_shutdown(int);
#ifdef HAVE_SIGNALS
@ -147,13 +133,13 @@ urlParse(const char *url, char **hostname, unsigned short *port,
if (hostname == NULL || port == NULL || mountname == NULL) {
printf("%s: urlParse(): Internal error: Bad arguments\n",
__progname);
cfg_progname());
exit(1);
}
if (strncmp(url, "http://", strlen("http://")) != 0) {
printf("%s: Error: Invalid <url>: Not an HTTP address\n",
__progname);
cfg_progname());
return (0);
}
@ -161,7 +147,7 @@ urlParse(const char *url, char **hostname, unsigned short *port,
p2 = strchr(p1, ':');
if (p2 == NULL) {
printf("%s: Error: Invalid <url>: Missing port\n",
__progname);
cfg_progname());
return (0);
}
hostsiz = (p2 - p1) + 1;
@ -172,7 +158,7 @@ urlParse(const char *url, char **hostname, unsigned short *port,
p3 = strchr(p2, '/');
if (p3 == NULL || p3 - p2 >= (int)sizeof(tmpPort)) {
printf("%s: Error: Invalid <url>: Missing mountpoint or too long port number\n",
__progname);
cfg_progname());
xfree(*hostname);
return (0);
}
@ -181,7 +167,7 @@ urlParse(const char *url, char **hostname, unsigned short *port,
*port = (unsigned short)strtonum(tmpPort, 1LL, (long long)USHRT_MAX, &errstr);
if (errstr) {
printf("%s: Error: Invalid <url>: Port '%s' is %s\n",
__progname, tmpPort, errstr);
cfg_progname(), tmpPort, errstr);
xfree(*hostname);
return (0);
}
@ -276,7 +262,7 @@ buildCommandString(const char *extension, const char *fileName,
decoder = xstrdup(getFormatDecoder(extension));
if (strlen(decoder) == 0) {
printf("%s: Unknown extension '%s', cannot decode '%s'\n",
__progname, extension, fileName);
cfg_progname(), extension, fileName);
xfree(localTitle);
xfree(localArtist);
xfree(localMetaString);
@ -331,9 +317,9 @@ buildCommandString(const char *extension, const char *fileName,
encoder = xstrdup(getFormatEncoder(pezConfig->format));
if (strlen(encoder) == 0) {
if (vFlag)
if (cfg_verbosity())
printf("%s: Passing through%s%s data from the decoder\n",
__progname,
cfg_progname(),
(strcmp(pezConfig->format, THEORA_FORMAT) != 0) ? " (unsupported) " : " ",
pezConfig->format);
commandStringLen = strlen(newDecoder) + 1;
@ -402,7 +388,7 @@ getMetadataString(const char *format, metadata_t *mdata)
if (mdata == NULL) {
printf("%s: getMetadataString(): Internal error: NULL metadata_t\n",
__progname);
cfg_progname());
abort();
}
@ -445,7 +431,7 @@ getMetadata(const char *fileName)
metadata_t *mdata;
if (metadataFromProgram) {
if ((mdata = metadata_program(fileName, nFlag)) == NULL)
if ((mdata = metadata_program(fileName, cfg_normalize_strings())) == NULL)
return (NULL);
if (!metadata_program_update(mdata, METADATA_ALL)) {
@ -453,7 +439,7 @@ getMetadata(const char *fileName)
return (NULL);
}
} else {
if ((mdata = metadata_file(fileName, nFlag)) == NULL)
if ((mdata = metadata_file(fileName, cfg_normalize_strings())) == NULL)
return (NULL);
if (!metadata_file_update(mdata)) {
@ -475,18 +461,18 @@ setMetadata(shout_t *shout, metadata_t *mdata, char **mdata_copy)
if (shout == NULL) {
printf("%s: setMetadata(): Internal error: NULL shout_t\n",
__progname);
cfg_progname());
abort();
}
if (mFlag)
if (cfg_no_metadata_updates())
return (SHOUTERR_SUCCESS);
if (mdata == NULL)
return 1;
if ((shout_mdata = shout_metadata_new()) == NULL) {
printf("%s: shout_metadata_new(): %s\n", __progname,
printf("%s: shout_metadata_new(): %s\n", cfg_progname(),
strerror(ENOMEM));
exit(1);
}
@ -502,7 +488,7 @@ setMetadata(shout_t *shout, metadata_t *mdata, char **mdata_copy)
*/
if (shout_metadata_add(shout_mdata, "charset", "UTF-8") != SHOUTERR_SUCCESS) {
/* Assume SHOUTERR_MALLOC */
printf("%s: shout_metadata_add(): %s\n", __progname,
printf("%s: shout_metadata_add(): %s\n", cfg_progname(),
strerror(ENOMEM));
exit(1);
}
@ -514,31 +500,31 @@ setMetadata(shout_t *shout, metadata_t *mdata, char **mdata_copy)
songInfo = metadata_assemble_string(mdata);
if (artist[0] != '\0' && title[0] != '\0') {
if (shout_metadata_add(shout_mdata, "artist", artist) != SHOUTERR_SUCCESS) {
printf("%s: shout_metadata_add(): %s\n", __progname,
printf("%s: shout_metadata_add(): %s\n", cfg_progname(),
strerror(ENOMEM));
exit(1);
}
if (shout_metadata_add(shout_mdata, "title", title) != SHOUTERR_SUCCESS) {
printf("%s: shout_metadata_add(): %s\n", __progname,
printf("%s: shout_metadata_add(): %s\n", cfg_progname(),
strerror(ENOMEM));
exit(1);
}
} else {
if (shout_metadata_add(shout_mdata, "song", songInfo) != SHOUTERR_SUCCESS) {
printf("%s: shout_metadata_add(): %s\n", __progname,
printf("%s: shout_metadata_add(): %s\n", cfg_progname(),
strerror(ENOMEM));
exit(1);
}
}
} else if (shout_metadata_add(shout_mdata, "song", songInfo) != SHOUTERR_SUCCESS) {
printf("%s: shout_metadata_add(): %s\n", __progname,
printf("%s: shout_metadata_add(): %s\n", cfg_progname(),
strerror(ENOMEM));
exit(1);
}
if ((ret = shout_set_metadata(shout, shout_mdata)) != SHOUTERR_SUCCESS)
printf("%s: shout_set_metadata(): %s\n",
__progname, shout_get_error(shout));
cfg_progname(), shout_get_error(shout));
shout_metadata_free(shout_mdata);
@ -598,7 +584,7 @@ openResource(shout_t *shout, const char *fileName, int *popenFlag,
if (strlen(extension) == 0) {
printf("%s: Error: Cannot determine file type of '%s'\n",
__progname, fileName);
cfg_progname(), fileName);
return (filep);
}
@ -621,17 +607,17 @@ openResource(shout_t *shout, const char *fileName, int *popenFlag,
*mdata_p = mdata;
else
metadata_free(&mdata);
if (vFlag > 1)
printf("%s: Running command `%s`\n", __progname,
if (cfg_verbosity() > 1)
printf("%s: Running command `%s`\n", cfg_progname(),
pCommandString);
if (qFlag) {
if (cfg_quiet_stderr()) {
int fd;
stderr_fd = dup(fileno(stderr));
if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) == -1) {
printf("%s: Cannot open %s for redirecting STDERR output: %s\n",
__progname, _PATH_DEVNULL, strerror(errno));
cfg_progname(), _PATH_DEVNULL, strerror(errno));
exit(1);
}
@ -644,7 +630,7 @@ openResource(shout_t *shout, const char *fileName, int *popenFlag,
errno = 0;
if ((filep = popen(pCommandString, "r")) == NULL) {
printf("%s: popen(): Error while executing '%s'",
__progname, pCommandString);
cfg_progname(), pCommandString);
/* popen() does not set errno reliably ... */
if (errno)
printf(": %s\n", strerror(errno));
@ -655,7 +641,7 @@ openResource(shout_t *shout, const char *fileName, int *popenFlag,
}
xfree(pCommandString);
if (qFlag)
if (cfg_quiet_stderr())
dup2(stderr_fd, fileno(stderr));
if (stderr_fd > 2)
@ -670,7 +656,7 @@ openResource(shout_t *shout, const char *fileName, int *popenFlag,
metadata_free(&mdata);
if ((filep = fopen(fileName, "rb")) == NULL)
printf("%s: %s: %s\n", __progname, fileName,
printf("%s: %s: %s\n", cfg_progname(), fileName,
strerror(errno));
return (filep);
@ -682,11 +668,11 @@ reconnectServer(shout_t *shout, int closeConn)
unsigned int i;
int close_conn = closeConn;
printf("%s: Connection to %s lost\n", __progname, pezConfig->URL);
printf("%s: Connection to %s lost\n", cfg_progname(), pezConfig->URL);
i = 0;
while (++i) {
printf("%s: Attempting reconnection #", __progname);
printf("%s: Attempting reconnection #", cfg_progname());
if (pezConfig->reconnectAttempts > 0)
printf("%u/%u: ", i, pezConfig->reconnectAttempts);
else
@ -698,7 +684,7 @@ reconnectServer(shout_t *shout, int closeConn)
shout_close(shout);
if (shout_open(shout) == SHOUTERR_SUCCESS) {
printf("OK\n%s: Reconnect to %s successful\n",
__progname, pezConfig->URL);
cfg_progname(), pezConfig->URL);
return (1);
}
@ -709,14 +695,14 @@ reconnectServer(shout_t *shout, int closeConn)
break;
printf("%s: Waiting 5s for %s to come back ...\n",
__progname, pezConfig->URL);
cfg_progname(), pezConfig->URL);
if (quit)
return (0);
else
sleep(5);
};
printf("%s: Giving up\n", __progname);
printf("%s: Giving up\n", cfg_progname());
return (0);
}
@ -752,7 +738,7 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
if (startTime == NULL) {
printf("%s: sendStream(): Internal error: startTime is NULL\n",
__progname);
cfg_progname());
abort();
}
@ -773,7 +759,7 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
shout_sync(shout);
if (shout_send(shout, buff, bytes_read) != SHOUTERR_SUCCESS) {
printf("%s: shout_send(): %s\n", __progname,
printf("%s: shout_send(): %s\n", cfg_progname(),
shout_get_error(shout));
if (reconnectServer(shout, 1))
break;
@ -789,7 +775,7 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
rereadPlaylist_notify = 0;
if (!pezConfig->fileNameIsProgram)
printf("%s: SIGHUP signal received, will reread playlist after this file\n",
__progname);
cfg_progname());
}
if (skipTrack) {
skipTrack = 0;
@ -813,7 +799,7 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
}
total += bytes_read;
if (qFlag && vFlag) {
if (cfg_quiet_stderr() && cfg_verbosity()) {
double oldTime, newTime;
if (!isStdin && playlistMode) {
@ -862,10 +848,10 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
ret = STREAM_CONT;
} else if (errno == EBADF && isStdin)
printf("%s: No (more) data available on standard input\n",
__progname);
cfg_progname());
else
printf("%s: sendStream(): Error while reading '%s': %s\n",
__progname, fileName, strerror(errno));
cfg_progname(), fileName, strerror(errno));
}
return (ret);
@ -886,7 +872,7 @@ streamFile(shout_t *shout, const char *fileName)
if ((filepstream = openResource(shout, fileName, &popenFlag, &mdata, &isStdin, &songLen))
== NULL) {
if (++resource_errors > 100) {
printf("%s: Too many errors -- giving up.\n", __progname);
printf("%s: Too many errors -- giving up.\n", cfg_progname());
return (0);
}
/* Continue with next resource on failure: */
@ -901,8 +887,8 @@ streamFile(shout_t *shout, const char *fileName)
if ((metaData = UTF8toCHAR(tmp, ICONV_REPLACE)) == NULL)
metaData = xstrdup("(unknown title)");
xfree(tmp);
printf("%s: Streaming ``%s''", __progname, metaData);
if (vFlag)
printf("%s: Streaming ``%s''", cfg_progname(), metaData);
if (cfg_verbosity())
printf(" (file: %s)\n", fileName);
else
printf("\n");
@ -914,7 +900,7 @@ streamFile(shout_t *shout, const char *fileName)
metadata_free(&mdata);
} else if (isStdin)
printf("%s: Streaming from standard input\n", __progname);
printf("%s: Streaming from standard input\n", cfg_progname());
if (songLen > 0)
songLenStr = xstrdup(getTimeString(songLen));
@ -936,23 +922,23 @@ streamFile(shout_t *shout, const char *fileName)
}
if (ret == STREAM_SKIP || skipTrack) {
skipTrack = 0;
if (!isStdin && vFlag)
if (!isStdin && cfg_verbosity())
printf("%s: SIGUSR1 signal received, skipping current track\n",
__progname);
cfg_progname());
retval = 1;
ret = STREAM_DONE;
}
if (ret == STREAM_UPDMDATA || queryMetadata) {
queryMetadata = 0;
if (mFlag)
if (cfg_no_metadata_updates())
continue;
if (metadataFromProgram) {
char *mdataStr = NULL;
metadata_t *prog_mdata;
if (vFlag > 1)
if (cfg_verbosity() > 1)
printf("%s: Querying '%s' for fresh metadata\n",
__progname, pezConfig->metadataProgram);
cfg_progname(), pezConfig->metadataProgram);
if ((prog_mdata = getMetadata(pezConfig->metadataProgram)) == NULL) {
retval = 0;
ret = STREAM_DONE;
@ -964,9 +950,9 @@ streamFile(shout_t *shout, const char *fileName)
continue;
}
metadata_free(&prog_mdata);
if (vFlag > 1)
if (cfg_verbosity() > 1)
printf("%s: New metadata: ``%s''\n",
__progname, mdataStr);
cfg_progname(), mdataStr);
xfree(mdataStr);
}
}
@ -1002,9 +988,9 @@ streamPlaylist(shout_t *shout, const char *fileName)
} else {
if ((playlist = playlist_read(fileName)) == NULL)
return (0);
if (vFlag && playlist_get_num_items(playlist) == 0)
if (cfg_verbosity() && playlist_get_num_items(playlist) == 0)
printf("%s: Warning: Playlist '%s' is empty\n",
__progname, fileName);
cfg_progname(), fileName);
}
} else {
/*
@ -1028,7 +1014,7 @@ streamPlaylist(shout_t *shout, const char *fileName)
rereadPlaylist = rereadPlaylist_notify = 0;
if (pezConfig->fileNameIsProgram)
continue;
printf("%s: Rereading playlist\n", __progname);
printf("%s: Rereading playlist\n", cfg_progname());
if (!playlist_reread(&playlist))
return (0);
if (pezConfig->shuffle)
@ -1044,32 +1030,6 @@ streamPlaylist(shout_t *shout, const char *fileName)
return (1);
}
/*
* Borrowed from OpenNTPd-portable's compat-openbsd/bsd-misc.c.
* Does not use xalloc on purpose, as the 9 bytes of memory that don't get
* cleaned up in the end really don't matter.
*/
char *
getProgname(const char *argv0)
{
#ifdef HAVE___PROGNAME
(void)argv0;
return (strdup(__progname));
#else
char *p;
if (argv0 == NULL)
return ((char *)"ezstream");
p = strrchr(argv0, '/');
if (p == NULL)
p = (char *)argv0;
else
p++;
return (strdup(p));
#endif /* HAVE___PROGNAME */
}
int
ez_shutdown(int exitval)
{
@ -1081,36 +1041,13 @@ ez_shutdown(int exitval)
return (exitval);
}
void
usage(void)
{
printf("usage: %s [-hmnqVv] -c configfile\n", __progname);
printf(" %s -s [playlist]\n", __progname);
}
void
usageHelp(void)
{
printf("\n");
printf(" -c configfile use XML configuration in configfile (mandatory)\n");
printf(" -h display this additional help and exit\n");
printf(" -m disable metadata updates\n");
printf(" -n normalize metadata strings\n");
printf(" -q suppress STDERR output from external en-/decoders\n");
printf(" -s [playlist] read lines from playlist (or STDIN), shuffle and print them to\n");
printf(" STDOUT, then exit\n");
printf(" -V print the version number and exit\n");
printf(" -v verbose output (use twice for more effect)\n");
printf("\n");
printf("See the ezstream(1) manual for detailed information.\n");
}
int
main(int argc, char *argv[])
{
int c;
char *configFile = NULL;
char *playlistFile = NULL;
int ret;
const char *configFile;
const char *playlistFile;
char *host = NULL;
unsigned short port = 0;
char *mount = NULL;
@ -1121,6 +1058,9 @@ main(int argc, char *argv[])
struct sigaction act;
unsigned int i;
#endif
ret = 1;
if (0 > cfg_cmdline_parse(argc, argv, &ret))
return (ret);
#ifdef XALLOC_DEBUG
xalloc_initialize_debug(2, NULL);
@ -1130,63 +1070,10 @@ main(int argc, char *argv[])
playlist_init();
shout_init();
__progname = getProgname(argv[0]);
pezConfig = getEZConfig();
mFlag = 0;
nFlag = 0;
qFlag = 0;
vFlag = 0;
while ((c = getopt(argc, argv, "c:hmnqs:Vv")) != -1) {
switch (c) {
case 'c':
if (configFile != NULL) {
printf("Error: multiple -c arguments given\n");
usage();
return (ez_shutdown(2));
}
configFile = xstrdup(optarg);
break;
case 'h':
usage();
usageHelp();
return (ez_shutdown(0));
case 'm':
mFlag = 1;
break;
case 'n':
nFlag = 1;
break;
case 'q':
qFlag = 1;
break;
case 's':
sFlag = 1;
if (playlistFile != NULL) {
printf("Error: multiple -s arguments given\n");
usage();
return (ez_shutdown(2));
}
playlistFile = xstrdup(optarg);
break;
case 'V':
printf("%s\n", PACKAGE_STRING);
return (ez_shutdown(0));
case 'v':
vFlag++;
break;
case '?':
usage();
return (ez_shutdown(2));
default:
break;
}
}
argc -= optind;
argv += optind;
if (sFlag) {
playlistFile = cfg_shuffle_file();
if (playlistFile) {
playlist_t *pl;
const char *entry;
@ -1207,11 +1094,8 @@ main(int argc, char *argv[])
return (ez_shutdown(0));
}
if (configFile == NULL) {
printf("You must supply a config file with the -c argument.\n");
usage();
return (ez_shutdown(2));
} else {
configFile = cfg_config_file();
{
/*
* Attempt to open configFile here for a more meaningful error
* message. Where possible, do it with stat() and check for
@ -1222,15 +1106,14 @@ main(int argc, char *argv[])
if (stat(configFile, &st) == -1) {
printf("%s: %s\n", configFile, strerror(errno));
usage();
return (ez_shutdown(2));
}
if (vFlag && (st.st_mode & (S_IRGRP | S_IROTH)))
if (cfg_verbosity() && (st.st_mode & (S_IRGRP | S_IROTH)))
printf("%s: Warning: %s is group and/or world readable\n",
__progname, configFile);
cfg_progname(), configFile);
if (st.st_mode & (S_IWGRP | S_IWOTH)) {
printf("%s: Error: %s is group and/or world writeable\n",
__progname, configFile);
cfg_progname(), configFile);
return (ez_shutdown(2));
}
#else
@ -1279,8 +1162,6 @@ main(int argc, char *argv[])
printf("Specify a stream format of either MP3, VORBIS or THEORA\n");
}
xfree(configFile);
if ((shout = stream_setup(host, port, mount)) == NULL)
return (ez_shutdown(1));
@ -1298,7 +1179,7 @@ main(int argc, char *argv[])
for (i = 0; i < sizeof(ezstream_signals) / sizeof(int); i++) {
if (sigaction(ezstream_signals[i], &act, NULL) == -1) {
printf("%s: sigaction(): %s\n",
__progname, strerror(errno));
cfg_progname(), strerror(errno));
return (ez_shutdown(1));
}
}
@ -1309,15 +1190,15 @@ main(int argc, char *argv[])
act.sa_handler = SIG_IGN;
if (sigaction(SIGPIPE, &act, NULL) == -1) {
printf("%s: sigaction(): %s\n",
__progname, strerror(errno));
cfg_progname(), strerror(errno));
return (ez_shutdown(1));
}
#endif /* HAVE_SIGNALS */
if (shout_open(shout) == SHOUTERR_SUCCESS) {
int ret;
int cont;
printf("%s: Connected to http://%s:%hu%s\n", __progname,
printf("%s: Connected to http://%s:%hu%s\n", cfg_progname(),
host, port, mount);
if (pezConfig->fileNameIsProgram ||
@ -1327,32 +1208,32 @@ main(int argc, char *argv[])
else
playlistMode = 0;
if (vFlag && pezConfig->fileNameIsProgram)
if (cfg_verbosity() && pezConfig->fileNameIsProgram)
printf("%s: Using program '%s' to get filenames for streaming\n",
__progname, pezConfig->fileName);
cfg_progname(), pezConfig->fileName);
do {
if (playlistMode) {
ret = streamPlaylist(shout, pezConfig->fileName);
cont = streamPlaylist(shout, pezConfig->fileName);
} else {
ret = streamFile(shout, pezConfig->fileName);
cont = streamFile(shout, pezConfig->fileName);
}
if (quit)
break;
if (pezConfig->streamOnce)
break;
} while (ret);
} while (cont);
shout_close(shout);
} else
printf("%s: Connection to http://%s:%hu%s failed: %s\n", __progname,
printf("%s: Connection to http://%s:%hu%s failed: %s\n", cfg_progname(),
host, port, mount, shout_get_error(shout));
if (quit)
printf("\r%s: SIGINT or SIGTERM received\n", __progname);
printf("\r%s: SIGINT or SIGTERM received\n", cfg_progname());
if (vFlag)
printf("%s: Exiting ...\n", __progname);
if (cfg_verbosity())
printf("%s: Exiting ...\n", cfg_progname());
xfree(host);
xfree(mount);

View File

@ -50,6 +50,8 @@
# include <unistd.h>
#endif
#include "cfg.h"
#ifndef STDIN_FILENO
# define STDIN_FILENO 0
#endif /* !STDIN_FILENO */

View File

@ -30,6 +30,7 @@
#endif /* HAVE_VORBISFILE */
#include <shout/shout.h>
#include "cfg.h"
#include "metadata.h"
#include "util.h"
#include "xalloc.h"
@ -39,9 +40,6 @@
# define S_IEXEC S_IXUSR
#endif /* !S_IEXEC */
extern char *__progname;
extern int vFlag;
static const char *blankString = "";
struct metadata {
@ -96,7 +94,7 @@ metadata_use_taglib(metadata_t *md, FILE **filep)
if (md == NULL || md->filename == NULL) {
printf("%s: metadata_use_taglib(): Internal error: Bad arguments\n",
__progname);
cfg_progname());
abort();
}
@ -148,7 +146,7 @@ metadata_use_taglib(metadata_t *md, FILE **filep)
(void)filep;
printf("%s: Internal error: metadata_use_taglib() called without TagLib support\n",
__progname);
cfg_progname());
abort();
}
#endif /* HAVE_TAGLIB */
@ -161,7 +159,7 @@ metadata_use_self(metadata_t *md, FILE **filep)
(void)filep;
printf("%s: Internal error: metadata_use_self() called with TagLib support\n",
__progname);
cfg_progname());
abort();
}
#else
@ -172,7 +170,7 @@ metadata_use_self(metadata_t *md, FILE **filep)
if (md == NULL || filep == NULL || *filep == NULL ||
md->filename == NULL) {
printf("%s: metadata_use_self(): Internal error: Bad arguments\n",
__progname);
cfg_progname());
abort();
}
@ -198,27 +196,27 @@ metadata_use_self(metadata_t *md, FILE **filep)
switch (ret) {
case OV_EREAD:
printf("%s: ov_open(): %s: Media read error\n",
__progname, md->filename);
cfg_progname(), md->filename);
break;
case OV_ENOTVORBIS:
printf("%s: ov_open(): %s: Invalid Vorbis bitstream\n",
__progname, md->filename);
cfg_progname(), md->filename);
break;
case OV_EVERSION:
printf("%s: ov_open(): %s: Vorbis version mismatch\n",
__progname, md->filename);
cfg_progname(), md->filename);
break;
case OV_EBADHEADER:
printf("%s: ov_open(): %s: Invalid Vorbis bitstream header\n",
__progname, md->filename);
cfg_progname(), md->filename);
break;
case OV_EFAULT:
printf("%s: Fatal: Internal libvorbisfile fault\n",
__progname);
cfg_progname());
abort();
default:
printf("%s: ov_open(): %s: ov_read() returned unknown error\n",
__progname, md->filename);
cfg_progname(), md->filename);
break;
}
} else {
@ -256,7 +254,7 @@ metadata_clean_md(metadata_t *md)
{
if (md == NULL) {
printf("%s: Internal error: metadata_clean_md(): NULL argument\n",
__progname);
cfg_progname());
abort();
}
@ -281,7 +279,7 @@ metadata_get_extension(char *buf, size_t siz, const char *filename)
if (buf == NULL || siz == 0 || filename == NULL) {
printf("%s: metadata_get_extension(): Internal error: Bad arguments\n",
__progname);
cfg_progname());
abort();
}
@ -301,13 +299,13 @@ metadata_get_name(const char *file)
if (file == NULL) {
printf("%s: metadata_get_name(): Internal error: Bad arguments\n",
__progname);
cfg_progname());
abort();
}
if ((p1 = basename(filename)) == NULL) {
printf("%s: Internal error: basename() failed with '%s'\n",
__progname, filename);
cfg_progname(), filename);
exit(1);
}
@ -328,7 +326,7 @@ metadata_process_md(metadata_t *md)
{
if (md == NULL) {
printf("%s: metadata_process_md(): Internal error: Bad arguments\n",
__progname);
cfg_progname());
abort();
}
@ -380,7 +378,7 @@ metadata_file(const char *filename, int normalize)
if (filename == NULL || strlen(filename) == 0) {
printf("%s: metadata_file(): Internal error: Bad arguments\n",
__progname);
cfg_progname());
abort();
}
@ -407,7 +405,7 @@ metadata_program(const char *program, int normalize)
if (program == NULL || strlen(program) == 0) {
printf("%s: metadata_program(): Internal error: Bad arguments\n",
__progname);
cfg_progname());
abort();
}
@ -417,24 +415,24 @@ metadata_program(const char *program, int normalize)
#ifdef HAVE_STAT
if (stat(program, &st) == -1) {
printf("%s: %s: %s\n", __progname, program, strerror(errno));
printf("%s: %s: %s\n", cfg_progname(), program, strerror(errno));
metadata_free(&md);
return (NULL);
}
if (st.st_mode & (S_IWGRP | S_IWOTH)) {
printf("%s: Error: %s is group and/or world writeable\n",
__progname, program);
cfg_progname(), program);
metadata_free(&md);
return (NULL);
}
if (!(st.st_mode & (S_IEXEC | S_IXGRP | S_IXOTH))) {
printf("%s: %s: Not an executable program\n", __progname, program);
printf("%s: %s: Not an executable program\n", cfg_progname(), program);
metadata_free(&md);
return (NULL);
}
#else
if ((filep = fopen(program, "r")) == NULL) {
printf("%s: %s: %s\n", __progname, program, strerror(errno));
printf("%s: %s: %s\n", cfg_progname(), program, strerror(errno));
metadata_free(&md);
return (NULL);
}
@ -471,18 +469,18 @@ metadata_file_update(metadata_t *md)
if (md == NULL) {
printf("%s: metadata_file_update(): Internal error: NULL argument\n",
__progname);
cfg_progname());
abort();
}
if (md->program) {
printf("%s: metadata_file_update(): Internal error: Called with program handle\n",
__progname);
cfg_progname());
abort();
}
if ((filep = fopen(md->filename, "rb")) == NULL) {
printf("%s: %s: %s\n", __progname, md->filename, strerror(errno));
printf("%s: %s: %s\n", cfg_progname(), md->filename, strerror(errno));
return (0);
}
@ -506,13 +504,13 @@ metadata_program_update(metadata_t *md, enum metadata_request md_req)
if (md == NULL) {
printf("%s: metadata_program_update(): Internal error: NULL argument\n",
__progname);
cfg_progname());
abort();
}
if (!md->program) {
printf("%s: metadata_program_update(): Internal error: Received file handle\n",
__progname);
cfg_progname());
abort();
}
@ -548,18 +546,18 @@ metadata_program_update(metadata_t *md, enum metadata_request md_req)
break;
default:
printf("%s: metadata_program_update(): Internal error: Unknown md_req\n",
__progname);
cfg_progname());
abort();
}
fflush(NULL);
errno = 0;
if (vFlag > 1)
printf("%s: Running command `%s`\n", __progname,
if (cfg_verbosity() > 1)
printf("%s: Running command `%s`\n", cfg_progname(),
command);
if ((filep = popen(command, "r")) == NULL) {
printf("%s: playlist_run_program(): Error while executing '%s'",
__progname, command);
cfg_progname(), command);
/* popen() does not set errno reliably ... */
if (errno)
printf(": %s\n", strerror(errno));
@ -571,10 +569,10 @@ metadata_program_update(metadata_t *md, enum metadata_request md_req)
if (fgets(buf, (int)sizeof(buf), filep) == NULL) {
if (ferror(filep))
printf("%s: Error while reading output from program '%s': %s\n",
__progname, md->filename, strerror(errno));
cfg_progname(), md->filename, strerror(errno));
pclose(filep);
printf("%s: FATAL: External program '%s' not (or no longer) usable.\n",
__progname, md->filename);
cfg_progname(), md->filename);
exit(1);
}
@ -582,7 +580,7 @@ metadata_program_update(metadata_t *md, enum metadata_request md_req)
if (strlen(buf) == sizeof(buf) - 1)
printf("%s: Warning: Metadata string received via '%s' is too long and has been truncated\n",
__progname, command);
cfg_progname(), command);
buf[strcspn(buf, "\n")] = '\0';
buf[strcspn(buf, "\r")] = '\0';
@ -591,7 +589,7 @@ metadata_program_update(metadata_t *md, enum metadata_request md_req)
case METADATA_STRING:
if (strlen(buf) == 0) {
printf("%s: Warning: Empty metadata string received from '%s'\n",
__progname, md->filename);
cfg_progname(), md->filename);
md->string = xstrdup("");
} else
md->string = xstrdup(buf);
@ -607,7 +605,7 @@ metadata_program_update(metadata_t *md, enum metadata_request md_req)
case METADATA_ALL:
default:
printf("%s: metadata_program_update(): Internal error: METADATA_ALL in code unreachable by METADATA_ALL\n",
__progname);
cfg_progname());
abort();
}
@ -625,13 +623,13 @@ metadata_get_string(metadata_t *md)
{
if (md == NULL) {
printf("%s: metadata_get_string(): Internal error: Bad arguments\n",
__progname);
cfg_progname());
abort();
}
if (md->string == NULL) {
printf("%s: metadata_get_string(): Internal error: md->string cannot be NULL\n",
__progname);
cfg_progname());
abort();
}
@ -643,7 +641,7 @@ metadata_get_artist(metadata_t *md)
{
if (md == NULL) {
printf("%s: metadata_get_artist(): Internal error: Bad arguments\n",
__progname);
cfg_progname());
abort();
}
@ -658,7 +656,7 @@ metadata_get_title(metadata_t *md)
{
if (md == NULL) {
printf("%s: metadata_get_title(): Internal error: Bad arguments\n",
__progname);
cfg_progname());
abort();
}
@ -673,7 +671,7 @@ metadata_get_filename(metadata_t *md)
{
if (md == NULL) {
printf("%s: metadata_get_filename(): Internal error: Bad arguments\n",
__progname);
cfg_progname());
abort();
}
@ -689,7 +687,7 @@ metadata_get_length(metadata_t *md)
{
if (md == NULL) {
printf("%s: metadata_get_length(): Internal error: Bad arguments\n",
__progname);
cfg_progname());
abort();
}
@ -704,7 +702,7 @@ metadata_assemble_string(metadata_t *md)
if (md == NULL) {
printf("%s: metadata_assemble_string(): Internal error: Bad arguments\n",
__progname);
cfg_progname());
abort();
}

View File

@ -20,6 +20,7 @@
#include "ezstream.h"
#include "cfg.h"
#include "playlist.h"
#include "xalloc.h"
@ -28,8 +29,6 @@
# define S_IEXEC S_IXUSR
#endif /* !S_IEXEC */
extern char *__progname;
struct playlist {
char *filename;
char **list;
@ -63,7 +62,7 @@ playlist_add(playlist_t *pl, const char *entry)
if (pl == NULL || entry == NULL) {
printf("%s: playlist_add(): Internal error: Bad arguments\n",
__progname);
cfg_progname());
exit(1);
}
@ -134,7 +133,7 @@ playlist_read(const char *filename)
pl = playlist_create(filename);
if ((filep = fopen(filename, "r")) == NULL) {
printf("%s: %s: %s\n", __progname, filename, strerror(errno));
printf("%s: %s: %s\n", cfg_progname(), filename, strerror(errno));
playlist_free(&pl);
return (NULL);
}
@ -142,7 +141,7 @@ playlist_read(const char *filename)
pl = playlist_create("stdin");
if ((filep = fdopen(STDIN_FILENO, "r")) == NULL) {
printf("%s: stdin: %s\n", __progname, strerror(errno));
printf("%s: stdin: %s\n", cfg_progname(), strerror(errno));
playlist_free(&pl);
return (NULL);
}
@ -190,7 +189,7 @@ playlist_read(const char *filename)
}
if (ferror(filep)) {
printf("%s: playlist_read(): Error while reading %s: %s\n",
__progname, pl->filename, strerror(errno));
cfg_progname(), pl->filename, strerror(errno));
fclose(filep);
playlist_free(&pl);
return (NULL);
@ -215,24 +214,24 @@ playlist_program(const char *filename)
#ifdef HAVE_STAT
if (stat(filename, &st) == -1) {
printf("%s: %s: %s\n", __progname, filename, strerror(errno));
printf("%s: %s: %s\n", cfg_progname(), filename, strerror(errno));
playlist_free(&pl);
return (NULL);
}
if (st.st_mode & (S_IWGRP | S_IWOTH)) {
printf("%s: Error: %s is group and/or world writeable\n",
__progname, filename);
cfg_progname(), filename);
playlist_free(&pl);
return (NULL);
}
if (!(st.st_mode & (S_IEXEC | S_IXGRP | S_IXOTH))) {
printf("%s: %s: Not an executable program\n", __progname, filename);
printf("%s: %s: Not an executable program\n", cfg_progname(), filename);
playlist_free(&pl);
return (NULL);
}
#else
if ((filep = fopen(filename, "r")) == NULL) {
printf("%s: %s: %s\n", __progname, filename, strerror(errno));
printf("%s: %s: %s\n", cfg_progname(), filename, strerror(errno));
playlist_free(&pl);
return (NULL);
}
@ -283,7 +282,7 @@ playlist_get_next(playlist_t *pl)
{
if (pl == NULL) {
printf("%s: playlist_get_next(): Internal error: NULL argument\n",
__progname);
cfg_progname());
exit(1);
}
@ -301,7 +300,7 @@ playlist_peek_next(playlist_t *pl)
{
if (pl == NULL) {
printf("%s: playlist_peek_next(): Internal error: NULL argument\n",
__progname);
cfg_progname());
exit(1);
}
@ -316,7 +315,7 @@ playlist_skip_next(playlist_t *pl)
{
if (pl == NULL) {
printf("%s: playlist_skip_next(): Internal error: NULL argument\n",
__progname);
cfg_progname());
exit(1);
}
@ -332,7 +331,7 @@ playlist_get_num_items(playlist_t *pl)
{
if (pl == NULL) {
printf("%s: playlist_get_position(): Internal error: NULL argument\n",
__progname);
cfg_progname());
exit(1);
}
@ -347,7 +346,7 @@ playlist_get_position(playlist_t *pl)
{
if (pl == NULL) {
printf("%s: playlist_get_position(): Internal error: NULL argument\n",
__progname);
cfg_progname());
exit(1);
}
@ -362,7 +361,7 @@ playlist_set_position(playlist_t *pl, unsigned long idx)
{
if (pl == NULL) {
printf("%s: playlist_set_position(): Internal error: NULL argument\n",
__progname);
cfg_progname());
exit(1);
}
@ -381,7 +380,7 @@ playlist_goto_entry(playlist_t *pl, const char *entry)
if (pl == NULL || entry == NULL) {
printf("%s: playlist_goto_entry(): Internal error: Bad arguments\n",
__progname);
cfg_progname());
exit(1);
}
@ -403,7 +402,7 @@ playlist_rewind(playlist_t *pl)
{
if (pl == NULL) {
printf("%s: playlist_rewind(): Internal error: NULL argument\n",
__progname);
cfg_progname());
exit(1);
}
@ -420,7 +419,7 @@ playlist_reread(playlist_t **plist)
if (plist == NULL || *plist == NULL) {
printf("%s: playlist_reread(): Internal error: NULL argument\n",
__progname);
cfg_progname());
exit(1);
}
@ -449,7 +448,7 @@ playlist_shuffle(playlist_t *pl)
if (pl == NULL) {
printf("%s: playlist_shuffle(): Internal error: NULL argument\n",
__progname);
cfg_progname());
exit(1);
}
@ -487,7 +486,7 @@ playlist_run_program(playlist_t *pl)
if (pl == NULL) {
printf("%s: playlist_run_program(): Internal error: NULL argument\n",
__progname);
cfg_progname());
exit(1);
}
@ -498,7 +497,7 @@ playlist_run_program(playlist_t *pl)
errno = 0;
if ((filep = popen(pl->filename, "r")) == NULL) {
printf("%s: playlist_run_program(): Error while executing '%s'",
__progname, pl->filename);
cfg_progname(), pl->filename);
/* popen() does not set errno reliably ... */
if (errno)
printf(": %s\n", strerror(errno));
@ -514,7 +513,7 @@ playlist_run_program(playlist_t *pl)
if (ferror(filep)) {
printf("%s: Error while reading output from program '%s': %s\n",
__progname, pl->filename, strerror(errnum));
cfg_progname(), pl->filename, strerror(errnum));
exit(1);
}
@ -525,7 +524,7 @@ playlist_run_program(playlist_t *pl)
pclose(filep);
if (strlen(buf) == sizeof(buf) - 1) {
printf("%s: Output from program '%s' too long\n", __progname,
printf("%s: Output from program '%s' too long\n", cfg_progname(),
pl->filename);
return (NULL);
}

View File

@ -45,7 +45,6 @@
#endif
extern EZCONFIG *pezConfig;
extern char *__progname;
char * iconvert(const char *, const char *, const char *, int);
@ -89,42 +88,42 @@ stream_setup(const char *host, unsigned short port, const char *mount)
shout_t *shout = NULL;
if ((shout = shout_new()) == NULL) {
printf("%s: shout_new(): %s", __progname, strerror(ENOMEM));
printf("%s: shout_new(): %s", cfg_progname(), strerror(ENOMEM));
return (NULL);
}
if (shout_set_host(shout, host) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_host(): %s\n", __progname,
printf("%s: shout_set_host(): %s\n", cfg_progname(),
shout_get_error(shout));
shout_free(shout);
return (NULL);
}
if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_protocol(): %s\n", __progname,
printf("%s: shout_set_protocol(): %s\n", cfg_progname(),
shout_get_error(shout));
shout_free(shout);
return (NULL);
}
if (shout_set_port(shout, port) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_port: %s\n", __progname,
printf("%s: shout_set_port: %s\n", cfg_progname(),
shout_get_error(shout));
shout_free(shout);
return (NULL);
}
if (shout_set_password(shout, pezConfig->password) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_password(): %s\n", __progname,
printf("%s: shout_set_password(): %s\n", cfg_progname(),
shout_get_error(shout));
shout_free(shout);
return (NULL);
}
if (shout_set_mount(shout, mount) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_mount(): %s\n", __progname,
printf("%s: shout_set_mount(): %s\n", cfg_progname(),
shout_get_error(shout));
shout_free(shout);
return (NULL);
}
if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS) {
printf("%s: shout_set_user(): %s\n", __progname,
printf("%s: shout_set_user(): %s\n", cfg_progname(),
shout_get_error(shout));
shout_free(shout);
return (NULL);
@ -133,7 +132,7 @@ stream_setup(const char *host, unsigned short port, const char *mount)
if (!strcmp(pezConfig->format, MP3_FORMAT) &&
shout_set_format(shout, SHOUT_FORMAT_MP3) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_format(MP3): %s\n",
__progname, shout_get_error(shout));
cfg_progname(), shout_get_error(shout));
shout_free(shout);
return (NULL);
}
@ -141,7 +140,7 @@ stream_setup(const char *host, unsigned short port, const char *mount)
!strcmp(pezConfig->format, THEORA_FORMAT)) &&
shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_format(OGG): %s\n",
__progname, shout_get_error(shout));
cfg_progname(), shout_get_error(shout));
shout_free(shout);
return (NULL);
}
@ -149,70 +148,70 @@ stream_setup(const char *host, unsigned short port, const char *mount)
if (pezConfig->username &&
shout_set_user(shout, pezConfig->username) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_user(): %s\n",
__progname, shout_get_error(shout));
cfg_progname(), shout_get_error(shout));
shout_free(shout);
return (NULL);
}
if (pezConfig->serverName &&
shout_set_name(shout, pezConfig->serverName) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_name(): %s\n",
__progname, shout_get_error(shout));
cfg_progname(), shout_get_error(shout));
shout_free(shout);
return (NULL);
}
if (pezConfig->serverURL &&
shout_set_url(shout, pezConfig->serverURL) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_url(): %s\n",
__progname, shout_get_error(shout));
cfg_progname(), shout_get_error(shout));
shout_free(shout);
return (NULL);
}
if (pezConfig->serverGenre &&
shout_set_genre(shout, pezConfig->serverGenre) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_genre(): %s\n",
__progname, shout_get_error(shout));
cfg_progname(), shout_get_error(shout));
shout_free(shout);
return (NULL);
}
if (pezConfig->serverDescription &&
shout_set_description(shout, pezConfig->serverDescription) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_description(): %s\n",
__progname, shout_get_error(shout));
cfg_progname(), shout_get_error(shout));
shout_free(shout);
return (NULL);
}
if (pezConfig->serverBitrate &&
shout_set_audio_info(shout, SHOUT_AI_BITRATE, pezConfig->serverBitrate) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_audio_info(AI_BITRATE): %s\n",
__progname, shout_get_error(shout));
cfg_progname(), shout_get_error(shout));
shout_free(shout);
return (NULL);
}
if (pezConfig->serverChannels &&
shout_set_audio_info(shout, SHOUT_AI_CHANNELS, pezConfig->serverChannels) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_audio_info(AI_CHANNELS): %s\n",
__progname, shout_get_error(shout));
cfg_progname(), shout_get_error(shout));
shout_free(shout);
return (NULL);
}
if (pezConfig->serverSamplerate &&
shout_set_audio_info(shout, SHOUT_AI_SAMPLERATE, pezConfig->serverSamplerate) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_audio_info(AI_SAMPLERATE): %s\n",
__progname, shout_get_error(shout));
cfg_progname(), shout_get_error(shout));
shout_free(shout);
return (NULL);
}
if (pezConfig->serverQuality &&
shout_set_audio_info(shout, SHOUT_AI_QUALITY, pezConfig->serverQuality) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_audio_info(AI_QUALITY): %s\n",
__progname, shout_get_error(shout));
cfg_progname(), shout_get_error(shout));
shout_free(shout);
return (NULL);
}
if (shout_set_public(shout, (unsigned int)pezConfig->serverPublic) != SHOUTERR_SUCCESS) {
printf("%s: shout_set_public(): %s\n",
__progname, shout_get_error(shout));
cfg_progname(), shout_get_error(shout));
shout_free(shout);
return (NULL);
}
@ -293,7 +292,7 @@ iconvert(const char *in_str, const char *from, const char *to, int mode)
(cd = iconv_open("", from)) == (iconv_t)-1 &&
(cd = iconv_open(tocode, "")) == (iconv_t)-1) {
xfree(tocode);
printf("%s: iconv_open(): %s\n", __progname, strerror(errno));
printf("%s: iconv_open(): %s\n", cfg_progname(), strerror(errno));
return (xstrdup(in_str));
}
@ -332,7 +331,7 @@ iconvert(const char *in_str, const char *from, const char *to, int mode)
}
if (iconv_close(cd) == -1) {
printf("%s: iconv_close(): %s\n", __progname, strerror(errno));
printf("%s: iconv_close(): %s\n", cfg_progname(), strerror(errno));
xfree(output);
xfree(tocode);
return (xstrdup(in_str));