Merge pull request #123 from chme/mpdprotocol

[mpd] add IPv6 support and a little cleanup in db upgrade v16
This commit is contained in:
ejurgensen 2015-03-20 23:47:34 +01:00
commit 1a96f651d2
2 changed files with 30 additions and 12 deletions

View File

@ -5674,11 +5674,11 @@ db_upgrade_v16(void)
char *title; char *title;
int id; int id;
char *path; char *path;
int data_kind; int type;
char virtual_path[PATH_MAX]; char virtual_path[PATH_MAX];
int ret; int ret;
query = "SELECT id, album_artist, album, title, path, data_kind FROM files;"; query = "SELECT id, album_artist, album, title, path FROM files;";
DPRINTF(E_DBG, L_DB, "Running query '%s'\n", query); DPRINTF(E_DBG, L_DB, "Running query '%s'\n", query);
@ -5696,7 +5696,6 @@ db_upgrade_v16(void)
album = (char *)sqlite3_column_text(stmt, 2); album = (char *)sqlite3_column_text(stmt, 2);
title = (char *)sqlite3_column_text(stmt, 3); title = (char *)sqlite3_column_text(stmt, 3);
path = (char *)sqlite3_column_text(stmt, 4); path = (char *)sqlite3_column_text(stmt, 4);
data_kind = sqlite3_column_int(stmt, 5);
if (strncmp(path, "http:", strlen("http:")) == 0) if (strncmp(path, "http:", strlen("http:")) == 0)
{ {
@ -5741,9 +5740,9 @@ db_upgrade_v16(void)
id = sqlite3_column_int(stmt, 0); id = sqlite3_column_int(stmt, 0);
title = (char *)sqlite3_column_text(stmt, 1); title = (char *)sqlite3_column_text(stmt, 1);
path = (char *)sqlite3_column_text(stmt, 2); path = (char *)sqlite3_column_text(stmt, 2);
data_kind = sqlite3_column_int(stmt, 3); type = sqlite3_column_int(stmt, 3);
if (data_kind == 0) /* Excludes default playlists */ if (type == 0) /* Excludes default playlists */
{ {
if (strncmp(path, "spotify:", strlen("spotify:")) == 0) if (strncmp(path, "spotify:", strlen("spotify:")) == 0)
{ {

View File

@ -3673,10 +3673,15 @@ mpd_accept_error_cb(struct evconnlistener *listener, void *ctx)
int mpd_init(void) int mpd_init(void)
{ {
struct evconnlistener *listener; struct evconnlistener *listener;
struct sockaddr *saddr;
size_t saddr_length;
struct sockaddr_in sin; struct sockaddr_in sin;
struct sockaddr_in6 sin6;
unsigned short port; unsigned short port;
int v6enabled;
int ret; int ret;
port = cfg_getint(cfg_getsec(cfg, "mpd"), "port"); port = cfg_getint(cfg_getsec(cfg, "mpd"), "port");
if (port <= 0) if (port <= 0)
{ {
@ -3684,6 +3689,8 @@ int mpd_init(void)
return 0; return 0;
} }
v6enabled = cfg_getbool(cfg_getsec(cfg, "general"), "ipv6");
# if defined(__linux__) # if defined(__linux__)
ret = pipe2(g_exit_pipe, O_CLOEXEC); ret = pipe2(g_exit_pipe, O_CLOEXEC);
# else # else
@ -3711,11 +3718,23 @@ int mpd_init(void)
event_add(g_exitev, NULL); event_add(g_exitev, NULL);
//TODO ipv6 if (v6enabled)
memset(&sin, 0, sizeof(sin)); {
saddr_length = sizeof(sin6);
memset(&sin6, 0, saddr_length);
sin6.sin6_family = AF_INET6;
sin6.sin6_port = htons(port);
saddr = (struct sockaddr *)&sin6;
}
else
{
saddr_length = sizeof(struct sockaddr_in);
memset(&sin, 0, saddr_length);
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_addr.s_addr = htonl(0); sin.sin_addr.s_addr = htonl(0);
sin.sin_port = htons(port); sin.sin_port = htons(port);
saddr = (struct sockaddr *)&sin;
}
listener = evconnlistener_new_bind( listener = evconnlistener_new_bind(
evbase_mpd, evbase_mpd,
@ -3723,8 +3742,8 @@ int mpd_init(void)
NULL, NULL,
LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE, LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE,
-1, -1,
(struct sockaddr*) &sin, saddr,
sizeof(sin)); saddr_length);
if (!listener) if (!listener)
{ {