diff --git a/configure.ac b/configure.ac index 3bee4d6..e2271b1 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ([2.69]) AC_INIT([pianod], - 174.08-sc, + 174.09-sc, [pianod@lists.deviousfish.com], ,[http://deviousfish.com/pianod]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) @@ -108,15 +108,6 @@ AM_CONDITIONAL([ENABLE_SHOUT],[test "x$HAS_SHOUT" = "x1"]) AC_SEARCH_LIBS([crypt],[crypt], [], [AC_MSG_ERROR([Cannot find required library: crypt (DES password encryption).])]) -# Fgetln for Football: -# May be in standard libraries, in -lbsd on Linux, or not exist at all. -AC_SEARCH_LIBS([fgetln],[bsd], - [AC_DEFINE([HAVE_FGETLN],[1],[Set to 1 if fgetln is available])]) -AC_SEARCH_LIBS([getprogname],[bsd], - [AC_DEFINE([HAVE_GETPROGNAME],[1],[Set to 1 if getprogname/setprogname is available])]) - -AM_CONDITIONAL([HAVE_FGETLN],[test "$ac_cv_search_fgetln" = 'none required']) - # IPv6 support AC_MSG_CHECKING([PF_INET6/IPv6 support]) AC_TRY_COMPILE([#include ], diff --git a/pianod-sc.cbp b/pianod-sc.cbp index a327852..54b9371 100644 --- a/pianod-sc.cbp +++ b/pianod-sc.cbp @@ -96,10 +96,6 @@ - - - diff --git a/src/command.c b/src/command.c index 394c8b2..b52bea3 100644 --- a/src/command.c +++ b/src/command.c @@ -11,7 +11,7 @@ #ifndef __FreeBSD__ #define _POSIX_C_SOURCE 1 /* fileno() */ -#define _BSD_SOURCE /* strdup() */ +#define _DEFAULT_SOURCE /* strdup() */ #define _DARWIN_C_SOURCE /* strdup() on OS X */ #endif diff --git a/src/libfootball/Makefile.am b/src/libfootball/Makefile.am index 6fed78b..66fc0c7 100644 --- a/src/libfootball/Makefile.am +++ b/src/libfootball/Makefile.am @@ -1,11 +1,5 @@ ## Process this file with automake to produce Makefile.in -if HAVE_FGETLN -fgetln_files = -else -fgetln_files = fgetln.c fgetln.h -endif - if ENABLE_DEBUG libfootball_a_CFLAGS = -g endif @@ -15,6 +9,5 @@ noinst_LIBRARIES = libfootball.a libfootball_a_CPPFLAGS = -Iinclude -I../.. -D_GNU_SOURCE libfootball_a_SOURCES = fb_event.c fb_parser.c fb_service.c fb_socketmgr.c \ fb_http.c fb_message.c fb_utility.c sha1.c \ - fb_public.h fb_service.h sha1.h \ - $(fgetln_files) + fb_public.h fb_service.h sha1.h diff --git a/src/libfootball/fb_event.c b/src/libfootball/fb_event.c index ae438a3..67dae61 100644 --- a/src/libfootball/fb_event.c +++ b/src/libfootball/fb_event.c @@ -10,7 +10,7 @@ #include #ifndef __FreeBSD__ -#define _BSD_SOURCE /* snprintf() */ +#define _DEFAULT_SOURCE /* snprintf() */ #endif #if !defined(__FreeBSD__) && !defined(__APPLE__) #define _POSIX_C_SOURCE 1 /* required by getaddrinfo() */ @@ -31,10 +31,6 @@ #include "fb_service.h" -#ifndef HAVE_FGETLN -#include "fgetln.h" -#endif - #ifndef HAVE_MSG_NOSIGNAL #define MSG_NOSIGNAL (0) #ifndef HAVE_SO_NOSIGPIPE @@ -369,7 +365,7 @@ static char *fb_get_line_bytes (FB_CONNECTION *connection, size_t *length) { assert (connection->in.size <= connection->in.capacity); if (connection->in.size == connection->in.capacity) { if (!fb_set_input_buffer_size (connection, connection->in.capacity * 2 + 64)) { - return false; + return NULL; } } ok = fb_recv_input (connection, 1); @@ -390,45 +386,55 @@ static char *fb_get_line_bytes (FB_CONNECTION *connection, size_t *length) { @param connection the connection from which input is read @return An FB_EVENT_INPUT event, or input is incomplete. */ +/* Global buffer for getline() */ +static char *buffer = NULL; +static size_t bufsize = 0; + FB_EVENT *fb_read_line_input (FB_EVENT *event, FB_CONNECTION *connection) { assert (connection); assert (event); char *line; - char *buffer = NULL; - size_t buffilled = 0; + size_t lbufsize; + char *evbuffer; /* If we got here, socket_data will be for a connection */ event->type = FB_EVENT_INPUT; if (connection->file) { /* Reading from file connection */ - line = fgetln (connection->file, &buffilled); - if (!line || buffilled == 0) { + lbufsize = getline(&buffer, &bufsize, connection->file); + if ((lbufsize == -1) || (buffer == NULL)) { /* EOF/Connection closed from other end. Initiate closure. */ + if (buffer) { + free(buffer); + buffer = NULL; + } fb_close_connection (connection); return NULL; } + line = buffer; } else { - line = fb_get_line_bytes (connection, &buffilled); + line = fb_get_line_bytes (connection, &lbufsize); if (!line) { /* Haven't got a full line yet, or error. */ return NULL; } } - /* Make a copy of the line */ - buffer = malloc (buffilled + 1); - if (!buffer) { - fb_perror ("malloc"); + /* Make a copy of the line for event queue */ + evbuffer = malloc (lbufsize + 1); + if (!evbuffer) { + fb_perror ("malloc"); return NULL; } - memcpy (buffer, line, buffilled); + memcpy (evbuffer, line, lbufsize); /* strip returns off the end of the unparsed line */ - while (buffilled > 0 && (buffer [buffilled - 1] == '\r' || buffer [buffilled - 1] == '\n')) { - buffilled--; + while (lbufsize > 0 && (evbuffer [lbufsize - 1] == '\r' || evbuffer [lbufsize - 1] == '\n')) { + lbufsize--; } - buffer [buffilled] = '\0'; + /* NULL termination always */ + evbuffer [lbufsize] = '\0'; /* Store the command and parse it into an argv array */ - event->command = buffer; + event->command = evbuffer; event->argc = fb_create_argv(event->command, &event->argv, &event->argr); if (event->argc < 0) { event->argc = 0; diff --git a/src/libfootball/fb_http.c b/src/libfootball/fb_http.c index 7ae450f..9e6f219 100644 --- a/src/libfootball/fb_http.c +++ b/src/libfootball/fb_http.c @@ -20,7 +20,7 @@ Sec-WebSocket-Version: 13 #ifndef __FreeBSD__ #define _POSIX_C_SOURCE 1 /* fileno() */ -#define _BSD_SOURCE /* strdup() */ +#define _DEFAULT_SOURCE /* strdup() */ #define _DARWIN_C_SOURCE /* strdup() on OS X */ #endif #ifdef __linux__ diff --git a/src/libfootball/fb_parser.c b/src/libfootball/fb_parser.c index a8fa2d5..7435529 100644 --- a/src/libfootball/fb_parser.c +++ b/src/libfootball/fb_parser.c @@ -62,7 +62,7 @@ #include #ifndef __FreeBSD__ -#define _BSD_SOURCE /* snprintf() */ +#define _DEFAULT_SOURCE /* snprintf() */ #endif #include diff --git a/src/libfootball/fb_service.c b/src/libfootball/fb_service.c index 9bcd4a0..2b450da 100644 --- a/src/libfootball/fb_service.c +++ b/src/libfootball/fb_service.c @@ -12,7 +12,7 @@ #define _POSIX_C_SOURCE 1 /* fileno,fdopen() */ #endif #ifndef __FreeBSD__ -#define _BSD_SOURCE /* strdup */ +#define _DEFAULT_SOURCE /* strdup */ #endif #include diff --git a/src/libfootball/fb_socketmgr.c b/src/libfootball/fb_socketmgr.c index 79970be..f081d82 100644 --- a/src/libfootball/fb_socketmgr.c +++ b/src/libfootball/fb_socketmgr.c @@ -10,7 +10,7 @@ #ifndef __FreeBSD__ #define _POSIX_C_SOURCE 1 /* fileno() */ -#define _BSD_SOURCE /* strdup() */ +#define _DEFAULT_SOURCE /* strdup() */ #define _DARWIN_C_SOURCE /* strdup() on OS X */ #endif #ifdef __linux__ diff --git a/src/libfootball/fgetln.c b/src/libfootball/fgetln.c deleted file mode 100644 index 8c1db98..0000000 --- a/src/libfootball/fgetln.c +++ /dev/null @@ -1,82 +0,0 @@ -/* $NetBSD: fgetln.c,v 1.3 2006/09/25 07:18:17 lukem Exp $ */ -/* With modifications (adding #includes) to make this compile with pianod. */ - -/*- - * Copyright (c) 1998 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Christos Zoulas. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include "fgetln.h" - -char * -fgetln(FILE *fp, size_t *len) -{ - static char *buf = NULL; - static size_t bufsiz = 0; - char *ptr; - - - if (buf == NULL) { - bufsiz = BUFSIZ; - if ((buf = malloc(bufsiz)) == NULL) - return NULL; - } - - if (fgets(buf, bufsiz, fp) == NULL) - return NULL; - - *len = 0; - while ((ptr = strchr(&buf[*len], '\n')) == NULL) { - size_t nbufsiz = bufsiz + BUFSIZ; - char *nbuf = realloc(buf, nbufsiz); - - if (nbuf == NULL) { - int oerrno = errno; - free(buf); - errno = oerrno; - buf = NULL; - return NULL; - } else - buf = nbuf; - - *len = bufsiz; - if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL) - return buf; - - bufsiz = nbufsiz; - } - - *len = (ptr - buf) + 1; - return buf; -} diff --git a/src/libfootball/fgetln.h b/src/libfootball/fgetln.h deleted file mode 100644 index 8461f60..0000000 --- a/src/libfootball/fgetln.h +++ /dev/null @@ -1,37 +0,0 @@ -/* $NetBSD: fgetln.c,v 1.3 2006/09/25 07:18:17 lukem Exp $ */ - -/*- - * Copyright (c) 1998 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Christos Zoulas. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -extern char *fgetln(FILE *fp, size_t *len); - diff --git a/src/libpiano/Makefile.am b/src/libpiano/Makefile.am index 407f415..da927ea 100644 --- a/src/libpiano/Makefile.am +++ b/src/libpiano/Makefile.am @@ -21,7 +21,7 @@ if HAVE_JSON_H have_json_h = -DHAVE_JSON_H=1 endif -libpiano_a_CPPFLAGS = $(json_CFLAGS) -I../include -DGCRYPT_NO_DEPRECATED $(request_assert) $(have_json_json_h) $(have_json_c_json_h) $(have_json_h) +libpiano_a_CPPFLAGS = $(json_CFLAGS) -D_GNU_SOURCE -I../include -DGCRYPT_NO_DEPRECATED $(request_assert) $(have_json_json_h) $(have_json_c_json_h) $(have_json_h) libpiano_a_SOURCES = crypt.c piano.c request.c response.c list.c \ config.h piano.h crypt.h piano_private.h diff --git a/src/libpiano/piano.c b/src/libpiano/piano.c index 61438f4..08147c9 100644 --- a/src/libpiano/piano.c +++ b/src/libpiano/piano.c @@ -22,7 +22,7 @@ THE SOFTWARE. */ #ifndef __FreeBSD__ -#define _BSD_SOURCE /* required by strdup() */ +#define _DEFAULT_SOURCE /* required by strdup() */ #define _DARWIN_C_SOURCE /* strdup() on OS X */ #endif diff --git a/src/libpiano/request.c b/src/libpiano/request.c index c8f75df..c7dafb2 100644 --- a/src/libpiano/request.c +++ b/src/libpiano/request.c @@ -22,7 +22,7 @@ THE SOFTWARE. */ #ifndef __FreeBSD__ -#define _BSD_SOURCE /* required by strdup() */ +#define _DEFAULT_SOURCE /* required by strdup() */ #define _DARWIN_C_SOURCE /* strdup() on OS X */ #endif diff --git a/src/libpiano/response.c b/src/libpiano/response.c index 60681c5..ae9f6d0 100644 --- a/src/libpiano/response.c +++ b/src/libpiano/response.c @@ -22,7 +22,7 @@ THE SOFTWARE. */ #ifndef __FreeBSD__ -#define _BSD_SOURCE /* required by strdup() */ +#define _DEFAULT_SOURCE /* required by strdup() */ #define _DARWIN_C_SOURCE /* strdup() on OS X */ #endif diff --git a/src/libwaitress/waitress.c b/src/libwaitress/waitress.c index 63ae055..5165f3d 100644 --- a/src/libwaitress/waitress.c +++ b/src/libwaitress/waitress.c @@ -23,7 +23,7 @@ THE SOFTWARE. #ifndef __FreeBSD__ #define _POSIX_C_SOURCE 1 /* required by getaddrinfo() */ -#define _BSD_SOURCE /* snprintf() */ +#define _DEFAULT_SOURCE /* snprintf() */ #define _DARWIN_C_SOURCE /* snprintf() on OS X */ #endif @@ -50,6 +50,7 @@ THE SOFTWARE. #include #include #include +#include #include struct _mbedtls_ctx @@ -795,7 +796,11 @@ static WaitressReturn_t WaitressTlsVerify (const WaitressHandle_t *waith) { return WAITRESS_RET_TLS_HANDSHAKE_ERR; } +#if MBEDTLS_VERSION_NUMBER >= 0x02070000 + mbedtls_sha1_ret (cert->raw.p, cert->raw.len, fingerprint); +#else mbedtls_sha1 (cert->raw.p, cert->raw.len, fingerprint); +#endif if (memcmp (fingerprint, waith->tlsFingerprint, sizeof (fingerprint)) != 0) { return WAITRESS_RET_TLS_FINGERPRINT_MISMATCH; diff --git a/src/pianod.c b/src/pianod.c index f333764..3726004 100644 --- a/src/pianod.c +++ b/src/pianod.c @@ -32,7 +32,7 @@ #ifndef __FreeBSD__ #define _POSIX_C_SOURCE 1 /* fileno() */ -#define _BSD_SOURCE /* strdup() */ +#define _DEFAULT_SOURCE /* strdup() */ #define _DARWIN_C_SOURCE /* strdup() on OS X */ #endif @@ -74,20 +74,7 @@ extern void ripit_open_file(struct audioPlayer *player, PianoSong_t *song); #endif -#ifndef HAVE_SETPROGNAME -static const char *progname; -void setprogname (const char *name) { - const char *last = strrchr(name, '/'); - if (last) { - progname = last+1; - } else { - progname = name; - } -} -const char *getprogname (void) { - return progname; -} -#endif +static const char *progname = "pianod"; /* Fetch a new playlist from Pandora. */ @@ -655,7 +642,7 @@ static void usage () { #if defined(ENABLE_CAPTURE) " -m capturedir : a directory for stream capture\n" #endif - , getprogname()); + , progname); } @@ -674,7 +661,6 @@ int main (int argc, char **argv) { struct stat sbuf; #endif - setprogname(*argv); memset (&app, 0, sizeof (app)); settings_get_config_dir (PACKAGE, "startscript", startscriptname, sizeof (startscriptname)); diff --git a/src/query.c b/src/query.c index 9446c7e..2771502 100644 --- a/src/query.c +++ b/src/query.c @@ -9,7 +9,7 @@ #ifndef __FreeBSD__ #define _POSIX_C_SOURCE 1 /* fileno() */ -#define _BSD_SOURCE /* strdup() */ +#define _DEFAULT_SOURCE /* strdup() */ #define _DARWIN_C_SOURCE /* strdup() on OS X */ #endif diff --git a/src/seeds.c b/src/seeds.c index 7c89c18..113c911 100644 --- a/src/seeds.c +++ b/src/seeds.c @@ -8,7 +8,7 @@ */ #ifndef __FreeBSD__ -#define _BSD_SOURCE /* strdup() */ +#define _DEFAULT_SOURCE /* strdup() */ #define _DARWIN_C_SOURCE /* strdup() on OS X */ #endif diff --git a/src/settings.c b/src/settings.c index 3e02b05..ec4bdcc 100644 --- a/src/settings.c +++ b/src/settings.c @@ -34,7 +34,7 @@ THE SOFTWARE. #ifndef __FreeBSD__ #define _POSIX_C_SOURCE 1 /* PATH_MAX */ -#define _BSD_SOURCE /* strdup() */ +#define _DEFAULT_SOURCE /* strdup() */ #define _DARWIN_C_SOURCE /* strdup() on OS X */ #endif diff --git a/src/shoutcast.c b/src/shoutcast.c index b9bf433..7310f0b 100644 --- a/src/shoutcast.c +++ b/src/shoutcast.c @@ -128,7 +128,7 @@ void sc_close_service(sc_service *svc) // Cleanup queue thread_queue_cleanup(&svc->sc_queue, 0); - if (svc->si); + if (svc->si) free(svc->si); if (svc->shout) diff --git a/src/support.c b/src/support.c index 5003dac..2886796 100644 --- a/src/support.c +++ b/src/support.c @@ -31,7 +31,7 @@ THE SOFTWARE. #ifndef __FreeBSD__ #define _POSIX_C_SOURCE 1 /* fileno() */ -#define _BSD_SOURCE /* strdup() */ +#define _DEFAULT_SOURCE /* strdup() */ #define _DARWIN_C_SOURCE /* strdup() on OS X */ #endif diff --git a/src/users.c b/src/users.c index adec026..2a35902 100644 --- a/src/users.c +++ b/src/users.c @@ -8,7 +8,7 @@ */ #ifndef __FreeBSD__ -#define _BSD_SOURCE /* snprintf() */ +#define _DEFAULT_SOURCE /* snprintf() */ #endif #include