[xiph-commits] r13655 - in experimental/moritz/iceadmin: . examples src

moritz at svn.xiph.org moritz at svn.xiph.org
Wed Aug 29 09:45:20 PDT 2007


Author: moritz
Date: 2007-08-29 09:45:20 -0700 (Wed, 29 Aug 2007)
New Revision: 13655

Modified:
   experimental/moritz/iceadmin/configure.in
   experimental/moritz/iceadmin/examples/iceadmin.conf
   experimental/moritz/iceadmin/src/cfg.c
   experimental/moritz/iceadmin/src/cfg.h
   experimental/moritz/iceadmin/src/iceadmin.c
Log:
Avoid losing work. Right now, this is only a very rough step into the direction
I want this to go ...


Modified: experimental/moritz/iceadmin/configure.in
===================================================================
--- experimental/moritz/iceadmin/configure.in	2007-08-29 16:43:30 UTC (rev 13654)
+++ experimental/moritz/iceadmin/configure.in	2007-08-29 16:45:20 UTC (rev 13655)
@@ -41,19 +41,20 @@
 
 AC_CANONICAL_HOST
 
+XIPH_CPPFLAGS="-DSYSCONF_DIR=\"\\\"${sysconfdir}\\\"\""
 if test -z "$GCC"; then
 	case $host in 
 	*-irix*)
-		XIPH_CPPFLAGS="-fullwarn"
+		XIPH_CPPFLAGS="$XIPH_CPPFLAGS -fullwarn"
 		;;
 	*-solaris*)
-		XIPH_CPPFLAGS="-v"
+		XIPH_CPPFLAGS="$XIPH_CPPFLAGS -v"
 		;;
 	*)
 		;;
 	esac
 else
-	XIPH_CPPFLAGS="-fstrict-aliasing -Wall -W -ansi -pedantic -Wno-unused-parameter -Wwrite-strings -Wpointer-arith -Wsign-compare -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations"
+	XIPH_CPPFLAGS="$XIPH_CPPFLAGS -fstrict-aliasing -Wall -W -ansi -pedantic -Wno-unused-parameter -Wwrite-strings -Wpointer-arith -Wsign-compare -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations"
 fi
 
 XALLOC_CPPFLAGS=""
@@ -82,7 +83,7 @@
 
 dnl USEFUL HEADERS
 
-AC_CHECK_HEADERS(sys/socket.h netdb.h)
+AC_CHECK_HEADERS(sys/socket.h sys/stat.h netdb.h)
 
 COMPAT_INCLUDES=""
 if test x"$ia_enable_debug" = "xyes"; then

Modified: experimental/moritz/iceadmin/examples/iceadmin.conf
===================================================================
--- experimental/moritz/iceadmin/examples/iceadmin.conf	2007-08-29 16:43:30 UTC (rev 13654)
+++ experimental/moritz/iceadmin/examples/iceadmin.conf	2007-08-29 16:45:20 UTC (rev 13655)
@@ -15,9 +15,15 @@
 # configuration.
 #
 # Available configuration keys are 'hostname', 'service', 'username',
-# 'password' and 'default_mountpoint'.
+# 'password' and 'default_mountpoint'. Keys are followed by an equal
+# sign '=' and a value in double-quotes '"'. Each key/value pair is
+# optional.
+#
+# Values may contain double-quotes as long as they are escaped with
+# a backslash, e.g. "foo\"bar". The backslash itself must be escaped
+# as well, e.g. "foo\\bar".
 
-#[local] 	# A local Icecast server called "local".
+#[local] 	# A local Icecast server configuration called "local".
 #    hostname		= "localhost"	# - This can be a hostname or an IP.
 #    service		= "8000"	# - Port number or service from
 #					#   /etc/services.

Modified: experimental/moritz/iceadmin/src/cfg.c
===================================================================
--- experimental/moritz/iceadmin/src/cfg.c	2007-08-29 16:43:30 UTC (rev 13654)
+++ experimental/moritz/iceadmin/src/cfg.c	2007-08-29 16:45:20 UTC (rev 13655)
@@ -2,6 +2,12 @@
 # include "config.h"
 #endif
 
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
 #include <sys/tree.h>
 #include <errno.h>
 #include <limits.h>
