Skip to content

Commit

Permalink
add command "listneighbors"
Browse files Browse the repository at this point in the history
Closes #38
  • Loading branch information
MaxKellermann committed Feb 27, 2019
1 parent 4aaa4e4 commit 552bc59
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS
@@ -1,4 +1,5 @@
0.32 (not yet released)
* add command "listneighbors"
* reduce network transfer for "search"

0.31 (2018/10/24)
Expand Down
1 change: 1 addition & 0 deletions meson.build
Expand Up @@ -99,6 +99,7 @@ executable('mpc',
'src/idle.c',
'src/message.c',
'src/mount.c',
'src/neighbors.c',
'src/search.c',
'src/options.c',
'src/path.c',
Expand Down
3 changes: 3 additions & 0 deletions src/main.c
Expand Up @@ -32,6 +32,7 @@
#include "idle.h"
#include "message.h"
#include "mount.h"
#include "neighbors.h"
#include "search.h"
#include "mpc.h"
#include "options.h"
Expand Down Expand Up @@ -141,6 +142,8 @@ static const struct command {
{ "subscribe", 1, 1, 0, cmd_subscribe, "<channel>",
"Subscribe to the specified channel and continuously receive messages." },

{ "listneighbors", 0, 2, 0, cmd_listneighbors, "", "List neighbors." },

#if LIBMPDCLIENT_CHECK_VERSION(2,16,0)
{ "mount", 0, 2, 0, cmd_mount, "[<uri> <storage>]", "List mounts or add a new mount." },
{ "unmount", 1, 1, 0, cmd_unmount, "<uri>", "Remove a mount." },
Expand Down
47 changes: 47 additions & 0 deletions src/neighbors.c
@@ -0,0 +1,47 @@
/*
* music player command (mpc)
* Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "neighbors.h"
#include "util.h"
#include "charset.h"
#include "Compiler.h"

#include <mpd/client.h>

#include <stdio.h>

int
cmd_listneighbors(gcc_unused int argc, gcc_unused char **argv,
struct mpd_connection *connection)
{
if (!mpd_send_command(connection, "listneighbors", NULL))
printErrorAndExit(connection);

struct mpd_pair *pair;
while ((pair = mpd_recv_pair_named(connection, "neighbor")) != NULL) {
printf("%s\n", charset_from_utf8(pair->value));
mpd_return_pair(connection, pair);
}

if (!mpd_response_finish(connection))
printErrorAndExit(connection);

return 0;
}
29 changes: 29 additions & 0 deletions src/neighbors.h
@@ -0,0 +1,29 @@
/*
* music player command (mpc)
* Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef MPC_NEIGHBORS_H
#define MPC_NEIGHBORS_H

struct mpd_connection;

int
cmd_listneighbors(int argc, char **argv, struct mpd_connection *connection);

#endif /* MPC_NEIGHBORS_H */

0 comments on commit 552bc59

Please sign in to comment.