aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-10-13 01:41:28 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2016-10-13 01:50:00 +0200
commit62a08ad4d33312c8470870150dd1f2eadde6638f (patch)
tree077dcbaebd53c127a1024cdb293bc960846e5a2d
parent5bf0410587fa9f55510071ee92ee21f5d5274f97 (diff)
downloadnncmpp-62a08ad4d33312c8470870150dd1f2eadde6638f.tar.gz
nncmpp-62a08ad4d33312c8470870150dd1f2eadde6638f.tar.xz
nncmpp-62a08ad4d33312c8470870150dd1f2eadde6638f.zip
Clean up mpd_process_info(), bump liberty
"command_list_ok_begin" allows us to partition the response easily.
m---------liberty0
-rw-r--r--nncmpp.c46
2 files changed, 23 insertions, 23 deletions
diff --git a/liberty b/liberty
-Subproject 2a15b1de700eb4e20c6bebb9742c8e20fffc968
+Subproject dfc7ff57efee0608c652f81779ef45a1b5269ab
diff --git a/nncmpp.c b/nncmpp.c
index 991bc90..7d0a93c 100644
--- a/nncmpp.c
+++ b/nncmpp.c
@@ -2739,33 +2739,33 @@ mpd_process_info (const struct str_vector *data)
map.key_xfrm = tolower_ascii_strxfrm;
map.free = free;
- // First there's the status, followed by playlist items chunked by "file".
- // Unfortunately we need a field from the front before we process the rest
- // but otherwise it's much better to process the list from the back.
- //
- // TODO: one thing that could help is command_list_ok_begin,
- // which can add NULL strings to the vector in place of list_OK
- unsigned long n;
- for (size_t i = 0; i < data->len; i++)
+ // First there's the status, followed by playlist items chunked by "file"
+ unsigned long n; char *key, *value;
+ for (size_t i = 0; i < data->len - 1 && data->vector[i]; i++)
{
- static const char needle[] = "playlistlength: ";
- if (!strncasecmp_ascii (data->vector[i], needle, sizeof needle - 1)
- && xstrtoul (&n, data->vector[i] + sizeof needle - 1, 10))
+ if (!(key = mpd_client_parse_kv (data->vector[i], &value)))
{
- item_list_resize (&g_ctx.playlist, n);
- break;
+ print_debug ("%s: %s", "erroneous MPD output", data->vector[i]);
+ continue;
}
+ if (!strcasecmp_ascii (key, "playlistlength")
+ && xstrtoul (&n, value, 10))
+ item_list_resize (&g_ctx.playlist, n);
+ str_map_set (&map, key, xstrdup (value));
}
+ g_ctx.playback_info = map;
- char *key, *value;
- for (size_t i = data->len; i--; )
+ // It's much better to process the playlist from the back
+ str_map_init (&map);
+ map.key_xfrm = tolower_ascii_strxfrm;
+ for (size_t i = data->len - 1; i-- && data->vector[i]; )
{
if (!(key = mpd_client_parse_kv (data->vector[i], &value)))
{
print_debug ("%s: %s", "erroneous MPD output", data->vector[i]);
continue;
}
- str_map_set (&map, key, xstrdup (value));
+ str_map_set (&map, key, value);
if (!strcasecmp_ascii (key, "file"))
{
if (xstrtoul_map (&map, "pos", &n))
@@ -2773,7 +2773,7 @@ mpd_process_info (const struct str_vector *data)
str_map_clear (&map);
}
}
- g_ctx.playback_info = map;
+ str_map_free (&map);
}
static void
@@ -2792,13 +2792,13 @@ mpd_on_info_response (const struct mpd_response *response,
g_ctx.playlist_version = 0;
// TODO: preset an error player state?
- if (response->success)
- mpd_process_info (data);
- else
- {
+ if (!response->success)
print_debug ("%s: %s",
"retrieving MPD info failed", response->message_text);
- }
+ else if (!data->len)
+ print_debug ("empty MPD status response");
+ else
+ mpd_process_info (data);
mpd_update_playback_state ();
current_tab_update ();
@@ -2826,7 +2826,7 @@ mpd_request_info (void)
{
struct mpd_client *c = &g_ctx.client;
- mpd_client_list_begin (c);
+ mpd_client_list_ok_begin (c);
mpd_client_send_command (c, "status", NULL);
char *last_version = xstrdup_printf ("%" PRIu32, g_ctx.playlist_version);
mpd_client_send_command (c, "plchanges", last_version, NULL);