mirror of
https://github.com/owntone/owntone-server.git
synced 2025-11-10 14:09:51 -05:00
Full removal of libevent 1 legacy code. Also drop pipe() in FreeBSD, since pipe2 is available now.
This commit is contained in:
12
configure.ac
12
configure.ac
@@ -113,17 +113,7 @@ LIBS="$save_LIBS"
|
|||||||
|
|
||||||
PKG_CHECK_MODULES(MINIXML, [ mxml ])
|
PKG_CHECK_MODULES(MINIXML, [ mxml ])
|
||||||
|
|
||||||
PKG_CHECK_MODULES(LIBEVENT, [ libevent >= 2 ],
|
PKG_CHECK_MODULES(LIBEVENT, [ libevent >= 2 ])
|
||||||
AC_DEFINE(HAVE_LIBEVENT2, 1, [Define to 1 if you have libevent 2])
|
|
||||||
)
|
|
||||||
|
|
||||||
AM_CONDITIONAL(COND_LIBEVENT20, false)
|
|
||||||
AM_CONDITIONAL(COND_LIBEVENT21, false)
|
|
||||||
|
|
||||||
PKG_CHECK_EXISTS([ libevent >= 2.1 ],
|
|
||||||
AM_CONDITIONAL(COND_LIBEVENT21, true),
|
|
||||||
AM_CONDITIONAL(COND_LIBEVENT20, true)
|
|
||||||
)
|
|
||||||
PKG_CHECK_EXISTS([ libevent >= 2.1.4 ], ,
|
PKG_CHECK_EXISTS([ libevent >= 2.1.4 ], ,
|
||||||
AC_DEFINE(HAVE_LIBEVENT2_OLD, 1, [Define to 1 if you have libevent 2 (<2.1.4)])
|
AC_DEFINE(HAVE_LIBEVENT2_OLD, 1, [Define to 1 if you have libevent 2 (<2.1.4)])
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -25,14 +25,6 @@ if COND_OSS4
|
|||||||
OSS4_SRC=laudio_oss4.c
|
OSS4_SRC=laudio_oss4.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if COND_LIBEVENT20
|
|
||||||
RTSP_SRC=evrtsp/rtsp-libevent20.c evrtp/evrtsp.h evrtsp/rtsp-internal.h evrtsp/log.h
|
|
||||||
endif
|
|
||||||
|
|
||||||
if COND_LIBEVENT21
|
|
||||||
RTSP_SRC=evrtsp/rtsp.c evrtp/evrtsp.h evrtsp/rtsp-internal.h evrtsp/log.h
|
|
||||||
endif
|
|
||||||
|
|
||||||
GPERF_FILES = \
|
GPERF_FILES = \
|
||||||
daap_query.gperf \
|
daap_query.gperf \
|
||||||
rsp_query.gperf \
|
rsp_query.gperf \
|
||||||
@@ -109,7 +101,7 @@ forked_daapd_SOURCES = main.c \
|
|||||||
laudio_dummy.c \
|
laudio_dummy.c \
|
||||||
laudio.c laudio.h \
|
laudio.c laudio.h \
|
||||||
raop.c raop.h \
|
raop.c raop.h \
|
||||||
$(RTSP_SRC) \
|
evrtsp/rtsp.c evrtp/evrtsp.h evrtsp/rtsp-internal.h evrtsp/log.h \
|
||||||
$(SPOTIFY_SRC) \
|
$(SPOTIFY_SRC) \
|
||||||
$(LASTFM_SRC) \
|
$(LASTFM_SRC) \
|
||||||
$(MPD_SRC) \
|
$(MPD_SRC) \
|
||||||
|
|||||||
@@ -44,10 +44,6 @@
|
|||||||
#include "avio_evbuffer.h"
|
#include "avio_evbuffer.h"
|
||||||
#include "artwork.h"
|
#include "artwork.h"
|
||||||
|
|
||||||
#ifndef HAVE_LIBEVENT2
|
|
||||||
# define evbuffer_get_length(x) (x)->off
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_SPOTIFY_H
|
#ifdef HAVE_SPOTIFY_H
|
||||||
# include "spotify.h"
|
# include "spotify.h"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,11 +5,7 @@
|
|||||||
#define ART_FMT_PNG 1
|
#define ART_FMT_PNG 1
|
||||||
#define ART_FMT_JPEG 2
|
#define ART_FMT_JPEG 2
|
||||||
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
#include <event2/buffer.h>
|
#include <event2/buffer.h>
|
||||||
#else
|
|
||||||
# include <event.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Get artwork for individual track */
|
/* Get artwork for individual track */
|
||||||
int
|
int
|
||||||
|
|||||||
@@ -2,11 +2,7 @@
|
|||||||
#ifndef __AVIO_EVBUFFER_H__
|
#ifndef __AVIO_EVBUFFER_H__
|
||||||
#define __AVIO_EVBUFFER_H__
|
#define __AVIO_EVBUFFER_H__
|
||||||
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
#include <event2/buffer.h>
|
#include <event2/buffer.h>
|
||||||
#else
|
|
||||||
# include <event.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
AVIOContext *
|
AVIOContext *
|
||||||
avio_evbuffer_open(struct evbuffer *evbuf);
|
avio_evbuffer_open(struct evbuffer *evbuf);
|
||||||
|
|||||||
49
src/cache.c
49
src/cache.c
@@ -31,6 +31,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#include <event2/event.h>
|
||||||
|
|
||||||
#include "conffile.h"
|
#include "conffile.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "httpd_daap.h"
|
#include "httpd_daap.h"
|
||||||
@@ -661,13 +663,8 @@ cache_daap_reply_add(const char *query, struct evbuffer *evbuf)
|
|||||||
size_t datalen;
|
size_t datalen;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
datalen = evbuffer_get_length(evbuf);
|
datalen = evbuffer_get_length(evbuf);
|
||||||
data = evbuffer_pullup(evbuf, -1);
|
data = evbuffer_pullup(evbuf, -1);
|
||||||
#else
|
|
||||||
datalen = EVBUFFER_LENGTH(evbuf);
|
|
||||||
data = EVBUFFER_DATA(evbuf);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ret = sqlite3_prepare_v2(g_db_hdl, Q_TMPL, -1, &stmt, 0);
|
ret = sqlite3_prepare_v2(g_db_hdl, Q_TMPL, -1, &stmt, 0);
|
||||||
if (ret != SQLITE_OK)
|
if (ret != SQLITE_OK)
|
||||||
@@ -1123,13 +1120,8 @@ cache_artwork_add_impl(struct cache_command *cmd)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
datalen = evbuffer_get_length(cmd->arg.evbuf);
|
datalen = evbuffer_get_length(cmd->arg.evbuf);
|
||||||
data = evbuffer_pullup(cmd->arg.evbuf, -1);
|
data = evbuffer_pullup(cmd->arg.evbuf, -1);
|
||||||
#else
|
|
||||||
datalen = EVBUFFER_LENGTH(cmd->arg.evbuf);
|
|
||||||
data = EVBUFFER_DATA(cmd->arg.evbuf);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
sqlite3_bind_int64(stmt, 1, cmd->arg.persistentid);
|
sqlite3_bind_int64(stmt, 1, cmd->arg.persistentid);
|
||||||
sqlite3_bind_int(stmt, 2, cmd->arg.max_w);
|
sqlite3_bind_int(stmt, 2, cmd->arg.max_w);
|
||||||
@@ -1793,22 +1785,14 @@ cache_init(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
# if defined(__linux__)
|
|
||||||
ret = pipe2(g_exit_pipe, O_CLOEXEC);
|
ret = pipe2(g_exit_pipe, O_CLOEXEC);
|
||||||
# else
|
|
||||||
ret = pipe(g_exit_pipe);
|
|
||||||
# endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_CACHE, "Could not create pipe: %s\n", strerror(errno));
|
DPRINTF(E_LOG, L_CACHE, "Could not create pipe: %s\n", strerror(errno));
|
||||||
goto exit_fail;
|
goto exit_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
# if defined(__linux__)
|
|
||||||
ret = pipe2(g_cmd_pipe, O_CLOEXEC);
|
ret = pipe2(g_cmd_pipe, O_CLOEXEC);
|
||||||
# else
|
|
||||||
ret = pipe(g_cmd_pipe);
|
|
||||||
# endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_CACHE, "Could not create command pipe: %s\n", strerror(errno));
|
DPRINTF(E_LOG, L_CACHE, "Could not create command pipe: %s\n", strerror(errno));
|
||||||
@@ -1822,7 +1806,6 @@ cache_init(void)
|
|||||||
goto evbase_fail;
|
goto evbase_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
g_exitev = event_new(evbase_cache, g_exit_pipe[0], EV_READ, exit_cb, NULL);
|
g_exitev = event_new(evbase_cache, g_exit_pipe[0], EV_READ, exit_cb, NULL);
|
||||||
if (!g_exitev)
|
if (!g_exitev)
|
||||||
{
|
{
|
||||||
@@ -1843,34 +1826,6 @@ cache_init(void)
|
|||||||
DPRINTF(E_LOG, L_CACHE, "Could not create cache event\n");
|
DPRINTF(E_LOG, L_CACHE, "Could not create cache event\n");
|
||||||
goto evnew_fail;
|
goto evnew_fail;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
g_exitev = (struct event *)malloc(sizeof(struct event));
|
|
||||||
if (!g_exitev)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_CACHE, "Could not create exit event\n");
|
|
||||||
goto evnew_fail;
|
|
||||||
}
|
|
||||||
event_set(g_exitev, g_exit_pipe[0], EV_READ, exit_cb, NULL);
|
|
||||||
event_base_set(evbase_cache, g_exitev);
|
|
||||||
|
|
||||||
g_cmdev = (struct event *)malloc(sizeof(struct event));
|
|
||||||
if (!g_cmdev)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_CACHE, "Could not create cmd event\n");
|
|
||||||
goto evnew_fail;
|
|
||||||
}
|
|
||||||
event_set(g_cmdev, g_cmd_pipe[0], EV_READ, command_cb, NULL);
|
|
||||||
event_base_set(evbase_cache, g_cmdev);
|
|
||||||
|
|
||||||
g_cacheev = (struct event *)malloc(sizeof(struct event));
|
|
||||||
if (!g_cacheev)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_CACHE, "Could not create cache event\n");
|
|
||||||
goto evnew_fail;
|
|
||||||
}
|
|
||||||
event_set(g_cacheev, -1, EV_TIMEOUT, cache_daap_update_cb, NULL);
|
|
||||||
event_base_set(evbase_cache, g_cacheev);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
event_add(g_exitev, NULL);
|
event_add(g_exitev, NULL);
|
||||||
event_add(g_cmdev, NULL);
|
event_add(g_cmdev, NULL);
|
||||||
|
|||||||
@@ -2,13 +2,7 @@
|
|||||||
#ifndef __CACHE_H__
|
#ifndef __CACHE_H__
|
||||||
#define __CACHE_H__
|
#define __CACHE_H__
|
||||||
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
# include <event2/event.h>
|
|
||||||
#include <event2/buffer.h>
|
#include <event2/buffer.h>
|
||||||
#else
|
|
||||||
# include <event.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------- DAAP cache API --------------------------- */
|
/* ---------------------------- DAAP cache API --------------------------- */
|
||||||
|
|
||||||
|
|||||||
@@ -23,10 +23,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifndef HAVE_LIBEVENT2
|
|
||||||
# define evbuffer_get_length(x) (x)->off
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|||||||
@@ -2,13 +2,8 @@
|
|||||||
#ifndef __DMAP_HELPERS_H__
|
#ifndef __DMAP_HELPERS_H__
|
||||||
#define __DMAP_HELPERS_H__
|
#define __DMAP_HELPERS_H__
|
||||||
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
#include <event2/buffer.h>
|
#include <event2/buffer.h>
|
||||||
#include <event2/http.h>
|
#include <event2/http.h>
|
||||||
#else
|
|
||||||
# include <event.h>
|
|
||||||
# include "evhttp/evhttp.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
#ifndef _EVRTSP_H_
|
#ifndef _EVRTSP_H_
|
||||||
#define _EVRTSP_H_
|
#define _EVRTSP_H_
|
||||||
|
|
||||||
#include <event.h>
|
#include <event2/event.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
@@ -13,6 +13,9 @@
|
|||||||
#ifndef _RTSP_H_
|
#ifndef _RTSP_H_
|
||||||
#define _RTSP_H_
|
#define _RTSP_H_
|
||||||
|
|
||||||
|
#include <event2/buffer.h>
|
||||||
|
#include <event2/event_struct.h>
|
||||||
|
|
||||||
#define RTSP_CONNECT_TIMEOUT 45
|
#define RTSP_CONNECT_TIMEOUT 45
|
||||||
#define RTSP_WRITE_TIMEOUT 50
|
#define RTSP_WRITE_TIMEOUT 50
|
||||||
#define RTSP_READ_TIMEOUT 50
|
#define RTSP_READ_TIMEOUT 50
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -28,40 +28,18 @@
|
|||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <event.h>
|
|
||||||
|
|
||||||
#ifdef EVENT__HAVE_SYS_PARAM_H
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#endif
|
|
||||||
#ifdef EVENT__HAVE_SYS_TYPES_H
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef EVENT__HAVE_SYS_TIME_H
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
|
||||||
#ifdef EVENT__HAVE_SYS_IOCCOM_H
|
|
||||||
#include <sys/ioccom.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef WIN32
|
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
|
|
||||||
#ifndef WIN32
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <winsock2.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -69,17 +47,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#ifndef WIN32
|
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#endif
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#ifdef EVENT__HAVE_UNISTD_H
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
|
||||||
#ifdef EVENT__HAVE_FCNTL_H
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#endif
|
|
||||||
|
#include <event2/event-config.h>
|
||||||
|
|
||||||
#undef timeout_pending
|
#undef timeout_pending
|
||||||
#undef timeout_initialized
|
#undef timeout_initialized
|
||||||
@@ -89,10 +63,15 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "rtsp-internal.h"
|
#include "rtsp-internal.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
// For compability with libevent 2.0 (HAVE_LIBEVENT2_OLD)
|
||||||
#define strcasecmp _stricmp
|
#if defined(_EVENT_HAVE_GETNAMEINFO)
|
||||||
#define strncasecmp _strnicmp
|
# define EVENT__HAVE_GETNAMEINFO 1
|
||||||
#define strdup _strdup
|
#endif
|
||||||
|
#if defined(_EVENT_HAVE_GETADDRINFO)
|
||||||
|
# define EVENT__HAVE_GETADDRINFO 1
|
||||||
|
#endif
|
||||||
|
#if defined(_EVENT_HAVE_STRSEP)
|
||||||
|
# define EVENT__HAVE_STRSEP 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef EVENT__HAVE_GETNAMEINFO
|
#ifndef EVENT__HAVE_GETNAMEINFO
|
||||||
|
|||||||
@@ -24,7 +24,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_LIBAV_PACKET_RESCALE_TS
|
#ifndef HAVE_LIBAV_PACKET_RESCALE_TS
|
||||||
void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
|
static void
|
||||||
|
av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
|
||||||
{
|
{
|
||||||
if (pkt->pts != AV_NOPTS_VALUE)
|
if (pkt->pts != AV_NOPTS_VALUE)
|
||||||
pkt->pts = av_rescale_q(pkt->pts, src_tb, dst_tb);
|
pkt->pts = av_rescale_q(pkt->pts, src_tb, dst_tb);
|
||||||
@@ -38,8 +39,8 @@ void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_LIBAV_ALLOC_OUTPUT_CONTEXT2
|
#ifndef HAVE_LIBAV_ALLOC_OUTPUT_CONTEXT2
|
||||||
int avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *oformat,
|
static int
|
||||||
const char *format, const char *filename)
|
avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *oformat, const char *format, const char *filename)
|
||||||
{
|
{
|
||||||
AVFormatContext *s = avformat_alloc_context();
|
AVFormatContext *s = avformat_alloc_context();
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|||||||
@@ -48,16 +48,11 @@
|
|||||||
# include <sys/event.h>
|
# include <sys/event.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_SYS_EVENTFD_H) && defined(HAVE_EVENTFD)
|
|
||||||
# define USE_EVENTFD
|
|
||||||
# include <sys/eventfd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_REGEX_H
|
#ifdef HAVE_REGEX_H
|
||||||
# include <regex.h>
|
# include <regex.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <event.h>
|
#include <event2/event.h>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
@@ -126,17 +121,13 @@ struct stacked_dir {
|
|||||||
|
|
||||||
|
|
||||||
static int cmd_pipe[2];
|
static int cmd_pipe[2];
|
||||||
#ifdef USE_EVENTFD
|
|
||||||
static int exit_efd;
|
|
||||||
#else
|
|
||||||
static int exit_pipe[2];
|
static int exit_pipe[2];
|
||||||
#endif
|
|
||||||
static int scan_exit;
|
static int scan_exit;
|
||||||
static int inofd;
|
static int inofd;
|
||||||
static struct event_base *evbase_scan;
|
static struct event_base *evbase_scan;
|
||||||
static struct event inoev;
|
static struct event *inoev;
|
||||||
static struct event exitev;
|
static struct event *exitev;
|
||||||
static struct event cmdev;
|
static struct event *cmdev;
|
||||||
static pthread_t tid_scan;
|
static pthread_t tid_scan;
|
||||||
static struct deferred_pl *playlists;
|
static struct deferred_pl *playlists;
|
||||||
static struct stacked_dir *dirstack;
|
static struct stacked_dir *dirstack;
|
||||||
@@ -154,8 +145,8 @@ static int scanning;
|
|||||||
* when we get the IN_CREATE and then ignore the IN_ATTRIB for these files.
|
* when we get the IN_CREATE and then ignore the IN_ATTRIB for these files.
|
||||||
*/
|
*/
|
||||||
#define INCOMINGFILES_BUFFER_SIZE 50
|
#define INCOMINGFILES_BUFFER_SIZE 50
|
||||||
int incomingfiles_idx;
|
static int incomingfiles_idx;
|
||||||
uint32_t incomingfiles_buffer[INCOMINGFILES_BUFFER_SIZE];
|
static uint32_t incomingfiles_buffer[INCOMINGFILES_BUFFER_SIZE];
|
||||||
|
|
||||||
/* Forward */
|
/* Forward */
|
||||||
static void
|
static void
|
||||||
@@ -1302,7 +1293,7 @@ filescanner(void *arg)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Enable inotify */
|
/* Enable inotify */
|
||||||
event_add(&inoev, NULL);
|
event_add(inoev, NULL);
|
||||||
|
|
||||||
event_base_dispatch(evbase_scan);
|
event_base_dispatch(evbase_scan);
|
||||||
}
|
}
|
||||||
@@ -1763,7 +1754,7 @@ inotify_cb(int fd, short event, void *arg)
|
|||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
event_add(&inoev, NULL);
|
event_add(inoev, NULL);
|
||||||
}
|
}
|
||||||
#endif /* __linux__ */
|
#endif /* __linux__ */
|
||||||
|
|
||||||
@@ -1946,7 +1937,7 @@ kqueue_cb(int fd, short event, void *arg)
|
|||||||
DPRINTF(E_LOG, L_SCAN, "WARNING: unhandled leftover directories\n");
|
DPRINTF(E_LOG, L_SCAN, "WARNING: unhandled leftover directories\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
event_add(&inoev, NULL);
|
event_add(inoev, NULL);
|
||||||
}
|
}
|
||||||
#endif /* __FreeBSD__ || __FreeBSD_kernel__ */
|
#endif /* __FreeBSD__ || __FreeBSD_kernel__ */
|
||||||
|
|
||||||
@@ -1963,7 +1954,7 @@ inofd_event_set(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_set(&inoev, inofd, EV_READ, inotify_cb, NULL);
|
inoev = event_new(evbase_scan, inofd, EV_READ, inotify_cb, NULL);
|
||||||
|
|
||||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||||
|
|
||||||
@@ -1975,11 +1966,9 @@ inofd_event_set(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_set(&inoev, inofd, EV_READ, kqueue_cb, NULL);
|
inoev = event_new(evbase_scan, inofd, EV_READ, kqueue_cb, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
event_base_set(evbase_scan, &inoev);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1987,7 +1976,7 @@ inofd_event_set(void)
|
|||||||
static void
|
static void
|
||||||
inofd_event_unset(void)
|
inofd_event_unset(void)
|
||||||
{
|
{
|
||||||
event_del(&inoev);
|
event_free(inoev);
|
||||||
close(inofd);
|
close(inofd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2030,7 +2019,7 @@ command_cb(int fd, short what, void *arg)
|
|||||||
pthread_mutex_unlock(&cmd->lck);
|
pthread_mutex_unlock(&cmd->lck);
|
||||||
|
|
||||||
readd:
|
readd:
|
||||||
event_add(&cmdev, NULL);
|
event_add(cmdev, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -2145,27 +2134,20 @@ filescanner_init(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_EVENTFD
|
|
||||||
exit_efd = eventfd(0, EFD_CLOEXEC);
|
|
||||||
if (exit_efd < 0)
|
|
||||||
{
|
|
||||||
DPRINTF(E_FATAL, L_SCAN, "Could not create eventfd: %s\n", strerror(errno));
|
|
||||||
|
|
||||||
goto pipe_fail;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# if defined(__linux__)
|
|
||||||
ret = pipe2(exit_pipe, O_CLOEXEC);
|
ret = pipe2(exit_pipe, O_CLOEXEC);
|
||||||
# else
|
|
||||||
ret = pipe(exit_pipe);
|
|
||||||
# endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_FATAL, L_SCAN, "Could not create pipe: %s\n", strerror(errno));
|
DPRINTF(E_FATAL, L_SCAN, "Could not create pipe: %s\n", strerror(errno));
|
||||||
|
|
||||||
goto pipe_fail;
|
goto pipe_fail;
|
||||||
}
|
}
|
||||||
#endif /* USE_EVENTFD */
|
|
||||||
|
exitev = event_new(evbase_scan, exit_pipe[0], EV_READ, exit_cb, NULL);
|
||||||
|
if (!exitev || (event_add(exitev, NULL) < 0))
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_SCAN, "Could not create/add command event\n");
|
||||||
|
goto exitev_fail;
|
||||||
|
}
|
||||||
|
|
||||||
ret = inofd_event_set();
|
ret = inofd_event_set();
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@@ -2173,28 +2155,19 @@ filescanner_init(void)
|
|||||||
goto ino_fail;
|
goto ino_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_EVENTFD
|
|
||||||
event_set(&exitev, exit_efd, EV_READ, exit_cb, NULL);
|
|
||||||
#else
|
|
||||||
event_set(&exitev, exit_pipe[0], EV_READ, exit_cb, NULL);
|
|
||||||
#endif
|
|
||||||
event_base_set(evbase_scan, &exitev);
|
|
||||||
event_add(&exitev, NULL);
|
|
||||||
|
|
||||||
# if defined(__linux__)
|
|
||||||
ret = pipe2(cmd_pipe, O_CLOEXEC);
|
ret = pipe2(cmd_pipe, O_CLOEXEC);
|
||||||
# else
|
|
||||||
ret = pipe(cmd_pipe);
|
|
||||||
# endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SCAN, "Could not create command pipe: %s\n", strerror(errno));
|
DPRINTF(E_LOG, L_SCAN, "Could not create command pipe: %s\n", strerror(errno));
|
||||||
goto cmd_fail;
|
goto cmd_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_set(&cmdev, cmd_pipe[0], EV_READ, command_cb, NULL);
|
cmdev = event_new(evbase_scan, cmd_pipe[0], EV_READ, command_cb, NULL);
|
||||||
event_base_set(evbase_scan, &cmdev);
|
if (!cmdev || (event_add(cmdev, NULL) < 0))
|
||||||
event_add(&cmdev, NULL);
|
{
|
||||||
|
DPRINTF(E_LOG, L_SCAN, "Could not create/add command event\n");
|
||||||
|
goto cmd_fail;
|
||||||
|
}
|
||||||
|
|
||||||
ret = pthread_create(&tid_scan, NULL, filescanner, NULL);
|
ret = pthread_create(&tid_scan, NULL, filescanner, NULL);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
@@ -2211,13 +2184,10 @@ filescanner_init(void)
|
|||||||
close(cmd_pipe[0]);
|
close(cmd_pipe[0]);
|
||||||
close(cmd_pipe[1]);
|
close(cmd_pipe[1]);
|
||||||
close(inofd);
|
close(inofd);
|
||||||
|
exitev_fail:
|
||||||
ino_fail:
|
ino_fail:
|
||||||
#ifdef USE_EVENTFD
|
|
||||||
close(exit_efd);
|
|
||||||
#else
|
|
||||||
close(exit_pipe[0]);
|
close(exit_pipe[0]);
|
||||||
close(exit_pipe[1]);
|
close(exit_pipe[1]);
|
||||||
#endif
|
|
||||||
pipe_fail:
|
pipe_fail:
|
||||||
event_base_free(evbase_scan);
|
event_base_free(evbase_scan);
|
||||||
|
|
||||||
@@ -2229,16 +2199,6 @@ void
|
|||||||
filescanner_deinit(void)
|
filescanner_deinit(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#ifdef USE_EVENTFD
|
|
||||||
ret = eventfd_write(exit_efd, 1);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
DPRINTF(E_FATAL, L_SCAN, "Could not send exit event: %s\n", strerror(errno));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
int dummy = 42;
|
int dummy = 42;
|
||||||
|
|
||||||
ret = write(exit_pipe[1], &dummy, sizeof(dummy));
|
ret = write(exit_pipe[1], &dummy, sizeof(dummy));
|
||||||
@@ -2248,7 +2208,6 @@ filescanner_deinit(void)
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
scan_exit = 1;
|
scan_exit = 1;
|
||||||
|
|
||||||
@@ -2262,12 +2221,8 @@ filescanner_deinit(void)
|
|||||||
|
|
||||||
inofd_event_unset();
|
inofd_event_unset();
|
||||||
|
|
||||||
#ifdef USE_EVENTFD
|
|
||||||
close(exit_efd);
|
|
||||||
#else
|
|
||||||
close(exit_pipe[0]);
|
close(exit_pipe[0]);
|
||||||
close(exit_pipe[1]);
|
close(exit_pipe[1]);
|
||||||
#endif
|
|
||||||
close(cmd_pipe[0]);
|
close(cmd_pipe[0]);
|
||||||
close(cmd_pipe[1]);
|
close(cmd_pipe[1]);
|
||||||
event_base_free(evbase_scan);
|
event_base_free(evbase_scan);
|
||||||
|
|||||||
@@ -37,11 +37,7 @@
|
|||||||
|
|
||||||
#include <plist/plist.h>
|
#include <plist/plist.h>
|
||||||
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
#include <event2/http.h>
|
#include <event2/http.h>
|
||||||
#else
|
|
||||||
# include "evhttp/evhttp.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
|
|||||||
58
src/httpd.c
58
src/httpd.c
@@ -40,7 +40,11 @@
|
|||||||
# define USE_EVENTFD
|
# define USE_EVENTFD
|
||||||
# include <sys/eventfd.h>
|
# include <sys/eventfd.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <event2/event.h>
|
||||||
|
#ifdef HAVE_LIBEVENT2_OLD
|
||||||
|
# include <event2/bufferevent.h>
|
||||||
|
# include <event2/bufferevent_struct.h>
|
||||||
|
#endif
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
@@ -85,7 +89,7 @@ struct stream_ctx {
|
|||||||
struct evhttp_request *req;
|
struct evhttp_request *req;
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
struct evbuffer *evbuf;
|
struct evbuffer *evbuf;
|
||||||
struct event ev;
|
struct event *ev;
|
||||||
int id;
|
int id;
|
||||||
int fd;
|
int fd;
|
||||||
off_t size;
|
off_t size;
|
||||||
@@ -119,7 +123,7 @@ static int exit_efd;
|
|||||||
static int exit_pipe[2];
|
static int exit_pipe[2];
|
||||||
#endif
|
#endif
|
||||||
static int httpd_exit;
|
static int httpd_exit;
|
||||||
static struct event exitev;
|
static struct event *exitev;
|
||||||
static struct evhttp *evhttpd;
|
static struct evhttp *evhttpd;
|
||||||
static pthread_t tid_httpd;
|
static pthread_t tid_httpd;
|
||||||
|
|
||||||
@@ -142,6 +146,7 @@ stream_end(struct stream_ctx *st, int failed)
|
|||||||
evhttp_send_reply_end(st->req);
|
evhttp_send_reply_end(st->req);
|
||||||
|
|
||||||
evbuffer_free(st->evbuf);
|
evbuffer_free(st->evbuf);
|
||||||
|
event_free(st->ev);
|
||||||
|
|
||||||
if (st->xcode)
|
if (st->xcode)
|
||||||
transcode_cleanup(st->xcode);
|
transcode_cleanup(st->xcode);
|
||||||
@@ -181,7 +186,7 @@ stream_chunk_resched_cb(struct evhttp_connection *evcon, void *arg)
|
|||||||
st = (struct stream_ctx *)arg;
|
st = (struct stream_ctx *)arg;
|
||||||
|
|
||||||
evutil_timerclear(&tv);
|
evutil_timerclear(&tv);
|
||||||
ret = event_add(&st->ev, &tv);
|
ret = event_add(st->ev, &tv);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_HTTPD, "Could not re-add one-shot event for streaming\n");
|
DPRINTF(E_LOG, L_HTTPD, "Could not re-add one-shot event for streaming\n");
|
||||||
@@ -267,7 +272,7 @@ stream_chunk_xcode_cb(int fd, short event, void *arg)
|
|||||||
|
|
||||||
consume: /* reschedule immediately - consume up to start_offset */
|
consume: /* reschedule immediately - consume up to start_offset */
|
||||||
evutil_timerclear(&tv);
|
evutil_timerclear(&tv);
|
||||||
ret = event_add(&st->ev, &tv);
|
ret = event_add(st->ev, &tv);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_HTTPD, "Could not re-add one-shot event for streaming (xcode)\n");
|
DPRINTF(E_LOG, L_HTTPD, "Could not re-add one-shot event for streaming (xcode)\n");
|
||||||
@@ -340,7 +345,7 @@ stream_fail_cb(struct evhttp_connection *evcon, void *arg)
|
|||||||
DPRINTF(E_WARN, L_HTTPD, "Connection failed; stopping streaming of file ID %d\n", st->id);
|
DPRINTF(E_WARN, L_HTTPD, "Connection failed; stopping streaming of file ID %d\n", st->id);
|
||||||
|
|
||||||
/* Stop streaming */
|
/* Stop streaming */
|
||||||
event_del(&st->ev);
|
event_del(st->ev);
|
||||||
|
|
||||||
stream_end(st, 1);
|
stream_end(st, 1);
|
||||||
}
|
}
|
||||||
@@ -564,11 +569,9 @@ httpd_stream_file(struct evhttp_request *req, int id)
|
|||||||
goto out_cleanup;
|
goto out_cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
st->ev = event_new(evbase_httpd, -1, EV_TIMEOUT, stream_cb, st);
|
||||||
evutil_timerclear(&tv);
|
evutil_timerclear(&tv);
|
||||||
event_set(&st->ev, -1, EV_TIMEOUT, stream_cb, st);
|
if (!st->ev || (event_add(st->ev, &tv) < 0))
|
||||||
event_base_set(evbase_httpd, &st->ev);
|
|
||||||
ret = event_add(&st->ev, &tv);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_HTTPD, "Could not add one-shot event for streaming\n");
|
DPRINTF(E_LOG, L_HTTPD, "Could not add one-shot event for streaming\n");
|
||||||
|
|
||||||
@@ -676,7 +679,7 @@ httpd_send_reply(struct evhttp_request *req, int code, const char *reason, struc
|
|||||||
if (!req)
|
if (!req)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!evbuf || (EVBUFFER_LENGTH(evbuf) == 0))
|
if (!evbuf || (evbuffer_get_length(evbuf) == 0))
|
||||||
{
|
{
|
||||||
DPRINTF(E_DBG, L_HTTPD, "Not gzipping body-less reply\n");
|
DPRINTF(E_DBG, L_HTTPD, "Not gzipping body-less reply\n");
|
||||||
|
|
||||||
@@ -720,8 +723,8 @@ httpd_send_reply(struct evhttp_request *req, int code, const char *reason, struc
|
|||||||
goto out_fail_init;
|
goto out_fail_init;
|
||||||
}
|
}
|
||||||
|
|
||||||
strm.next_in = EVBUFFER_DATA(evbuf);
|
strm.next_in = evbuffer_pullup(evbuf, -1);
|
||||||
strm.avail_in = EVBUFFER_LENGTH(evbuf);
|
strm.avail_in = evbuffer_get_length(evbuf);
|
||||||
|
|
||||||
flush = Z_NO_FLUSH;
|
flush = Z_NO_FLUSH;
|
||||||
|
|
||||||
@@ -774,7 +777,7 @@ httpd_send_reply(struct evhttp_request *req, int code, const char *reason, struc
|
|||||||
evbuffer_free(gzbuf);
|
evbuffer_free(gzbuf);
|
||||||
|
|
||||||
/* Drain original buffer, as would be after evhttp_send_reply() */
|
/* Drain original buffer, as would be after evhttp_send_reply() */
|
||||||
evbuffer_drain(evbuf, EVBUFFER_LENGTH(evbuf));
|
evbuffer_drain(evbuf, evbuffer_get_length(evbuf));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1329,34 +1332,33 @@ httpd_init(void)
|
|||||||
|
|
||||||
goto pipe_fail;
|
goto pipe_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exitev = event_new(evbase_httpd, exit_efd, EV_READ, exit_cb, NULL);
|
||||||
#else
|
#else
|
||||||
# if defined(__linux__)
|
|
||||||
ret = pipe2(exit_pipe, O_CLOEXEC);
|
ret = pipe2(exit_pipe, O_CLOEXEC);
|
||||||
# else
|
|
||||||
ret = pipe(exit_pipe);
|
|
||||||
# endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_FATAL, L_HTTPD, "Could not create pipe: %s\n", strerror(errno));
|
DPRINTF(E_FATAL, L_HTTPD, "Could not create pipe: %s\n", strerror(errno));
|
||||||
|
|
||||||
goto pipe_fail;
|
goto pipe_fail;
|
||||||
}
|
}
|
||||||
#endif /* USE_EVENTFD */
|
|
||||||
|
|
||||||
#ifdef USE_EVENTFD
|
exitev = event_new(evbase_httpd, exit_pipe[0], EV_READ, exit_cb, NULL);
|
||||||
event_set(&exitev, exit_efd, EV_READ, exit_cb, NULL);
|
#endif /* USE_EVENTFD */
|
||||||
#else
|
if (!exitev)
|
||||||
event_set(&exitev, exit_pipe[0], EV_READ, exit_cb, NULL);
|
{
|
||||||
#endif
|
DPRINTF(E_FATAL, L_HTTPD, "Could not create exit event\n");
|
||||||
event_base_set(evbase_httpd, &exitev);
|
|
||||||
event_add(&exitev, NULL);
|
goto event_fail;
|
||||||
|
}
|
||||||
|
event_add(exitev, NULL);
|
||||||
|
|
||||||
evhttpd = evhttp_new(evbase_httpd);
|
evhttpd = evhttp_new(evbase_httpd);
|
||||||
if (!evhttpd)
|
if (!evhttpd)
|
||||||
{
|
{
|
||||||
DPRINTF(E_FATAL, L_HTTPD, "Could not create HTTP server\n");
|
DPRINTF(E_FATAL, L_HTTPD, "Could not create HTTP server\n");
|
||||||
|
|
||||||
goto evhttp_fail;
|
goto event_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg_getbool(cfg_getsec(cfg, "general"), "ipv6"))
|
if (cfg_getbool(cfg_getsec(cfg, "general"), "ipv6"))
|
||||||
@@ -1389,7 +1391,7 @@ httpd_init(void)
|
|||||||
thread_fail:
|
thread_fail:
|
||||||
bind_fail:
|
bind_fail:
|
||||||
evhttp_free(evhttpd);
|
evhttp_free(evhttpd);
|
||||||
evhttp_fail:
|
event_fail:
|
||||||
#ifdef USE_EVENTFD
|
#ifdef USE_EVENTFD
|
||||||
close(exit_efd);
|
close(exit_efd);
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -2,12 +2,8 @@
|
|||||||
#ifndef __HTTPD_H__
|
#ifndef __HTTPD_H__
|
||||||
#define __HTTPD_H__
|
#define __HTTPD_H__
|
||||||
|
|
||||||
#include <event.h>
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
#include <event2/http.h>
|
#include <event2/http.h>
|
||||||
#else
|
#include <event2/buffer.h>
|
||||||
# include "evhttp/evhttp_compat.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
void
|
||||||
httpd_stream_file(struct evhttp_request *req, int id);
|
httpd_stream_file(struct evhttp_request *req, int id);
|
||||||
|
|||||||
@@ -55,6 +55,7 @@
|
|||||||
#include <event2/event.h>
|
#include <event2/event.h>
|
||||||
#include <event2/buffer.h>
|
#include <event2/buffer.h>
|
||||||
#include <event2/http_struct.h>
|
#include <event2/http_struct.h>
|
||||||
|
#include <event2/keyvalq_struct.h>
|
||||||
|
|
||||||
/* httpd event base, from httpd.c */
|
/* httpd event base, from httpd.c */
|
||||||
extern struct event_base *evbase_httpd;
|
extern struct event_base *evbase_httpd;
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
#include <event2/event.h>
|
#include <event2/event.h>
|
||||||
#include <event2/buffer.h>
|
#include <event2/buffer.h>
|
||||||
|
#include <event2/keyvalq_struct.h>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
@@ -277,7 +278,7 @@ make_playstatusupdate(struct evbuffer *evbuf)
|
|||||||
dmap_add_char(psu, "casu", 1); /* 9 */ /* unknown */
|
dmap_add_char(psu, "casu", 1); /* 9 */ /* unknown */
|
||||||
dmap_add_char(psu, "ceQu", 0); /* 9 */ /* unknown */
|
dmap_add_char(psu, "ceQu", 0); /* 9 */ /* unknown */
|
||||||
|
|
||||||
dmap_add_container(evbuf, "cmst", EVBUFFER_LENGTH(psu)); /* 8 + len */
|
dmap_add_container(evbuf, "cmst", evbuffer_get_length(psu)); /* 8 + len */
|
||||||
|
|
||||||
ret = evbuffer_add_buffer(evbuf, psu);
|
ret = evbuffer_add_buffer(evbuf, psu);
|
||||||
evbuffer_free(psu);
|
evbuffer_free(psu);
|
||||||
@@ -298,6 +299,8 @@ playstatusupdate_cb(int fd, short what, void *arg)
|
|||||||
struct evbuffer *evbuf;
|
struct evbuffer *evbuf;
|
||||||
struct evbuffer *update;
|
struct evbuffer *update;
|
||||||
struct evhttp_connection *evcon;
|
struct evhttp_connection *evcon;
|
||||||
|
uint8_t *buf;
|
||||||
|
size_t len;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#ifdef USE_EVENTFD
|
#ifdef USE_EVENTFD
|
||||||
@@ -339,6 +342,8 @@ playstatusupdate_cb(int fd, short what, void *arg)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out_free_update;
|
goto out_free_update;
|
||||||
|
|
||||||
|
len = evbuffer_get_length(update);
|
||||||
|
|
||||||
for (ur = update_requests; update_requests; ur = update_requests)
|
for (ur = update_requests; update_requests; ur = update_requests)
|
||||||
{
|
{
|
||||||
update_requests = ur->next;
|
update_requests = ur->next;
|
||||||
@@ -347,9 +352,15 @@ playstatusupdate_cb(int fd, short what, void *arg)
|
|||||||
if (evcon)
|
if (evcon)
|
||||||
evhttp_connection_set_closecb(evcon, NULL, NULL);
|
evhttp_connection_set_closecb(evcon, NULL, NULL);
|
||||||
|
|
||||||
evbuffer_add(evbuf, EVBUFFER_DATA(update), EVBUFFER_LENGTH(update));
|
// Only copy buffer if we actually need to reuse it
|
||||||
|
if (ur->next)
|
||||||
|
{
|
||||||
|
buf = evbuffer_pullup(update, -1);
|
||||||
|
evbuffer_add(evbuf, buf, len);
|
||||||
httpd_send_reply(ur->req, HTTP_OK, "OK", evbuf);
|
httpd_send_reply(ur->req, HTTP_OK, "OK", evbuf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
httpd_send_reply(ur->req, HTTP_OK, "OK", update);
|
||||||
|
|
||||||
free(ur);
|
free(ur);
|
||||||
}
|
}
|
||||||
@@ -1452,7 +1463,7 @@ playqueuecontents_add_source(struct evbuffer *songlist, uint32_t source_id, int
|
|||||||
dmap_add_char(song, "caks", 6); /* Unknown */
|
dmap_add_char(song, "caks", 6); /* Unknown */
|
||||||
dmap_add_int(song, "ceQI", pos_in_queue);
|
dmap_add_int(song, "ceQI", pos_in_queue);
|
||||||
|
|
||||||
dmap_add_container(songlist, "mlit", EVBUFFER_LENGTH(song));
|
dmap_add_container(songlist, "mlit", evbuffer_get_length(song));
|
||||||
|
|
||||||
ret = evbuffer_add_buffer(songlist, song);
|
ret = evbuffer_add_buffer(songlist, song);
|
||||||
evbuffer_free(song);
|
evbuffer_free(song);
|
||||||
@@ -2646,11 +2657,7 @@ dacp_init(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# if defined(__linux__)
|
|
||||||
ret = pipe2(update_pipe, O_CLOEXEC);
|
ret = pipe2(update_pipe, O_CLOEXEC);
|
||||||
# else
|
|
||||||
ret = pipe(update_pipe);
|
|
||||||
# endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DACP, "Could not create update pipe: %s\n", strerror(errno));
|
DPRINTF(E_LOG, L_DACP, "Could not create update pipe: %s\n", strerror(errno));
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include <mxml.h>
|
#include <mxml.h>
|
||||||
|
#include <event2/buffer.h>
|
||||||
|
#include <event2/keyvalq_struct.h>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
|
|||||||
@@ -2,12 +2,7 @@
|
|||||||
#ifndef __HTTPD_RSP_H__
|
#ifndef __HTTPD_RSP_H__
|
||||||
#define __HTTPD_RSP_H__
|
#define __HTTPD_RSP_H__
|
||||||
|
|
||||||
#include <event.h>
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
#include <event2/http.h>
|
#include <event2/http.h>
|
||||||
#else
|
|
||||||
# include "evhttp/evhttp_compat.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int
|
int
|
||||||
rsp_init(void);
|
rsp_init(void);
|
||||||
|
|||||||
10
src/logger.c
10
src/logger.c
@@ -29,7 +29,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <event.h>
|
#include <event2/event.h>
|
||||||
|
|
||||||
#include <libavutil/log.h>
|
#include <libavutil/log.h>
|
||||||
|
|
||||||
@@ -160,19 +160,19 @@ logger_libevent(int severity, const char *msg)
|
|||||||
{
|
{
|
||||||
switch (severity)
|
switch (severity)
|
||||||
{
|
{
|
||||||
case _EVENT_LOG_DEBUG:
|
case EVENT_LOG_DEBUG:
|
||||||
severity = E_DBG;
|
severity = E_DBG;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _EVENT_LOG_ERR:
|
case EVENT_LOG_ERR:
|
||||||
severity = E_LOG;
|
severity = E_LOG;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _EVENT_LOG_WARN:
|
case EVENT_LOG_WARN:
|
||||||
severity = E_WARN;
|
severity = E_WARN;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _EVENT_LOG_MSG:
|
case EVENT_LOG_MSG:
|
||||||
severity = E_INFO;
|
severity = E_INFO;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
30
src/main.c
30
src/main.c
@@ -47,7 +47,7 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <event.h>
|
#include <event2/event.h>
|
||||||
#include <libavutil/log.h>
|
#include <libavutil/log.h>
|
||||||
#include <libavformat/avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
#include <libavfilter/avfilter.h>
|
#include <libavfilter/avfilter.h>
|
||||||
@@ -79,14 +79,14 @@ GCRY_THREAD_OPTION_PTHREAD_IMPL;
|
|||||||
|
|
||||||
struct event_base *evbase_main;
|
struct event_base *evbase_main;
|
||||||
|
|
||||||
static struct event sig_event;
|
static struct event *sig_event;
|
||||||
static int main_exit;
|
static int main_exit;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
version(void)
|
version(void)
|
||||||
{
|
{
|
||||||
fprintf(stdout, "Forked Media Server: Version %s\n", VERSION);
|
fprintf(stdout, "Forked Media Server: Version %s\n", VERSION);
|
||||||
fprintf(stdout, "Copyright (C) 2009-2011 Julien BLACHE <jb@jblache.org>\n");
|
fprintf(stdout, "Copyright (C) 2009-2015 Julien BLACHE <jb@jblache.org>\n");
|
||||||
fprintf(stdout, "Based on mt-daapd, Copyright (C) 2003-2007 Ron Pedde <ron@pedde.com>\n");
|
fprintf(stdout, "Based on mt-daapd, Copyright (C) 2003-2007 Ron Pedde <ron@pedde.com>\n");
|
||||||
fprintf(stdout, "Released under the GNU General Public License version 2 or later\n");
|
fprintf(stdout, "Released under the GNU General Public License version 2 or later\n");
|
||||||
}
|
}
|
||||||
@@ -359,7 +359,7 @@ signal_signalfd_cb(int fd, short event, void *arg)
|
|||||||
if (main_exit)
|
if (main_exit)
|
||||||
event_base_loopbreak(evbase_main);
|
event_base_loopbreak(evbase_main);
|
||||||
else
|
else
|
||||||
event_add(&sig_event, NULL);
|
event_add(sig_event, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||||
@@ -404,7 +404,7 @@ signal_kqueue_cb(int fd, short event, void *arg)
|
|||||||
if (main_exit)
|
if (main_exit)
|
||||||
event_base_loopbreak(evbase_main);
|
event_base_loopbreak(evbase_main);
|
||||||
else
|
else
|
||||||
event_add(&sig_event, NULL);
|
event_add(sig_event, NULL);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -644,8 +644,8 @@ main(int argc, char **argv)
|
|||||||
goto daemon_fail;
|
goto daemon_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize libevent (after forking) */
|
/* Initialize event base (after forking) */
|
||||||
evbase_main = event_init();
|
evbase_main = event_base_new();
|
||||||
|
|
||||||
DPRINTF(E_LOG, L_MAIN, "mDNS init\n");
|
DPRINTF(E_LOG, L_MAIN, "mDNS init\n");
|
||||||
ret = mdns_init();
|
ret = mdns_init();
|
||||||
@@ -778,8 +778,7 @@ main(int argc, char **argv)
|
|||||||
goto signalfd_fail;
|
goto signalfd_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_set(&sig_event, sigfd, EV_READ, signal_signalfd_cb, NULL);
|
sig_event = event_new(evbase_main, sigfd, EV_READ, signal_signalfd_cb, NULL);
|
||||||
|
|
||||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||||
sigfd = kqueue();
|
sigfd = kqueue();
|
||||||
if (sigfd < 0)
|
if (sigfd < 0)
|
||||||
@@ -804,11 +803,17 @@ main(int argc, char **argv)
|
|||||||
goto signalfd_fail;
|
goto signalfd_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_set(&sig_event, sigfd, EV_READ, signal_kqueue_cb, NULL);
|
sig_event = event_new(evbase_main, sigfd, EV_READ, signal_kqueue_cb, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
if (!sig_event)
|
||||||
|
{
|
||||||
|
DPRINTF(E_FATAL, L_MAIN, "Could not create signal event\n");
|
||||||
|
|
||||||
event_base_set(evbase_main, &sig_event);
|
ret = EXIT_FAILURE;
|
||||||
event_add(&sig_event, NULL);
|
goto sig_event_fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
event_add(sig_event, NULL);
|
||||||
|
|
||||||
/* Run the loop */
|
/* Run the loop */
|
||||||
event_base_dispatch(evbase_main);
|
event_base_dispatch(evbase_main);
|
||||||
@@ -823,6 +828,7 @@ main(int argc, char **argv)
|
|||||||
DPRINTF(E_LOG, L_MAIN, "mDNS deinit\n");
|
DPRINTF(E_LOG, L_MAIN, "mDNS deinit\n");
|
||||||
mdns_deinit();
|
mdns_deinit();
|
||||||
|
|
||||||
|
sig_event_fail:
|
||||||
signalfd_fail:
|
signalfd_fail:
|
||||||
mdns_reg_fail:
|
mdns_reg_fail:
|
||||||
DPRINTF(E_LOG, L_MAIN, "Remote pairing deinit\n");
|
DPRINTF(E_LOG, L_MAIN, "Remote pairing deinit\n");
|
||||||
|
|||||||
@@ -34,11 +34,7 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
#include <event2/event.h>
|
#include <event2/event.h>
|
||||||
#else
|
|
||||||
# include <event.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <avahi-common/watch.h>
|
#include <avahi-common/watch.h>
|
||||||
#include <avahi-common/malloc.h>
|
#include <avahi-common/malloc.h>
|
||||||
@@ -125,7 +121,6 @@ _ev_watch_add(AvahiWatch *w, int fd, AvahiWatchEvent a_events)
|
|||||||
if (a_events & AVAHI_WATCH_OUT)
|
if (a_events & AVAHI_WATCH_OUT)
|
||||||
ev_events |= EV_WRITE;
|
ev_events |= EV_WRITE;
|
||||||
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
if (w->ev)
|
if (w->ev)
|
||||||
event_free(w->ev);
|
event_free(w->ev);
|
||||||
|
|
||||||
@@ -135,20 +130,6 @@ _ev_watch_add(AvahiWatch *w, int fd, AvahiWatchEvent a_events)
|
|||||||
DPRINTF(E_LOG, L_MDNS, "Could not make new event in _ev_watch_add\n");
|
DPRINTF(E_LOG, L_MDNS, "Could not make new event in _ev_watch_add\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if (w->ev)
|
|
||||||
free(w->ev);
|
|
||||||
|
|
||||||
w->ev = (struct event *)malloc(sizeof(struct event));
|
|
||||||
if (!w->ev)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_MDNS, "Out of memory in _ev_watch_add\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
event_set(w->ev, fd, ev_events, evcb_watch, w);
|
|
||||||
event_base_set(evbase_main, w->ev);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return event_add(w->ev, NULL);
|
return event_add(w->ev, NULL);
|
||||||
}
|
}
|
||||||
@@ -187,11 +168,7 @@ ev_watch_update(AvahiWatch *w, AvahiWatchEvent a_events)
|
|||||||
if (w->ev)
|
if (w->ev)
|
||||||
event_del(w->ev);
|
event_del(w->ev);
|
||||||
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
_ev_watch_add(w, (int)event_get_fd(w->ev), a_events);
|
_ev_watch_add(w, (int)event_get_fd(w->ev), a_events);
|
||||||
#else
|
|
||||||
_ev_watch_add(w, EVENT_FD(w->ev), a_events);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static AvahiWatchEvent
|
static AvahiWatchEvent
|
||||||
@@ -217,12 +194,7 @@ ev_watch_free(AvahiWatch *w)
|
|||||||
|
|
||||||
if (w->ev)
|
if (w->ev)
|
||||||
{
|
{
|
||||||
event_del(w->ev);
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
event_free(w->ev);
|
event_free(w->ev);
|
||||||
#else
|
|
||||||
free(w->ev);
|
|
||||||
#endif
|
|
||||||
w->ev = NULL;
|
w->ev = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,7 +223,6 @@ _ev_timeout_add(AvahiTimeout *t, const struct timeval *tv)
|
|||||||
struct timeval now;
|
struct timeval now;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
if (t->ev)
|
if (t->ev)
|
||||||
event_free(t->ev);
|
event_free(t->ev);
|
||||||
|
|
||||||
@@ -261,20 +232,6 @@ _ev_timeout_add(AvahiTimeout *t, const struct timeval *tv)
|
|||||||
DPRINTF(E_LOG, L_MDNS, "Could not make event in _ev_timeout_add - out of memory?\n");
|
DPRINTF(E_LOG, L_MDNS, "Could not make event in _ev_timeout_add - out of memory?\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if (t->ev)
|
|
||||||
free(t->ev);
|
|
||||||
|
|
||||||
t->ev = (struct event *)malloc(sizeof(struct event));
|
|
||||||
if (!t->ev)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_MDNS, "Out of memory in _ev_timeout_add\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
evtimer_set(t->ev, evcb_timeout, t);
|
|
||||||
event_base_set(evbase_main, t->ev);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ((tv->tv_sec == 0) && (tv->tv_usec == 0))
|
if ((tv->tv_sec == 0) && (tv->tv_usec == 0))
|
||||||
{
|
{
|
||||||
@@ -342,12 +299,7 @@ ev_timeout_free(AvahiTimeout *t)
|
|||||||
|
|
||||||
if (t->ev)
|
if (t->ev)
|
||||||
{
|
{
|
||||||
event_del(t->ev);
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
event_free(t->ev);
|
event_free(t->ev);
|
||||||
#else
|
|
||||||
free(t->ev);
|
|
||||||
#endif
|
|
||||||
t->ev = NULL;
|
t->ev = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1028,24 +980,14 @@ mdns_deinit(void)
|
|||||||
for (t = all_t; t; t = t->next)
|
for (t = all_t; t; t = t->next)
|
||||||
if (t->ev)
|
if (t->ev)
|
||||||
{
|
{
|
||||||
event_del(t->ev);
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
event_free(t->ev);
|
event_free(t->ev);
|
||||||
#else
|
|
||||||
free(t->ev);
|
|
||||||
#endif
|
|
||||||
t->ev = NULL;
|
t->ev = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (w = all_w; w; w = w->next)
|
for (w = all_w; w; w = w->next)
|
||||||
if (w->ev)
|
if (w->ev)
|
||||||
{
|
{
|
||||||
event_del(w->ev);
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
event_free(w->ev);
|
event_free(w->ev);
|
||||||
#else
|
|
||||||
free(w->ev);
|
|
||||||
#endif
|
|
||||||
w->ev = NULL;
|
w->ev = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4463,22 +4463,14 @@ int mpd_init(void)
|
|||||||
|
|
||||||
v6enabled = cfg_getbool(cfg_getsec(cfg, "general"), "ipv6");
|
v6enabled = cfg_getbool(cfg_getsec(cfg, "general"), "ipv6");
|
||||||
|
|
||||||
# if defined(__linux__)
|
|
||||||
ret = pipe2(g_exit_pipe, O_CLOEXEC);
|
ret = pipe2(g_exit_pipe, O_CLOEXEC);
|
||||||
# else
|
|
||||||
ret = pipe(g_exit_pipe);
|
|
||||||
# endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_MPD, "Could not create pipe: %s\n", strerror(errno));
|
DPRINTF(E_LOG, L_MPD, "Could not create pipe: %s\n", strerror(errno));
|
||||||
goto exit_fail;
|
goto exit_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
# if defined(__linux__)
|
|
||||||
ret = pipe2(g_cmd_pipe, O_CLOEXEC);
|
ret = pipe2(g_cmd_pipe, O_CLOEXEC);
|
||||||
# else
|
|
||||||
ret = pipe(g_cmd_pipe);
|
|
||||||
# endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_MPD, "Could not create command pipe: %s\n", strerror(errno));
|
DPRINTF(E_LOG, L_MPD, "Could not create command pipe: %s\n", strerror(errno));
|
||||||
|
|||||||
@@ -2,12 +2,8 @@
|
|||||||
#ifndef __PIPE_H__
|
#ifndef __PIPE_H__
|
||||||
#define __PIPE_H__
|
#define __PIPE_H__
|
||||||
|
|
||||||
#include "db.h"
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
#include <event2/buffer.h>
|
#include <event2/buffer.h>
|
||||||
#else
|
#include "db.h"
|
||||||
# include <event.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int
|
int
|
||||||
pipe_setup(struct media_file_info *mfi);
|
pipe_setup(struct media_file_info *mfi);
|
||||||
|
|||||||
46
src/player.c
46
src/player.c
@@ -37,13 +37,8 @@
|
|||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
#include <event2/event.h>
|
#include <event2/event.h>
|
||||||
#include <event2/buffer.h>
|
#include <event2/buffer.h>
|
||||||
#else
|
|
||||||
# include <event.h>
|
|
||||||
# define evbuffer_get_length(x) (x)->off
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <gcrypt.h>
|
#include <gcrypt.h>
|
||||||
|
|
||||||
@@ -4716,11 +4711,7 @@ player_init(void)
|
|||||||
|
|
||||||
raop_v6enabled = cfg_getbool(cfg_getsec(cfg, "general"), "ipv6");
|
raop_v6enabled = cfg_getbool(cfg_getsec(cfg, "general"), "ipv6");
|
||||||
|
|
||||||
#if defined(__linux__)
|
|
||||||
ret = pipe2(exit_pipe, O_CLOEXEC);
|
ret = pipe2(exit_pipe, O_CLOEXEC);
|
||||||
#else
|
|
||||||
ret = pipe(exit_pipe);
|
|
||||||
#endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_PLAYER, "Could not create pipe: %s\n", strerror(errno));
|
DPRINTF(E_LOG, L_PLAYER, "Could not create pipe: %s\n", strerror(errno));
|
||||||
@@ -4728,11 +4719,7 @@ player_init(void)
|
|||||||
goto exit_fail;
|
goto exit_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
# if defined(__linux__)
|
|
||||||
ret = pipe2(cmd_pipe, O_CLOEXEC);
|
ret = pipe2(cmd_pipe, O_CLOEXEC);
|
||||||
# else
|
|
||||||
ret = pipe(cmd_pipe);
|
|
||||||
# endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_PLAYER, "Could not create command pipe: %s\n", strerror(errno));
|
DPRINTF(E_LOG, L_PLAYER, "Could not create command pipe: %s\n", strerror(errno));
|
||||||
@@ -4748,7 +4735,6 @@ player_init(void)
|
|||||||
goto evbase_fail;
|
goto evbase_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
exitev = event_new(evbase_player, exit_pipe[0], EV_READ, exit_cb, NULL);
|
exitev = event_new(evbase_player, exit_pipe[0], EV_READ, exit_cb, NULL);
|
||||||
if (!exitev)
|
if (!exitev)
|
||||||
{
|
{
|
||||||
@@ -4773,38 +4759,6 @@ player_init(void)
|
|||||||
DPRINTF(E_LOG, L_PLAYER, "Could not create playback timer event\n");
|
DPRINTF(E_LOG, L_PLAYER, "Could not create playback timer event\n");
|
||||||
goto evnew_fail;
|
goto evnew_fail;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
exitev = (struct event *)malloc(sizeof(struct event));
|
|
||||||
if (!exitev)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_PLAYER, "Could not create exit event\n");
|
|
||||||
goto evnew_fail;
|
|
||||||
}
|
|
||||||
event_set(exitev, exit_pipe[0], EV_READ, exit_cb, NULL);
|
|
||||||
event_base_set(evbase_player, exitev);
|
|
||||||
|
|
||||||
cmdev = (struct event *)malloc(sizeof(struct event));
|
|
||||||
if (!cmdev)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_PLAYER, "Could not create cmd event\n");
|
|
||||||
goto evnew_fail;
|
|
||||||
}
|
|
||||||
event_set(cmdev, cmd_pipe[0], EV_READ, command_cb, NULL);
|
|
||||||
event_base_set(evbase_player, cmdev);
|
|
||||||
|
|
||||||
pb_timer_ev = (struct event *)malloc(sizeof(struct event));
|
|
||||||
if (!pb_timer_ev)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_PLAYER, "Could not create playback timer event\n");
|
|
||||||
goto evnew_fail;
|
|
||||||
}
|
|
||||||
# if defined(__linux__)
|
|
||||||
event_set(pb_timer_ev, pb_timer_fd, EV_READ, player_playback_cb, NULL);
|
|
||||||
# else
|
|
||||||
signal_set(pb_timer_ev, SIGALRM, player_playback_cb, NULL);
|
|
||||||
# endif
|
|
||||||
event_base_set(evbase_player, pb_timer_ev);
|
|
||||||
#endif /* HAVE_LIBEVENT2 */
|
|
||||||
|
|
||||||
event_add(exitev, NULL);
|
event_add(exitev, NULL);
|
||||||
event_add(cmdev, NULL);
|
event_add(cmdev, NULL);
|
||||||
|
|||||||
133
src/raop.c
133
src/raop.c
@@ -57,11 +57,11 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
|
|
||||||
#include <event.h>
|
#include <event2/event.h>
|
||||||
#include "evrtsp/evrtsp.h"
|
#include <event2/buffer.h>
|
||||||
|
|
||||||
#include <gcrypt.h>
|
#include <gcrypt.h>
|
||||||
|
|
||||||
|
#include "evrtsp/evrtsp.h"
|
||||||
#include "conffile.h"
|
#include "conffile.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
@@ -109,6 +109,8 @@ struct raop_session
|
|||||||
unsigned auth_quirk_itunes:1;
|
unsigned auth_quirk_itunes:1;
|
||||||
unsigned wants_metadata:1;
|
unsigned wants_metadata:1;
|
||||||
|
|
||||||
|
struct event *deferredev;
|
||||||
|
|
||||||
int reqs_in_flight;
|
int reqs_in_flight;
|
||||||
int cseq;
|
int cseq;
|
||||||
char *session;
|
char *session;
|
||||||
@@ -161,13 +163,7 @@ struct raop_service
|
|||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
struct event ev;
|
struct event *ev;
|
||||||
};
|
|
||||||
|
|
||||||
struct raop_deferred_eh
|
|
||||||
{
|
|
||||||
struct event ev;
|
|
||||||
struct raop_session *session;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*evrtsp_req_cb)(struct evrtsp_request *req, void *arg);
|
typedef void (*evrtsp_req_cb)(struct evrtsp_request *req, void *arg);
|
||||||
@@ -242,7 +238,7 @@ static struct raop_metadata *metadata_head;
|
|||||||
static struct raop_metadata *metadata_tail;
|
static struct raop_metadata *metadata_tail;
|
||||||
|
|
||||||
/* FLUSH timer */
|
/* FLUSH timer */
|
||||||
static struct event flush_timer;
|
static struct event *flush_timer;
|
||||||
|
|
||||||
/* Sessions */
|
/* Sessions */
|
||||||
static struct raop_session *sessions;
|
static struct raop_session *sessions;
|
||||||
@@ -1639,6 +1635,8 @@ raop_session_free(struct raop_session *rs)
|
|||||||
|
|
||||||
evrtsp_connection_free(rs->ctrl);
|
evrtsp_connection_free(rs->ctrl);
|
||||||
|
|
||||||
|
event_free(rs->deferredev);
|
||||||
|
|
||||||
close(rs->server_fd);
|
close(rs->server_fd);
|
||||||
|
|
||||||
if (rs->realm)
|
if (rs->realm)
|
||||||
@@ -1708,16 +1706,11 @@ raop_session_failure(struct raop_session *rs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
raop_deferred_eh_cb(int fd, short what, void *arg)
|
raop_deferredev_cb(int fd, short what, void *arg)
|
||||||
{
|
{
|
||||||
struct raop_deferred_eh *deh;
|
|
||||||
struct raop_session *rs;
|
struct raop_session *rs;
|
||||||
|
|
||||||
deh = (struct raop_deferred_eh *)arg;
|
rs = (struct raop_session *)arg;
|
||||||
|
|
||||||
rs = deh->session;
|
|
||||||
|
|
||||||
free(deh);
|
|
||||||
|
|
||||||
DPRINTF(E_DBG, L_RAOP, "Cleaning up failed session (deferred) on device %s\n", rs->devname);
|
DPRINTF(E_DBG, L_RAOP, "Cleaning up failed session (deferred) on device %s\n", rs->devname);
|
||||||
|
|
||||||
@@ -1728,7 +1721,6 @@ static void
|
|||||||
raop_rtsp_close_cb(struct evrtsp_connection *evcon, void *arg)
|
raop_rtsp_close_cb(struct evrtsp_connection *evcon, void *arg)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
struct raop_deferred_eh *deh;
|
|
||||||
struct raop_session *rs;
|
struct raop_session *rs;
|
||||||
|
|
||||||
rs = (struct raop_session *)arg;
|
rs = (struct raop_session *)arg;
|
||||||
@@ -1737,20 +1729,8 @@ raop_rtsp_close_cb(struct evrtsp_connection *evcon, void *arg)
|
|||||||
|
|
||||||
rs->state = RAOP_FAILED;
|
rs->state = RAOP_FAILED;
|
||||||
|
|
||||||
deh = (struct raop_deferred_eh *)malloc(sizeof(struct raop_deferred_eh));
|
|
||||||
if (!deh)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_RAOP, "Out of memory for deferred error handling!\n");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
deh->session = rs;
|
|
||||||
|
|
||||||
evtimer_set(&deh->ev, raop_deferred_eh_cb, deh);
|
|
||||||
event_base_set(evbase_player, &deh->ev);
|
|
||||||
evutil_timerclear(&tv);
|
evutil_timerclear(&tv);
|
||||||
evtimer_add(&deh->ev, &tv);
|
evtimer_add(rs->deferredev, &tv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct raop_session *
|
static struct raop_session *
|
||||||
@@ -1833,12 +1813,20 @@ raop_session_make(struct raop_device *rd, int family, raop_status_cb cb)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rs->deferredev = evtimer_new(evbase_player, raop_deferredev_cb, rs);
|
||||||
|
if (!rs->deferredev)
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_RAOP, "Out of memory for deferred error handling!\n");
|
||||||
|
|
||||||
|
goto out_free_rs;
|
||||||
|
}
|
||||||
|
|
||||||
rs->ctrl = evrtsp_connection_new(address, port);
|
rs->ctrl = evrtsp_connection_new(address, port);
|
||||||
if (!rs->ctrl)
|
if (!rs->ctrl)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_RAOP, "Could not create control connection to %s\n", address);
|
DPRINTF(E_LOG, L_RAOP, "Could not create control connection to %s\n", address);
|
||||||
|
|
||||||
goto out_free_rs;
|
goto out_free_event;
|
||||||
}
|
}
|
||||||
|
|
||||||
evrtsp_connection_set_base(rs->ctrl, evbase_player);
|
evrtsp_connection_set_base(rs->ctrl, evbase_player);
|
||||||
@@ -1905,6 +1893,8 @@ raop_session_make(struct raop_device *rd, int family, raop_status_cb cb)
|
|||||||
|
|
||||||
out_free_evcon:
|
out_free_evcon:
|
||||||
evrtsp_connection_free(rs->ctrl);
|
evrtsp_connection_free(rs->ctrl);
|
||||||
|
out_free_event:
|
||||||
|
event_free(rs->deferredev);
|
||||||
out_free_rs:
|
out_free_rs:
|
||||||
free(rs);
|
free(rs);
|
||||||
|
|
||||||
@@ -1999,6 +1989,8 @@ static int
|
|||||||
raop_metadata_send_artwork(struct raop_session *rs, struct evbuffer *evbuf, struct raop_metadata *rmd, char *rtptime)
|
raop_metadata_send_artwork(struct raop_session *rs, struct evbuffer *evbuf, struct raop_metadata *rmd, char *rtptime)
|
||||||
{
|
{
|
||||||
char *ctype;
|
char *ctype;
|
||||||
|
uint8_t *buf;
|
||||||
|
size_t len;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
switch (rmd->artwork_fmt)
|
switch (rmd->artwork_fmt)
|
||||||
@@ -2017,7 +2009,10 @@ raop_metadata_send_artwork(struct raop_session *rs, struct evbuffer *evbuf, stru
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = evbuffer_add(evbuf, EVBUFFER_DATA(rmd->artwork), EVBUFFER_LENGTH(rmd->artwork));
|
buf = evbuffer_pullup(rmd->artwork, -1);
|
||||||
|
len = evbuffer_get_length(rmd->artwork);
|
||||||
|
|
||||||
|
ret = evbuffer_add(evbuf, buf, len);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_RAOP, "Could not copy artwork for sending\n");
|
DPRINTF(E_LOG, L_RAOP, "Could not copy artwork for sending\n");
|
||||||
@@ -2035,9 +2030,14 @@ raop_metadata_send_artwork(struct raop_session *rs, struct evbuffer *evbuf, stru
|
|||||||
static int
|
static int
|
||||||
raop_metadata_send_metadata(struct raop_session *rs, struct evbuffer *evbuf, struct raop_metadata *rmd, char *rtptime)
|
raop_metadata_send_metadata(struct raop_session *rs, struct evbuffer *evbuf, struct raop_metadata *rmd, char *rtptime)
|
||||||
{
|
{
|
||||||
|
uint8_t *buf;
|
||||||
|
size_t len;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = evbuffer_add(evbuf, EVBUFFER_DATA(rmd->metadata), EVBUFFER_LENGTH(rmd->metadata));
|
buf = evbuffer_pullup(rmd->metadata, -1);
|
||||||
|
len = evbuffer_get_length(rmd->metadata);
|
||||||
|
|
||||||
|
ret = evbuffer_add(evbuf, buf, len);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_RAOP, "Could not copy metadata for sending\n");
|
DPRINTF(E_LOG, L_RAOP, "Could not copy metadata for sending\n");
|
||||||
@@ -2412,11 +2412,9 @@ raop_flush(raop_status_cb cb, uint64_t rtptime)
|
|||||||
|
|
||||||
if (pending > 0)
|
if (pending > 0)
|
||||||
{
|
{
|
||||||
evtimer_set(&flush_timer, raop_flush_timer_cb, NULL);
|
|
||||||
event_base_set(evbase_player, &flush_timer);
|
|
||||||
evutil_timerclear(&tv);
|
evutil_timerclear(&tv);
|
||||||
tv.tv_sec = 10;
|
tv.tv_sec = 10;
|
||||||
evtimer_add(&flush_timer, &tv);
|
evtimer_add(flush_timer, &tv);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pending;
|
return pending;
|
||||||
@@ -2565,7 +2563,7 @@ raop_v2_timing_cb(int fd, short what, void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
readd:
|
readd:
|
||||||
ret = event_add(&svc->ev, NULL);
|
ret = event_add(svc->ev, NULL);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_RAOP, "Couldn't re-add event for timing requests\n");
|
DPRINTF(E_LOG, L_RAOP, "Couldn't re-add event for timing requests\n");
|
||||||
@@ -2654,16 +2652,16 @@ raop_v2_timing_start_one(struct raop_service *svc, int family)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_set(&svc->ev, svc->fd, EV_READ, raop_v2_timing_cb, svc);
|
svc->ev = event_new(evbase_player, svc->fd, EV_READ, raop_v2_timing_cb, svc);
|
||||||
event_base_set(evbase_player, &svc->ev);
|
if (!svc->ev)
|
||||||
ret = event_add(&svc->ev, NULL);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_RAOP, "Couldn't add event for timing requests\n");
|
DPRINTF(E_LOG, L_RAOP, "Out of memory for raop_service event\n");
|
||||||
|
|
||||||
goto out_fail;
|
goto out_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event_add(svc->ev, NULL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_fail:
|
out_fail:
|
||||||
@@ -2677,11 +2675,11 @@ raop_v2_timing_start_one(struct raop_service *svc, int family)
|
|||||||
static void
|
static void
|
||||||
raop_v2_timing_stop(void)
|
raop_v2_timing_stop(void)
|
||||||
{
|
{
|
||||||
if (event_initialized(&timing_4svc.ev))
|
if (timing_4svc.ev)
|
||||||
event_del(&timing_4svc.ev);
|
event_free(timing_4svc.ev);
|
||||||
|
|
||||||
if (event_initialized(&timing_6svc.ev))
|
if (timing_6svc.ev)
|
||||||
event_del(&timing_6svc.ev);
|
event_free(timing_6svc.ev);
|
||||||
|
|
||||||
close(timing_4svc.fd);
|
close(timing_4svc.fd);
|
||||||
|
|
||||||
@@ -2897,7 +2895,7 @@ raop_v2_control_cb(int fd, short what, void *arg)
|
|||||||
raop_v2_resend_range(rs, seq_start, seq_len);
|
raop_v2_resend_range(rs, seq_start, seq_len);
|
||||||
|
|
||||||
readd:
|
readd:
|
||||||
ret = event_add(&svc->ev, NULL);
|
ret = event_add(svc->ev, NULL);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_RAOP, "Couldn't re-add event for control requests\n");
|
DPRINTF(E_LOG, L_RAOP, "Couldn't re-add event for control requests\n");
|
||||||
@@ -2986,16 +2984,16 @@ raop_v2_control_start_one(struct raop_service *svc, int family)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_set(&svc->ev, svc->fd, EV_READ, raop_v2_control_cb, svc);
|
svc->ev = event_new(evbase_player, svc->fd, EV_READ, raop_v2_control_cb, svc);
|
||||||
event_base_set(evbase_player, &svc->ev);
|
if (!svc->ev)
|
||||||
ret = event_add(&svc->ev, NULL);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_RAOP, "Couldn't add event for control requests\n");
|
DPRINTF(E_LOG, L_RAOP, "Out of memory for control event\n");
|
||||||
|
|
||||||
goto out_fail;
|
goto out_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event_add(svc->ev, NULL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_fail:
|
out_fail:
|
||||||
@@ -3009,11 +3007,11 @@ raop_v2_control_start_one(struct raop_service *svc, int family)
|
|||||||
static void
|
static void
|
||||||
raop_v2_control_stop(void)
|
raop_v2_control_stop(void)
|
||||||
{
|
{
|
||||||
if (event_initialized(&control_4svc.ev))
|
if (control_4svc.ev)
|
||||||
event_del(&control_4svc.ev);
|
event_free(control_4svc.ev);
|
||||||
|
|
||||||
if (event_initialized(&control_6svc.ev))
|
if (control_6svc.ev)
|
||||||
event_del(&control_6svc.ev);
|
event_free(control_6svc.ev);
|
||||||
|
|
||||||
close(control_4svc.fd);
|
close(control_4svc.fd);
|
||||||
|
|
||||||
@@ -3920,8 +3918,7 @@ raop_playback_start(uint64_t next_pkt, struct timespec *ts)
|
|||||||
{
|
{
|
||||||
struct raop_session *rs;
|
struct raop_session *rs;
|
||||||
|
|
||||||
if (event_initialized(&flush_timer))
|
event_del(flush_timer);
|
||||||
event_del(&flush_timer);
|
|
||||||
|
|
||||||
sync_counter = 0;
|
sync_counter = 0;
|
||||||
|
|
||||||
@@ -4043,12 +4040,20 @@ raop_init(int *v6enabled)
|
|||||||
if (ptr)
|
if (ptr)
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
|
|
||||||
|
flush_timer = evtimer_new(evbase_player, raop_flush_timer_cb, NULL);
|
||||||
|
if (!flush_timer)
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_RAOP, "AirTunes v2 playback synchronization failed to start\n");
|
||||||
|
|
||||||
|
goto out_free_b64_iv;
|
||||||
|
}
|
||||||
|
|
||||||
ret = raop_v2_timing_start(*v6enabled);
|
ret = raop_v2_timing_start(*v6enabled);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_RAOP, "AirTunes v2 time synchronization failed to start\n");
|
DPRINTF(E_LOG, L_RAOP, "AirTunes v2 time synchronization failed to start\n");
|
||||||
|
|
||||||
goto out_free_b64_iv;
|
goto out_free_flush_timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = raop_v2_control_start(*v6enabled);
|
ret = raop_v2_control_start(*v6enabled);
|
||||||
@@ -4066,6 +4071,8 @@ raop_init(int *v6enabled)
|
|||||||
|
|
||||||
out_stop_timing:
|
out_stop_timing:
|
||||||
raop_v2_timing_stop();
|
raop_v2_timing_stop();
|
||||||
|
out_free_flush_timer:
|
||||||
|
event_free(flush_timer);
|
||||||
out_free_b64_iv:
|
out_free_b64_iv:
|
||||||
free(raop_aes_iv_b64);
|
free(raop_aes_iv_b64);
|
||||||
out_free_b64_key:
|
out_free_b64_key:
|
||||||
@@ -4088,8 +4095,10 @@ raop_deinit(void)
|
|||||||
raop_session_free(rs);
|
raop_session_free(rs);
|
||||||
}
|
}
|
||||||
|
|
||||||
raop_v2_timing_stop();
|
|
||||||
raop_v2_control_stop();
|
raop_v2_control_stop();
|
||||||
|
raop_v2_timing_stop();
|
||||||
|
|
||||||
|
event_free(flush_timer);
|
||||||
|
|
||||||
gcry_cipher_close(raop_aes_ctx);
|
gcry_cipher_close(raop_aes_ctx);
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,6 @@
|
|||||||
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|
||||||
#include <event.h>
|
|
||||||
#include "evrtsp/evrtsp.h"
|
|
||||||
|
|
||||||
|
|
||||||
union sockaddr_all
|
union sockaddr_all
|
||||||
{
|
{
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
|
|||||||
@@ -46,12 +46,9 @@
|
|||||||
# include <sys/eventfd.h>
|
# include <sys/eventfd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <event.h>
|
#include <event2/event.h>
|
||||||
#ifdef HAVE_LIBEVENT2
|
#include <event2/buffer.h>
|
||||||
#include <event2/http.h>
|
#include <event2/http.h>
|
||||||
#else
|
|
||||||
# include "evhttp/evhttp_compat.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <gcrypt.h>
|
#include <gcrypt.h>
|
||||||
|
|
||||||
@@ -88,7 +85,7 @@ static int pairing_efd;
|
|||||||
#else
|
#else
|
||||||
static int pairing_pipe[2];
|
static int pairing_pipe[2];
|
||||||
#endif
|
#endif
|
||||||
static struct event pairingev;
|
static struct event *pairingev;
|
||||||
static pthread_mutex_t remote_lck = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t remote_lck = PTHREAD_MUTEX_INITIALIZER;
|
||||||
static struct remote_info *remote_list;
|
static struct remote_info *remote_list;
|
||||||
|
|
||||||
@@ -417,6 +414,7 @@ pairing_request_cb(struct evhttp_request *req, void *arg)
|
|||||||
struct evbuffer *input_buffer;
|
struct evbuffer *input_buffer;
|
||||||
uint8_t *response;
|
uint8_t *response;
|
||||||
char guid[17];
|
char guid[17];
|
||||||
|
int buflen;
|
||||||
int response_code;
|
int response_code;
|
||||||
int len;
|
int len;
|
||||||
int i;
|
int i;
|
||||||
@@ -441,14 +439,15 @@ pairing_request_cb(struct evhttp_request *req, void *arg)
|
|||||||
|
|
||||||
input_buffer = evhttp_request_get_input_buffer(req);
|
input_buffer = evhttp_request_get_input_buffer(req);
|
||||||
|
|
||||||
if (EVBUFFER_LENGTH(input_buffer) < 8)
|
buflen = evbuffer_get_length(input_buffer);
|
||||||
|
if (buflen < 8)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_REMOTE, "Remote %s/%s: pairing response too short\n", ri->pi.remote_id, ri->pi.name);
|
DPRINTF(E_LOG, L_REMOTE, "Remote %s/%s: pairing response too short\n", ri->pi.remote_id, ri->pi.name);
|
||||||
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
response = EVBUFFER_DATA(input_buffer);
|
response = evbuffer_pullup(input_buffer, -1);
|
||||||
|
|
||||||
if ((response[0] != 'c') || (response[1] != 'm') || (response[2] != 'p') || (response[3] != 'a'))
|
if ((response[0] != 'c') || (response[1] != 'm') || (response[2] != 'p') || (response[3] != 'a'))
|
||||||
{
|
{
|
||||||
@@ -458,10 +457,10 @@ pairing_request_cb(struct evhttp_request *req, void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
len = (response[4] << 24) | (response[5] << 16) | (response[6] << 8) | (response[7]);
|
len = (response[4] << 24) | (response[5] << 16) | (response[6] << 8) | (response[7]);
|
||||||
if (EVBUFFER_LENGTH(input_buffer) < 8 + len)
|
if (buflen < 8 + len)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_REMOTE, "Remote %s/%s: pairing response truncated (got %d expected %d)\n",
|
DPRINTF(E_LOG, L_REMOTE, "Remote %s/%s: pairing response truncated (got %d expected %d)\n",
|
||||||
ri->pi.remote_id, ri->pi.name, (int)EVBUFFER_LENGTH(input_buffer), len + 8);
|
ri->pi.remote_id, ri->pi.name, buflen, len + 8);
|
||||||
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@@ -683,7 +682,7 @@ pairing_cb(int fd, short event, void *arg)
|
|||||||
do_pairing(ri);
|
do_pairing(ri);
|
||||||
}
|
}
|
||||||
|
|
||||||
event_add(&pairingev, NULL);
|
event_add(pairingev, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -918,27 +917,13 @@ remote_pairing_init(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# if defined(__linux__)
|
|
||||||
ret = pipe2(pairing_pipe, O_CLOEXEC | O_NONBLOCK);
|
ret = pipe2(pairing_pipe, O_CLOEXEC | O_NONBLOCK);
|
||||||
# else
|
|
||||||
ret = pipe(pairing_pipe);
|
|
||||||
# endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_FATAL, L_REMOTE, "Could not create pairing pipe: %s\n", strerror(errno));
|
DPRINTF(E_FATAL, L_REMOTE, "Could not create pairing pipe: %s\n", strerror(errno));
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
# ifndef __linux__
|
|
||||||
ret = fcntl(pairing_pipe[0], F_SETFL, O_NONBLOCK);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
DPRINTF(E_FATAL, L_REMOTE, "Could not set O_NONBLOCK: %s\n", strerror(errno));
|
|
||||||
|
|
||||||
goto pairing_pipe_fail;
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
#endif /* USE_EVENTFD */
|
#endif /* USE_EVENTFD */
|
||||||
|
|
||||||
ret = mdns_browse("_touch-remote._tcp", MDNS_WANT_V4, touch_remote_cb);
|
ret = mdns_browse("_touch-remote._tcp", MDNS_WANT_V4, touch_remote_cb);
|
||||||
@@ -950,18 +935,22 @@ remote_pairing_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_EVENTFD
|
#ifdef USE_EVENTFD
|
||||||
event_set(&pairingev, pairing_efd, EV_READ, pairing_cb, NULL);
|
pairingev = event_new(evbase_main, pairing_efd, EV_READ, pairing_cb, NULL);
|
||||||
#else
|
#else
|
||||||
event_set(&pairingev, pairing_pipe[0], EV_READ, pairing_cb, NULL);
|
pairingev = event_new(evbase_main, pairing_pipe[0], EV_READ, pairing_cb, NULL);
|
||||||
#endif
|
#endif
|
||||||
event_base_set(evbase_main, &pairingev);
|
if (!pairingev)
|
||||||
event_add(&pairingev, NULL);
|
{
|
||||||
|
DPRINTF(E_FATAL, L_REMOTE, "Out of memory for pairing event\n");
|
||||||
|
|
||||||
|
goto pairingev_fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
event_add(pairingev, NULL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#ifndef __linux__
|
pairingev_fail:
|
||||||
pairing_pipe_fail:
|
|
||||||
#endif
|
|
||||||
mdns_browse_fail:
|
mdns_browse_fail:
|
||||||
#ifdef USE_EVENTFD
|
#ifdef USE_EVENTFD
|
||||||
close(pairing_efd);
|
close(pairing_efd);
|
||||||
|
|||||||
@@ -2004,33 +2004,21 @@ spotify_init(void)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto assign_fail;
|
goto assign_fail;
|
||||||
|
|
||||||
# if defined(__linux__)
|
|
||||||
ret = pipe2(g_exit_pipe, O_CLOEXEC);
|
ret = pipe2(g_exit_pipe, O_CLOEXEC);
|
||||||
# else
|
|
||||||
ret = pipe(g_exit_pipe);
|
|
||||||
# endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SPOTIFY, "Could not create pipe: %s\n", strerror(errno));
|
DPRINTF(E_LOG, L_SPOTIFY, "Could not create pipe: %s\n", strerror(errno));
|
||||||
goto exit_fail;
|
goto exit_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
# if defined(__linux__)
|
|
||||||
ret = pipe2(g_cmd_pipe, O_CLOEXEC);
|
ret = pipe2(g_cmd_pipe, O_CLOEXEC);
|
||||||
# else
|
|
||||||
ret = pipe(g_cmd_pipe);
|
|
||||||
# endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SPOTIFY, "Could not create command pipe: %s\n", strerror(errno));
|
DPRINTF(E_LOG, L_SPOTIFY, "Could not create command pipe: %s\n", strerror(errno));
|
||||||
goto cmd_fail;
|
goto cmd_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
# if defined(__linux__)
|
|
||||||
ret = pipe2(g_notify_pipe, O_CLOEXEC);
|
ret = pipe2(g_notify_pipe, O_CLOEXEC);
|
||||||
# else
|
|
||||||
ret = pipe(g_notify_pipe);
|
|
||||||
# endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SPOTIFY, "Could not notify command pipe: %s\n", strerror(errno));
|
DPRINTF(E_LOG, L_SPOTIFY, "Could not notify command pipe: %s\n", strerror(errno));
|
||||||
@@ -2044,7 +2032,6 @@ spotify_init(void)
|
|||||||
goto evbase_fail;
|
goto evbase_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
g_exitev = event_new(evbase_spotify, g_exit_pipe[0], EV_READ, exit_cb, NULL);
|
g_exitev = event_new(evbase_spotify, g_exit_pipe[0], EV_READ, exit_cb, NULL);
|
||||||
if (!g_exitev)
|
if (!g_exitev)
|
||||||
{
|
{
|
||||||
@@ -2065,34 +2052,6 @@ spotify_init(void)
|
|||||||
DPRINTF(E_LOG, L_SPOTIFY, "Could not create notify event\n");
|
DPRINTF(E_LOG, L_SPOTIFY, "Could not create notify event\n");
|
||||||
goto evnew_fail;
|
goto evnew_fail;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
g_exitev = (struct event *)malloc(sizeof(struct event));
|
|
||||||
if (!g_exitev)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_SPOTIFY, "Could not create exit event\n");
|
|
||||||
goto evnew_fail;
|
|
||||||
}
|
|
||||||
event_set(g_exitev, g_exit_pipe[0], EV_READ, exit_cb, NULL);
|
|
||||||
event_base_set(evbase_spotify, g_exitev);
|
|
||||||
|
|
||||||
g_cmdev = (struct event *)malloc(sizeof(struct event));
|
|
||||||
if (!g_cmdev)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_SPOTIFY, "Could not create cmd event\n");
|
|
||||||
goto evnew_fail;
|
|
||||||
}
|
|
||||||
event_set(g_cmdev, g_cmd_pipe[0], EV_READ, command_cb, NULL);
|
|
||||||
event_base_set(evbase_spotify, g_cmdev);
|
|
||||||
|
|
||||||
g_notifyev = (struct event *)malloc(sizeof(struct event));
|
|
||||||
if (!g_notifyev)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_SPOTIFY, "Could not create notify event\n");
|
|
||||||
goto evnew_fail;
|
|
||||||
}
|
|
||||||
event_set(g_notifyev, g_notify_pipe[0], EV_READ | EV_TIMEOUT, notify_cb, NULL);
|
|
||||||
event_base_set(evbase_spotify, g_notifyev);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
event_add(g_exitev, NULL);
|
event_add(g_exitev, NULL);
|
||||||
event_add(g_cmdev, NULL);
|
event_add(g_cmdev, NULL);
|
||||||
|
|||||||
@@ -3,12 +3,8 @@
|
|||||||
#define __SPOTIFY_H__
|
#define __SPOTIFY_H__
|
||||||
|
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
#ifdef HAVE_LIBEVENT2
|
|
||||||
#include <event2/event.h>
|
#include <event2/event.h>
|
||||||
#include <event2/buffer.h>
|
#include <event2/buffer.h>
|
||||||
#else
|
|
||||||
# include <event.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int
|
int
|
||||||
spotify_playback_setup(struct media_file_info *mfi);
|
spotify_playback_setup(struct media_file_info *mfi);
|
||||||
|
|||||||
@@ -286,22 +286,14 @@ worker_init(void)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
# if defined(__linux__)
|
|
||||||
ret = pipe2(g_exit_pipe, O_CLOEXEC);
|
ret = pipe2(g_exit_pipe, O_CLOEXEC);
|
||||||
# else
|
|
||||||
ret = pipe(g_exit_pipe);
|
|
||||||
# endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_MAIN, "Could not create pipe: %s\n", strerror(errno));
|
DPRINTF(E_LOG, L_MAIN, "Could not create pipe: %s\n", strerror(errno));
|
||||||
goto exit_fail;
|
goto exit_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
# if defined(__linux__)
|
|
||||||
ret = pipe2(g_cmd_pipe, O_CLOEXEC);
|
ret = pipe2(g_cmd_pipe, O_CLOEXEC);
|
||||||
# else
|
|
||||||
ret = pipe(g_cmd_pipe);
|
|
||||||
# endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_MAIN, "Could not create command pipe: %s\n", strerror(errno));
|
DPRINTF(E_LOG, L_MAIN, "Could not create command pipe: %s\n", strerror(errno));
|
||||||
|
|||||||
Reference in New Issue
Block a user