[xiph-commits] r12550 - trunk/ezstream/src
moritz at svn.xiph.org
moritz at svn.xiph.org
Sat Feb 24 16:25:09 PST 2007
Author: moritz
Date: 2007-02-24 16:25:07 -0800 (Sat, 24 Feb 2007)
New Revision: 12550
Modified:
trunk/ezstream/src/ezstream.c
Log:
Begin merging ezstream.c changes. This first batch includes:
* License reference and various #include cleanups and additions that are
required later.
* Add new usage() and usageHelp() functions (which already contain what's
to come.) Move them close to main() where getopt() is called.
* New signal handler, which now no longer uses printf(). printf() is not safe
to use in signal handlers. Use volatile sig_atomic_t types instead of ints
as flags to set in the handler.
* Formatting and const'ifying of WIN32-basename() and strrcmp(). Rearrange
them so that the actual "worker functions" are grouped together.
* Add function prototypes for those that are already up-to-date.
* Rename ReplaceString() to replaceString() for consistency with other
function names in Ezstream.
* Prepare for portable *__progname usage.
Modified: trunk/ezstream/src/ezstream.c
===================================================================
--- trunk/ezstream/src/ezstream.c 2007-02-24 23:26:16 UTC (rev 12549)
+++ trunk/ezstream/src/ezstream.c 2007-02-25 00:25:07 UTC (rev 12550)
@@ -1,43 +1,124 @@
-/* example.c: Demonstration of the libshout API. */
+/*
+ * ezstream - source client for Icecast with external en-/decoder support
+ * Copyright (C) 2003, 2004, 2005, 2006 Ed Zaleski <oddsock at oddsock.org>
+ * Copyright (C) 2007 Moritz Grimm <gtgbr at gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#ifdef HAVE_PATHS_H
+# include <paths.h>
+#endif
+#ifdef HAVE_SIGNAL_H
+# include <signal.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#ifdef WIN32
-#include <fcntl.h>
-#include <io.h>
-#include <windows.h>
+# include <io.h>
+# include <windows.h>
+#else
+# include <libgen.h>
+# include <unistd.h>
+#endif /* WIN32 */
+#include <shout/shout.h>
+#include <vorbis/vorbisfile.h>
+
+#ifndef HAVE_GETOPT
+# include "getopt.h"
#endif
-#include <shout/shout.h>
-#include <getopt.h>
+#if !defined(HAVE_STRLCAT) || !defined(HAVE_STRLCPY)
+# include "strlfctns.h"
+#endif
#include "configfile.h"
-#ifndef WIN32
-#include <libgen.h>
-#include <unistd.h>
+#include "playlist.h"
+#include "util.h"
+
+#ifndef PATH_MAX
+# define PATH_MAX 256
#endif
-#include <vorbis/vorbisfile.h>
+/* For Solaris, possibly others (usually defined in <paths.h>.) */
+#ifndef _PATH_DEVNULL
+# define _PATH_DEVNULL "/dev/null"
+#endif /* _PATH_DEVNULL */
+
+#ifdef WIN32
+# define STRNCASECMP strnicmp
+# define popen _popen
+# define pclose _pclose
+# define snprintf _snprintf
+# define stat _stat
+#else
+# define STRNCASECMP strncasecmp
+#endif /* WIN32 */
+
+#ifdef HAVE___PROGNAME
+extern char *__progname;
+#else
+char *__progname;
+#endif /* HAVE___PROGNAME */
+
+int qFlag;
+int vFlag;
+
EZCONFIG *pezConfig = NULL;
-int rereadPlaylist = 0;
static char *blankString = "";
+playlist_t *playlist = NULL;
+int playlistMode = 0;
-#ifndef WIN32
-#include <signal.h>
+#ifdef HAVE_SIGNALS
+volatile sig_atomic_t rereadPlaylist = 0;
+volatile sig_atomic_t rereadPlaylist_notify = 0;
+volatile sig_atomic_t skipTrack = 0;
-void hup_handler(int sig)
+void
+sig_handler(int sig)
{
- rereadPlaylist = 1;
- printf("Will reread the playlist on next song\n");
+ switch (sig) {
+ case SIGHUP:
+ rereadPlaylist = 1;
+ rereadPlaylist_notify = 1;
+ break;
+ case SIGUSR1:
+ skipTrack = 1;
+ break;
+ default:
+ break;
+ }
}
-#endif
-#ifdef WIN32
-#define STRNCASECMP strnicmp
-#define popen _popen
-#define pclose _pclose
-#define snprintf _snprintf
#else
-#define STRNCASECMP strncasecmp
-#endif
+int rereadPlaylist = 0;
+int rereadPlaylist_notify = 0;
+int skipTrack = 0;
+#endif /* HAVE_SIGNALS */
typedef struct tag_ID3Tag {
char tag[3];
@@ -49,27 +130,39 @@
char genre;
} ID3Tag;
-void usage() {
- fprintf(stdout, "usage: ezstream -h -c ezstream.xml\n");
- fprintf(stdout, "where :\n");
- fprintf(stdout, " -h = display this help\n");
- fprintf(stdout, " -c = ezstream config file\n");
-
- exit(1);
+#ifdef WIN32
+char * basename(const char *);
+#endif
+int strrcmp(const char *, const char *);
+char * getProgname(const char *);
+void usage(void);
+void usageHelp(void);
+
+#ifdef WIN32
+char *
+basename(const char *fileName)
+{
+ char *pLast = strrchr(fileName, '\\');
+
+ if (pLast != NULL)
+ return (pLast + 1);
+
+ return (NULL);
}
+#endif /* WIN32 */
-int strrcmp(char *s, char *sub)
+int
+strrcmp(const char *s, const char *sub)
{
- int slen = strlen(s);
- int sublen = strlen(sub);
+ int slen = strlen(s);
+ int sublen = strlen(sub);
- if (sublen > slen) {
- return 1;
- }
- return memcmp(s + slen - sublen, sub, sublen);
+ if (sublen > slen)
+ return (1);
+
+ return (memcmp(s + slen - sublen, sub, sublen));
}
-
int urlParse(char *url, char *hostname, int *port, char *mountname)
{
char *p1;
@@ -102,7 +195,7 @@
}
-void ReplaceString(char *source, char *dest, char *from, char *to)
+void replaceString(char *source, char *dest, char *from, char *to)
{
char *p2 = (char *)1;
char *p1 = source;
@@ -146,7 +239,7 @@
newDecoderLen = strlen(decoder) + strlen(fileName) + 1;
newDecoder = (char *)malloc(newDecoderLen);
memset(newDecoder, '\000', newDecoderLen);
- ReplaceString(decoder, newDecoder, "@T@", fileName);
+ replaceString(decoder, newDecoder, "@T@", fileName);
encoder = strdup(getFormatEncoder(pezConfig->format));
if (strlen(encoder) == 0) {
@@ -168,7 +261,7 @@
newEncoderLen = strlen(encoder) + strlen(metadata) + 1;
newEncoder = (char *)malloc(newEncoderLen);
memset(newEncoder, '\000', newEncoderLen);
- ReplaceString(encoder, newEncoder, "@M@", metadata);
+ replaceString(encoder, newEncoder, "@M@", metadata);
commandStringLen = strlen(newDecoder) + strlen(" | ") + strlen(newEncoder) + 1;
commandString = (char *)malloc(commandStringLen);
@@ -185,15 +278,6 @@
return(commandString);
}
-#ifdef WIN32
-char *basename(char *fileName) {
- char *pLast = strrchr(fileName, '\\');
- if (pLast) {
- return pLast+1;
- }
- return NULL;
-}
-#endif
char * processMetadata(shout_t *shout, char *extension, char *fileName) {
FILE *filepstream = NULL;
char *artist = NULL;
@@ -356,7 +440,6 @@
}
-
int streamFile(shout_t *shout, char *fileName) {
FILE *filepstream = NULL;
char buff[4096];
@@ -417,6 +500,7 @@
filepstream = NULL;
return ret;
}
+
int streamPlaylist(shout_t *shout, char *fileName) {
FILE *filep = NULL;
char streamFileName[8096] = "";
@@ -479,8 +563,48 @@
return(1);
}
-int main(int argc, char **argv)
+/* Borrowed from OpenNTPd-portable's compat-openbsd/bsd-misc.c */
+char *
+getProgname(const char *argv0)
{
+#ifdef HAVE___PROGNAME
+ return (xstrdup(__progname));
+#else
+ char *p;
+
+ if (argv0 == NULL)
+ return ((char *)"ezstream");
+ p = strrchr(argv0, '/');
+ if (p == NULL)
+ p = argv0;
+ else
+ p++;
+
+ return (xstrdup(p));
+#endif /* HAVE___PROGNAME */
+}
+
+void
+usage(void)
+{
+ printf("usage: %s [-hqv] [-c configfile]\n", __progname);
+}
+
+void
+usageHelp(void)
+{
+ printf("\n");
+ printf(" -c configfile use XML configuration in configfile\n");
+ printf(" -h display this additional help and exit\n");
+ printf(" -q suppress STDERR output from external en-/decoders\n");
+ printf(" -v verbose output\n");
+ printf("\n");
+ printf("See the ezstream(1) manual for detailed information.\n");
+}
+
+int
+main(int argc, char **argv)
+{
char c;
char *configFile = NULL;
char *host = NULL;
@@ -491,7 +615,7 @@
pezConfig = getEZConfig();
#ifndef WIN32
- signal(SIGHUP, hup_handler);
+ signal(SIGHUP, sig_handler);
#endif
shout_init();
@@ -503,7 +627,8 @@
break;
case 'h':
usage();
- break;
+ usageHelp();
+ return (0);
default:
break;
}
More information about the commits
mailing list