@@ -52,15 +58,21 @@
 void
 _cfg_print_usage(void)
 {
+	fprintf(stderr, "usage: %s [-h] [-c configfile]\n",
+		__progname);
 }
 
 void
 _cfg_print_usagehelp(void)
 {
+	fprintf(stderr, "\n");
+	fprintf(stderr, "  -c configfile  use configuration defaults in configfile\n");
+	fprintf(stderr, "  -h             display this additional help and exit\n");
+	fprintf(stderr, "\n");
 }
 
 int
-cfg_parse_cmdline(int argc, char *argv[])
+cfg_parse_cmdopts(int *argc, char **argv[])
 {
 	extern char	*optarg;
 	extern int	 optind;
@@ -72,12 +84,12 @@
 	cfgfile = NULL;
 	cfgfile_name[0] = '\0';
 
-	while ((ch = getopt(argc, argv, optstring)) != -1) {
+	while ((ch = getopt(*argc, *argv, optstring)) != -1) {
+#ifdef S_IROTH
+		struct stat	st;
+#endif /* S_IROTH */
+
 		switch (ch) {
-		case 'h':
-			_cfg_print_usage();
-			_cfg_print_usagehelp();
-			return (0);
 		case 'c':
 			if (cfgfile != NULL) {
 				fprintf(stderr, "%s: Error: Multiple -c arguments given\n",
@@ -86,25 +98,64 @@
 				return (2);
 			}
 			snprintf(cfgfile_name, sizeof(cfgfile_name), "%s", optarg);
+#ifdef S_IROTH
+			if (stat(cfgfile_name, &st) != -1 &&
+			    (st.st_mode & S_IROTH)) {
+				fprintf(stderr, "WARNING: %s is world-readable!\n",
+					cfgfile_name);
+			}
+#endif /* S_IROTH */
 			if ((cfgfile = fopen(cfgfile_name, "r")) == NULL) {
-				fprintf(stderr, "%s: %s: %s\n", cfgfile_name,
-					strerror(errno), __progname);
+				fprintf(stderr, "%s: %s: %s\n", __progname,
+					cfgfile_name, strerror(errno));
 				return (2);
 			}
 			break;
+		case 'h':
+			_cfg_print_usage();
+			_cfg_print_usagehelp();
+			return (0);
 		default:
 			_cfg_print_usage();
 			return (2);
 		}
 	}
-	argc -= optind;
-	argv += optind;
+	*argc -= optind;
+	*argv += optind;
 
 	if (cfgfile == NULL && (home = getenv("HOME")) != NULL) {
-		snprintf(cfgfile_name, sizeof(cfgfile_name), "%s/%s", home, DEFAULT_CONFIG_FILE);
-		cfgfile = fopen(cfgfile_name, "r");
+#ifdef S_IROTH
+		struct stat	st;
+#endif /* S_IROTH */
+
+		snprintf(cfgfile_name, sizeof(cfgfile_name), "%s/%s", home, CONFIG_FILENAME_HOME);
+#ifdef S_IROTH
+		if (stat(cfgfile_name, &st) != -1 && (st.st_mode & S_IROTH)) {
+			fprintf(stderr, "WARNING: %s is world-readable!\n",
+				cfgfile_name);
+		}
+#endif /* S_IROTH */
+		if ((cfgfile = fopen(cfgfile_name, "r")) == NULL && errno != ENOENT)
+			fprintf(stderr, "%s: %s: %s\n", __progname,
+				cfgfile_name, strerror(errno));
 	}
+	if (cfgfile == NULL) {
+#ifdef S_IROTH
+		struct stat	st;
+#endif /* S_IROTH */
 
+		snprintf(cfgfile_name, sizeof(cfgfile_name), "%s/%s", SYSCONF_DIR, CONFIG_FILENAME);
+#ifdef S_IROTH
+		if (stat(cfgfile_name, &st) != -1 && (st.st_mode & S_IROTH)) {
+			fprintf(stderr, "WARNING: %s is world-readable!\n",
+				cfgfile_name);
+		}
+#endif /* S_IROTH */
+		if ((cfgfile = fopen(cfgfile_name, "r")) == NULL && errno != ENOENT)
+			fprintf(stderr, "%s: %s: %s\n", __progname,
+				cfgfile_name, strerror(errno));
+	}
+
 	if (_cfg_parse_cfgfile(cfgfile, cfgfile_name) != 0) {
 		fclose(cfgfile);
 		return (1);
@@ -141,6 +192,51 @@
 	_cfg_print_usagehelp();
 }
 
+struct server_pref *
+cfg_get_server_pref(const char *token)
+{
+	struct server_pref	*srvp, find;
+
+	if (token == NULL || token[0] == '\0')
+		return (NULL);
+
+	find.token = xstrdup(token);
+	srvp = RB_FIND(server_pref_tree, &server_pref_tree_head, &find);
+	xfree(find.token);
+
+	return (srvp);
+}
+
+const char *
+cfg_sp_hostname(struct server_pref *srvp)
+{
+	return ((const char *)srvp->hostname);
+}
+
+const char *
+cfg_sp_service(struct server_pref *srvp)
+{
+	return ((const char *)srvp->service);
+}
+
+const char *
+cfg_sp_username(struct server_pref *srvp)
+{
+	return ((const char *)srvp->username);
+}
+
+const char *
+cfg_sp_password(struct server_pref *srvp)
+{
+	return ((const char *)srvp->password);
+}
+
+const char *
+cfg_sp_default_mount(struct server_pref *srvp)
+{
+	return ((const char *)srvp->default_mount);
+}
+
 int
 _cfg_serverpref_cmp(void *arg_a, void *arg_b)
 {
@@ -511,7 +607,7 @@
 
 	/* Skip closing quote. */
 	bp++;
-	/* Whitespaces and comments behind the value are ok, the rest not. */
+	/* Whitespaces and comments behind the value are ok, the rest isn't. */
 	while (*bp != '\0' && (*bp == ' ' || *bp == '\t'))
 		bp++;
 	if (*bp != '\0' && *bp != '#')  {

Modified: experimental/moritz/iceadmin/src/cfg.h
===================================================================
--- experimental/moritz/iceadmin/src/cfg.h	2007-08-29 16:43:30 UTC (rev 13654)
+++ experimental/moritz/iceadmin/src/cfg.h	2007-08-29 16:45:20 UTC (rev 13655)
@@ -1,7 +1,15 @@
 #ifndef __CFG_H__
 #define __CFG_H__
 
-#define DEFAULT_CONFIG_FILE	".iceadminrc"
+#ifndef SYSCONF_DIR
+# define SYSCONF_DIR		"/etc"
+#endif
+#ifndef CONFIG_FILENAME
+# define CONFIG_FILENAME 	"iceadmin.conf"
+#endif
+#ifndef CONFIG_FILENAME_HOME
+# define CONFIG_FILENAME_HOME	".iceadminrc"
+#endif
 
 #define CFG_KEY_HOSTNAME	"hostname"
 #define CFG_KEY_SERVICE 	"service"
@@ -22,10 +30,19 @@
 # define BUFSIZ 		1024
 #endif /* !BUFSIZ */
 
-void	cfg_initialize(void);
-void	cfg_shutdown(void);
+typedef struct server_pref *server_pref_t;
 
-int	cfg_parse_cmdline(int, char *[]);
-void	cfg_print_help(void);
+void		cfg_initialize(void);
+void		cfg_shutdown(void);
 
+int		cfg_parse_cmdopts(int *, char **[]);
+void		cfg_print_help(void);
+
+server_pref_t	cfg_get_server_pref(const char *);
+const char *	cfg_sp_hostname(server_pref_t);
+const char *	cfg_sp_service(server_pref_t);
+const char *	cfg_sp_username(server_pref_t);
+const char *	cfg_sp_password(server_pref_t);
+const char *	cfg_sp_default_mount(server_pref_t);
+
 #endif /* __CFG_H__ */

Modified: experimental/moritz/iceadmin/src/iceadmin.c
===================================================================
--- experimental/moritz/iceadmin/src/iceadmin.c	2007-08-29 16:43:30 UTC (rev 13654)
+++ experimental/moritz/iceadmin/src/iceadmin.c	2007-08-29 16:45:20 UTC (rev 13655)
@@ -66,13 +66,19 @@
 	char		*buf;
 	size_t		 bufsize;
 	int		 ret;
+	extern int	 optind;
+	int		 i;
 
 	__progname = get_progname(argv[0]);
 
 	init_self();
 
-	if ((ret = cfg_parse_cmdline(argc, argv)) != CONFIG_OKAY)
+	if ((ret = cfg_parse_cmdopts(&argc, &argv)) != CONFIG_OKAY)
 		return (shutdown_self(ret));
 
+	for (i = 0; i < argc; i++)
+		printf("%s ", argv[i]);
+	printf("\n");
+
 	return (shutdown_self(0));
 }



More information about the commits mailing list