/*
* This file is part of DisOrder.
- * Copyright (C) 2004-2012 Richard Kettlewell
+ * Copyright (C) 2004-2013 Richard Kettlewell
*
* 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
#include <getopt.h>
#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+#if HAVE_SYS_UN_H
+# include <sys/un.h>
+#endif
#include <errno.h>
#include <locale.h>
#include <time.h>
#include <stddef.h>
-#include <unistd.h>
-#include <pcre.h>
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#if HAVE_PCRE_H
+# include <pcre.h>
+#endif
#include <ctype.h>
-#include <gcrypt.h>
-#include <langinfo.h>
+#if HAVE_GCRYPT_H
+# include <gcrypt.h>
+#endif
+#if HAVE_LANGINFO_H
+# include <langinfo.h>
+#endif
#include "configuration.h"
#include "syscalls.h"
const char *user = 0, *password = 0;
mem_init();
+#if HAVE_PCRE_H
/* garbage-collect PCRE's memory */
pcre_malloc = xmalloc;
pcre_free = xfree;
+#endif
if(!setlocale(LC_CTYPE, "")) disorder_fatal(errno, "error calling setlocale");
if(!setlocale(LC_TIME, "")) disorder_fatal(errno, "error calling setlocale");
while((n = getopt_long(argc, argv, "+hVc:dHlNu:p:", options, 0)) >= 0) {
config->connect.af = -1;
n = optind;
optind = 1; /* for subsequent getopt calls */
+#if HAVE_GCRYPT_H
/* gcrypt initialization */
if(!gcry_check_version(NULL))
disorder_fatal(0, "gcry_check_version failed");
gcry_control(GCRYCTL_INIT_SECMEM, 0);
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
+#endif
/* accumulate command args */
while(n < argc) {
if((i = TABLE_FIND(commands, name, argv[n])) < 0)
if test $want_coreaudio = yes; then
AC_CHECK_HEADERS([CoreAudio/AudioHardware.h])
fi
-AC_CHECK_HEADERS([inttypes.h])
+AC_CHECK_HEADERS([inttypes.h sys/time.h sys/socket.h netinet/in.h \
+ arpa/inet.h sys/un.h netdb.h pcre.h pwd.h langinfo.h])
# We don't bother checking very standard stuff
# Compilation will fail if any of these headers are missing, so we
# check for them here and fail early.
/*
* This file is part of DisOrder.
- * Copyright (C) 2004, 2007, 2008 Richard Kettlewell
+ * Copyright (C) 2004, 2007, 2008, 2013 Richard Kettlewell
*
* 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
#include "common.h"
#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/un.h>
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+#if HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+#if HAVE_ARPA_INET_H
+# include <arpa/inet.h>
+#endif
+#if HAVE_SYS_UN_H
+# include <sys/un.h>
+#endif
#include "log.h"
#include "printf.h"
return r;
}
+#if HAVE_SYS_UN_H
/** @brief Format a UNIX socket address */
static inline char *format_sockaddrun(const struct sockaddr_un *sun) {
return xstrdup(sun->sun_path);
}
+#endif
/** @brief Construct a text description a sockaddr
* @param sa Socket address
return format_sockaddr4((const struct sockaddr_in *)sa);
case AF_INET6:
return format_sockaddr6((const struct sockaddr_in6 *)sa);
+#if HAVE_SYS_UN_H
case AF_UNIX:
return format_sockaddrun((const struct sockaddr_un *)sa);
+#endif
default:
return 0;
}
/*
* This file is part of DisOrder.
- * Copyright (C) 2004, 2007, 2008 Richard Kettlewell
+ * Copyright (C) 2004, 2007, 2008, 2013 Richard Kettlewell
*
* 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
#ifndef ADDR_H
#define ADDR_H
-#include <netdb.h>
+#if HAVE_NETDB_H
+# include <netdb.h>
+#endif
struct stringlist;
/*
* This file is part of DisOrder
- * Copyright (C) 2004, 2006, 2007, 2009 Richard Kettlewell
+ * Copyright (C) 2004, 2006, 2007, 2009, 2013 Richard Kettlewell
*
* 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
#include "common.h"
#include <stddef.h>
-#include <gcrypt.h>
+#if HAVE_GCRYPT_H
+# include <gcrypt.h>
+#else
+# error No crypto API available
+#endif
#include "hex.h"
#include "log.h"
/** @brief DisOrder algorithm name */
const char *name;
+#if HAVE_GCRYPT_H
/** @brief gcrypt algorithm ID */
int id;
+#endif
+
};
/** @brief Algorithm lookup table
* the disorder protocol.
*/
static const struct algorithm algorithms[] = {
+#if HAVE_GCRYPT_H
{ "SHA1", GCRY_MD_SHA1 },
{ "sha1", GCRY_MD_SHA1 },
{ "SHA256", GCRY_MD_SHA256 },
{ "sha384", GCRY_MD_SHA384 },
{ "SHA512", GCRY_MD_SHA512 },
{ "sha512", GCRY_MD_SHA512 },
+#endif
};
/** @brief Number of supported algorithms */
*/
char *authhash(const void *challenge, size_t nchallenge,
const char *password, const char *algo) {
+#if HAVE_GCRYPT_H
gcrypt_hash_handle h;
+ int id;
+#endif
char *res;
size_t n;
- int id;
assert(challenge != 0);
assert(password != 0);
break;
if(n >= NALGORITHMS)
return NULL;
+#if HAVE_GCRYPT_H
id = algorithms[n].id;
#if HAVE_GCRY_ERROR_T
{
gcry_md_write(h, challenge, nchallenge);
res = hex(gcry_md_read(h, id), gcry_md_get_algo_dlen(id));
gcry_md_close(h);
+#endif
return res;
}
/*
* This file is part of DisOrder
- * Copyright (C) 2009 Richard Kettlewell
+ * Copyright (C) 2009, 2013 Richard Kettlewell
*
* 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
#ifndef BYTE_ORDER_H
#define BYTE_ORDER_H
-#include <config.h>
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
#define ENDIAN_BIG 1
#define ENDIAN_LITTLE 2
/*
* This file is part of DisOrder.
- * Copyright (C) 2004, 2005, 2007, 2008 Richard Kettlewell
+ * Copyright (C) 2004, 2005, 2007, 2008, 2013 Richard Kettlewell
*
* 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
#include "common.h"
-#include <iconv.h>
+#if HAVE_ICONV_H
+# include <iconv.h>
+#endif
#include <errno.h>
-#include <langinfo.h>
+#if HAVE_LANGINFO_H
+# include <langinfo.h>
+#endif
#include "mem.h"
#include "log.h"
/*
* This file is part of DisOrder
- * Copyright (C) 2004, 2005, 2006, 2007, 2009 Richard Kettlewell
+ * Copyright (C) 2004-7, 2009, 2011-13 Richard Kettlewell
*
* 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
#include "common.h"
-#include <netinet/in.h>
-#include <sys/un.h>
+#if HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+#if HAVE_SYS_UN_H
+# include <sys/un.h>
+#endif
#include <errno.h>
-#include <netdb.h>
-#include <unistd.h>
+#if HAVE_NETDB_H
+# include <netdb.h>
+#endif
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
#include "log.h"
#include "configuration.h"
/*
* This file is part of DisOrder
- * Copyright (C) 2004-2007 Richard Kettlewell
+ * Copyright (C) 2004-8, 2011, 2013 Richard Kettlewell
*
* 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
#define CLIENT_COMMON_H
#include <sys/types.h>
-#include <sys/socket.h>
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
socklen_t find_server(struct config *c, struct sockaddr **sap, char **namep);
/*
* This file is part of DisOrder.
- * Copyright (C) 2004-2010 Richard Kettlewell
+ * Copyright (C) 2004-13 Richard Kettlewell
*
* 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
#include "common.h"
#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <sys/un.h>
-#include <unistd.h>
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+#if HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+#if HAVE_SYS_UN_H
+# include <sys/un.h>
+#endif
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
#include <errno.h>
-#include <netdb.h>
-#include <pcre.h>
+#if HAVE_NETDB_H
+# include <netdb.h>
+#endif
+#if HAVE_PCRE_H
+# include <pcre.h>
+#endif
#include "log.h"
#include "mem.h"
/*
* This file is part of DisOrder.
- * Copyright (C) 2004, 2005, 2007, 2008 Richard Kettlewell
+ * Copyright (C) 2004, 2005, 2007, 2008, 2013 Richard Kettlewell
*
* 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
#ifndef COMMON_H
#define COMMON_H
-#include <config.h>
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
#if HAVE_INTTYPES_H
# include <inttypes.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <unistd.h>
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
#include <ctype.h>
#include <stddef.h>
-#include <pwd.h>
-#include <langinfo.h>
-#include <pcre.h>
+#if HAVE_PWD_H
+# include <pwd.h>
+#endif
+#if HAVE_LANGINFO_H
+# include <langinfo.h>
+#endif
+#if HAVE_PCRE_H
+# include <pcre.h>
+#endif
#include <signal.h>
#include "rights.h"
#include "charset.h"
#include "defs.h"
#include "printf.h"
-#include "regsub.h"
+#if HAVE_PCRE_H
+# include "regsub.h"
+#endif
#include "signame.h"
#include "authhash.h"
#include "vector.h"
/* Defaults */
if(!module)
module = "fs";
+#if HAVE_LANGINFO_H
if(!encoding)
encoding = nl_langinfo(CODESET);
+#else
+ if(!encoding)
+ encoding = "ascii";
+#endif
cl = ADDRESS(cs->config, struct collectionlist);
++cl->n;
cl->s = xrealloc(cl->s, cl->n * sizeof (struct collection));
nvec, vec);
}
+#if HAVE_PCRE_H
static int set_namepart(const struct config_state *cs,
const struct conf *whoami,
int nvec, char **vec) {
++tl->n;
return 0;
}
+#endif
static int set_rights(const struct config_state *cs,
const struct conf *whoami,
xfree(cll->s);
}
+#if HAVE_PCRE_H
static void free_namepartlist(struct config *c,
const struct conf *whoami) {
struct namepartlist *npl = ADDRESS(c, struct namepartlist);
}
xfree(tl->t);
}
+#endif
static void free_netaddress(struct config *c,
const struct conf *whoami) {
{ C(mount_rescan), &type_boolean, validate_any },
{ C(multicast_loop), &type_boolean, validate_any },
{ C(multicast_ttl), &type_integer, validate_non_negative },
+#if HAVE_PCRE_H
{ C(namepart), &type_namepart, validate_any },
+#endif
{ C(new_bias), &type_integer, validate_positive },
{ C(new_bias_age), &type_integer, validate_positive },
{ C(new_max), &type_integer, validate_positive },
{ C(stopword), &type_string_accum, validate_any },
{ C(templates), &type_string_accum, validate_isdir },
{ C(tracklength), &type_stringlist_accum, validate_tracklength },
+#if HAVE_PCRE_H
{ C(transform), &type_transform, validate_any },
+#endif
{ C(url), &type_string, validate_url },
{ C(user), &type_string, validate_isauser },
{ C(username), &type_string, validate_any },
static void config_postdefaults(struct config *c,
int server) {
struct config_state cs;
+#if HAVE_PCRE_H
const struct conf *whoami;
int n;
+#endif
+#if HAVE_PCRE_H
static const char *namepart[][4] = {
{ "title", "/([0-9]+ *[-:]? *)?([^/]+)\\.[a-zA-Z0-9]+$", "$2", "display" },
{ "title", "/([^/]+)\\.[a-zA-Z0-9]+$", "$1", "sort" },
{ "dir", "[[:punct:]]", "", "sort", "g", }
};
#define NTRANSFORM (int)(sizeof transform / sizeof *transform)
+#endif
cs.path = "<internal>";
cs.line = 0;
cs.config = c;
+#if HAVE_PCRE_H
if(!c->namepart.n) {
whoami = find("namepart");
for(n = 0; n < NNAMEPART; ++n)
for(n = 0; n < NTRANSFORM; ++n)
set_transform(&cs, whoami, 5, (char **)transform[n]);
}
+#endif
if(!c->api) {
if(c->speaker_command)
c->api = xstrdup("command");
disorder_error(0, "'nice_server' cannot be changed without a restart");
/* ...but we accept the new config anyway */
}
+#if HAVE_PCRE_H
if(namepartlist_compare(&c->namepart, &oldconfig->namepart)) {
disorder_error(0, "'namepart' settings cannot be changed without a restart");
failed = 1;
}
+#endif
if(stringlist_compare(&c->stopword, &oldconfig->stopword)) {
disorder_error(0, "'stopword' settings cannot be changed without a restart");
failed = 1;
return 0;
}
+#if HAVE_PCRE_H
/** @brief Order two namepart definitions
* @param a First namepart definition
* @param b Second namepart definition
else
return 0;
}
+#endif
/** @brief Verify configuration table.
* @return The number of problems found
/*
* This file is part of DisOrder.
- * Copyright (C) 2004-2010 Richard Kettlewell
+ * Copyright (C) 2004-2011, 2013 Richard Kettlewell
*
* 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
#ifndef CONFIGURATION_H
#define CONFIGURATION_H
-#include <pcre.h>
+#if HAVE_PCRE_H
+# include <pcre.h>
+#endif
#include "speaker-protocol.h"
#include "rights.h"
struct collection *s;
};
+#if HAVE_PCRE_H
/** @brief A track name part */
struct namepart {
char *part; /* part */
int n;
struct transform *t;
};
+#endif
/** @brief System configuration */
struct config {
/** @brief Minimum time between a track being played again */
long replay_min;
+#if HAVE_PCRE_H
struct namepartlist namepart; /* transformations */
+#endif
/** @brief Termination signal for subprocesses */
int signal;
/** @brief ALSA output device */
const char *device;
+
+#if HAVE_PCRE_H
struct transformlist transform; /* path name transformations */
+#endif
/** @brief Address to send audio data to */
struct netaddress broadcast;
/*
* This file is part of DisOrder.
- * Copyright (C) 2004-2008 Richard Kettlewell
+ * Copyright (C) 2004-9, 2013 Richard Kettlewell
*
* 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
#include "common.h"
#include <errno.h>
-#include <syslog.h>
-#include <sys/time.h>
+#include <sys/types.h>
+#if HAVE_SYSLOG_H
+# include <syslog.h>
+#endif
+#if HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+#if HAVE_NETDB_H
+# include <netdb.h>
+#endif
#include <time.h>
#include "log.h"
fputc('\n', fp);
}
+#if HAVE_SYSLOG_H
/** @brief Log to syslog */
static void logsyslog(int pri, const char *msg,
void attribute((unused)) *user) {
else
syslog(pri, "%s:%d: %s", debug_filename, debug_lineno, msg);
}
+#endif
/** @brief Log output that writes to @c stderr */
struct log_output log_stderr = { logfp, 0 };
+#if HAVE_SYSLOG_H
/** @brief Log output that sends to syslog */
struct log_output log_syslog = { logsyslog, 0 };
+#endif
/** @brief Format and log a message */
static void vlogger(int pri, const char *fmt, va_list ap) {
/*
* This file is part of DisOrder.
- * Copyright (C) 2004, 2005, 2007, 2008 Richard Kettlewell
+ * Copyright (C) 2004, 2005, 2007-9, 2013 Richard Kettlewell
*
* 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
extern const char *progname;
/* program name */
-extern struct log_output log_stderr, log_syslog, *log_default;
+extern struct log_output log_stderr, *log_default;
+#if HAVE_SYSLOG_H
+extern struct log_output log_syslog;
+#endif
/* some typical outputs */
extern const char *debug_filename;
#define SPEAKER_PROTOCOL_H
#include "byte-order.h"
-#include <netinet/in.h>
+#if HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
/** @brief A message from the main server to the speaker, or vica versa */
struct speaker_message {
/* strptime.c - partial strptime() reimplementation
*
- * Copyright (c) 2008, 2011 Richard Kettlewell.
+ * Copyright (c) 2008, 2011, 2013 Richard Kettlewell.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* some missing bits.
*/
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <ctype.h>
#include <limits.h>
#include <string.h>
-#include <langinfo.h>
+#if HAVE_LANGINFO_H
+# include <langinfo.h>
+#endif
#include "strptime.h"
+#if !HAVE_LANGINFO_H
+/* Fake plastic langinfo. Primarily for Windows.
+ * TODO WIN32 can we get these values out of the win32 api instead? */
+typedef enum {
+ DAY_1,
+ DAY_2,
+ DAY_3,
+ DAY_4,
+ DAY_5,
+ DAY_6,
+ DAY_7,
+ ABDAY_1,
+ ABDAY_2,
+ ABDAY_3,
+ ABDAY_4,
+ ABDAY_5,
+ ABDAY_6,
+ ABDAY_7,
+ MON_1,
+ MON_2,
+ MON_3,
+ MON_4,
+ MON_5,
+ MON_6,
+ MON_7,
+ MON_8,
+ MON_9,
+ MON_10,
+ MON_11,
+ MON_12,
+ ABMON_1,
+ ABMON_2,
+ ABMON_3,
+ ABMON_4,
+ ABMON_5,
+ ABMON_6,
+ ABMON_7,
+ ABMON_8,
+ ABMON_9,
+ ABMON_10,
+ ABMON_11,
+ ABMON_12,
+ D_FMT,
+ T_FMT,
+ D_T_FMT,
+ ERA_D_FMT,
+ ERA_T_FMT,
+ ERA_D_T_FMT,
+} nl_item;
+
+const char *nl_langinfo(nl_item item) {
+ switch(item) {
+ case DAY_1: return "Sunday";
+ case DAY_2: return "Monday";
+ case DAY_3: return "Tuesday";
+ case DAY_4: return "Wednesday";
+ case DAY_5: return "Thursday";
+ case DAY_6: return "Friday";
+ case DAY_7: return "Saturday";
+ case ABDAY_1: return "Sun";
+ case ABDAY_2: return "Mon";
+ case ABDAY_3: return "Tue";
+ case ABDAY_4: return "Wed";
+ case ABDAY_5: return "Thu";
+ case ABDAY_6: return "Fri";
+ case ABDAY_7: return "Sat";
+ case MON_1: return "January";
+ case MON_2: return "February";
+ case MON_3: return "March";
+ case MON_4: return "April";
+ case MON_5: return "May";
+ case MON_6: return "June";
+ case MON_7: return "July";
+ case MON_8: return "August";
+ case MON_9: return "September";
+ case MON_10: return "October";
+ case MON_11: return "November";
+ case MON_12: return "December";
+ case ABMON_1: return "Jan";
+ case ABMON_2: return "Feb";
+ case ABMON_3: return "Mar";
+ case ABMON_4: return "Apr";
+ case ABMON_5: return "May";
+ case ABMON_6: return "Jun";
+ case ABMON_7: return "Jul";
+ case ABMON_8: return "Aug";
+ case ABMON_9: return "Sep";
+ case ABMON_10: return "Oct";
+ case ABMON_11: return "Nov";
+ case ABMON_12: return "Dec";
+ case D_FMT: return "%d/%m/%y";
+ case T_FMT: return "%H:%M:%S";
+ case D_T_FMT: return "%a %d %b %Y %H:%M:%S %Z";
+ case ERA_D_FMT: return "";
+ case ERA_T_FMT: return "";
+ case ERA_D_T_FMT: return "";
+ default: return 0;
+ }
+}
+#endif
+
/** @brief Lookup table entry for locale-specific strings */
struct locale_item_match {
/** @brief Locale key to try */
/*
* This file is part of DisOrder.
- * Copyright (C) 2004, 2005, 2007, 2008, 2013 Richard Kettlewell
+ * Copyright (C) 2004, 2005, 2007-9, 2013 Richard Kettlewell
*
* 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
*/
#include "common.h"
-#include <unistd.h>
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+#if HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
#include <signal.h>
#include <time.h>
struct sigaction;
struct timezone;
-#include <sys/socket.h>
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
#include <signal.h>
pid_t xfork(void);