mpd-client
author Fabien Ninoles <fabien@tzone.org>
Mon, 19 May 2008 01:29:48 -0400
changeset 0 a17355c8ffbd
permissions -rw-r--r--
First import of mpd-client.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     1
diff -r fb5042644071 debian/patches/00list
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     2
--- a/debian/patches/00list	Mon May 19 00:17:05 2008 -0400
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     3
+++ b/debian/patches/00list	Mon May 19 01:12:49 2008 -0400
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     4
@@ -1,2 +1,4 @@
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     5
 01verbose-compilation
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     6
 02compile-with-gcc-4.3
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     7
+03mpd-client
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     8
+04mpd-client-config-init
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     9
diff -r fb5042644071 debian/patches/03mpd-client.dpatch
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    10
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    11
+++ b/debian/patches/03mpd-client.dpatch	Mon May 19 01:12:49 2008 -0400
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    12
@@ -0,0 +1,3597 @@
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    13
+#! /bin/sh /usr/share/dpatch/dpatch-run
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    14
+## mpd-client.dpatch by Fabien Niñoles <fabien@tzone.org>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    15
+##
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    16
+## All lines beginning with `## DP:' are a description of the patch.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    17
+## DP: Add mpd to imms clients.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    18
+
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    19
+@DPATCH@
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    20
+
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    21
+diff -r 171db9560cb5 clients/mpd/immsmpd.cc
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    22
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    23
++++ b/clients/mpd/immsmpd.cc	Mon May 19 00:21:51 2008 -0400
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    24
+@@ -0,0 +1,282 @@
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    25
++#include "immsutil.h"
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    26
++#include "clientstub.h"
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    27
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    28
++#include <glib.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    29
++#include <signal.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    30
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    31
++#include "mpdinterface.h"
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    32
++#include <list>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    33
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    34
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    35
++using std::endl;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    36
++using std::list;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    37
++using namespace mpd_interface;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    38
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    39
++// interface for communication with IMMS server
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    40
++// comes from clientstub.h
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    41
++struct MPDOps;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    42
++typedef IMMSClient<MPDOps> MPDClient;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    43
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    44
++int poll_time = 250; // miliseconds
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    45
++const double reconnect_interval = 1.0; // seconds
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    46
++GMainLoop *loop = nullptr;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    47
++GSource* ts;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    48
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    49
++MPDClient imms;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    50
++Player mpd;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    51
++list<int> playqueue;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    52
++const list<int>::size_type pq_capacity = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    53
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    54
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    55
++// that's the main function - it's called regularly and handles all the
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    56
++// IMMS and MPD communication and decides what to do when anything happens
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    57
++gboolean do_events(void *unused);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    58
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    59
++// determines whether the currently playing song has been selected
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    60
++// specifically by the user
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    61
++bool next_jumped(); 
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    62
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    63
++void notify_song_ended(const Song& song, double elapsed_time, bool jumped);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    64
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    65
++// resets the elapsed_timer and sets the jumped flag, too
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    66
++void notify_song_started(const Song& song, double& elapsed_time,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    67
++    bool& jumped);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    68
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    69
++void update_playqueue();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    70
++bool playqueue_contains(int song);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    71
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    72
++void quit(int signum);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    73
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    74
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    75
++struct MPDOps
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    76
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    77
++    // IMMS server's suggestion of the next song
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    78
++    static void set_next(int next)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    79
++    {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    80
++      if(playqueue.size() < pq_capacity) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    81
++	if(mpd.song(current).path() == mpd.song(next).path() ||
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    82
++	    mpd.song(previous).path() == mpd.song(next).path() ||
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    83
++	    playqueue_contains(next) || next >= mpd.playlist_length()) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    84
++          update_playqueue();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    85
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    86
++	else {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    87
++	  playqueue.push_back(next);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    88
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    89
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    90
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    91
++    // no idea, works just peach as it is
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    92
++    // asked mag about it, waiting for an answer
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    93
++    // TODO if he doesn't answer, dig it out
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    94
++    static void reset_selection() { }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    95
++    // path of the song at the given pos for IMMS server
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    96
++    static string get_item(int index) {return mpd.song(index).path(); }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    97
++    // size of the playlist for the IMMS server
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    98
++    static int get_length() { return mpd.playlist_length(); }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    99
++}; 
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   100
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   101
++int main(int argc, char **argv)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   102
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   103
++  // glib initialization
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   104
++  loop = g_main_loop_new(nullptr, FALSE);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   105
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   106
++  signal(SIGINT,  quit);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   107
++  signal(SIGTERM, quit);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   108
++  signal(SIGPIPE, SIG_IGN);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   109
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   110
++  ts = g_timeout_source_new(poll_time);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   111
++  g_source_attach(ts, nullptr);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   112
++  g_source_set_callback(ts, (GSourceFunc)do_events, nullptr, nullptr);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   113
++  // end of glib init
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   114
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   115
++  g_main_loop_run(loop);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   116
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   117
++  LOG(INFO) << "Exitting." << endl;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   118
++  return 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   119
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   120
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   121
++gboolean do_events(void *unused)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   122
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   123
++  static const double time_inc = double(poll_time)/1000.0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   124
++    // the time that ACTUALLY elapsed when playing the song (in seconds)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   125
++  static double elapsed_time = 0; 
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   126
++  static bool jumped = false;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   127
++  static double reconnect_timeout = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   128
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   129
++  try {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   130
++    if(!mpd.connected()) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   131
++      if(reconnect_timeout < time_inc) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   132
++	LOG(INFO) << "Not connected to MPD. Attempting to connect..."
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   133
++	  << endl;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   134
++	reconnect_timeout = reconnect_interval;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   135
++	mpd.connect();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   136
++	LOG(INFO) << "Connected to MPD." << endl;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   137
++	reconnect_timeout = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   138
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   139
++      else {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   140
++	reconnect_timeout -= time_inc;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   141
++	return TRUE;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   142
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   143
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   144
++    if(imms.check_connection()) imms.setup(0);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   145
++    if(!imms.isok()) return TRUE;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   146
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   147
++    mpd.refresh();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   148
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   149
++    if(mpd.playlist_changed()) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   150
++      imms.playlist_changed(mpd.playlist_length());
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   151
++      playqueue.clear();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   152
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   153
++    if(mpd.radnom()) update_playqueue();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   154
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   155
++    if(mpd.status_changed()) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   156
++      if(mpd.status(current) == stopped) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   157
++	notify_song_ended(mpd.song(current), elapsed_time, jumped);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   158
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   159
++      else if(mpd.status(previous) == stopped &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   160
++	  mpd.status(current)==playing) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   161
++	notify_song_started(mpd.song(current), elapsed_time, jumped);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   162
++	
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   163
++	// clear the song_changed() flag
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   164
++	if(mpd.song_changed()) mpd.refresh(); 
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   165
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   166
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   167
++    if(mpd.status(current) == playing) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   168
++      elapsed_time += time_inc;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   169
++      if(mpd.song_changed()) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   170
++	notify_song_ended(mpd.song(previous), elapsed_time, jumped);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   171
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   172
++	if(!mpd.radnom() || playqueue.empty()) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   173
++	  notify_song_started(mpd.song(current), elapsed_time, jumped);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   174
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   175
++	else {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   176
++	  mpd.play_song(playqueue.front());
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   177
++	  notify_song_started(mpd.song(playqueue.front()), elapsed_time,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   178
++	      jumped);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   179
++	  playqueue.erase(playqueue.begin());
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   180
++	  update_playqueue();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   181
++	  // this could otherwise incorrectly set song_changed() flag
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   182
++	  mpd.refresh(); 
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   183
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   184
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   185
++      else {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   186
++	// fix the real timer if it's inconsistent with what player
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   187
++	// says is the elapsed time of the current song
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   188
++	if(elapsed_time - double(mpd.song(current).elapsed()) >= 3.0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   189
++	  if(mpd.song(current).elapsed() == 0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   190
++	    Song tmp_ended = mpd.song(current);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   191
++	    tmp_ended.set_length(int(elapsed_time) * 2);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   192
++	    notify_song_ended(tmp_ended, elapsed_time, jumped);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   193
++	    notify_song_started(mpd.song(current), elapsed_time, jumped);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   194
++	    jumped = false;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   195
++	  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   196
++	  elapsed_time = mpd.song(current).elapsed();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   197
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   198
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   199
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   200
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   201
++  catch (connection_err) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   202
++    if(reconnect_timeout >= reconnect_interval) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   203
++	  LOG(INFO) << "Connecting to MPD was unsuccessful. "
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   204
++	    "Next attempt in " << reconnect_interval << " second"
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   205
++	    << (reconnect_interval == 1.0 ? "":"s") << "." << endl;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   206
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   207
++    else {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   208
++      LOG(INFO) << "Disconnected from MPD." << endl;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   209
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   210
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   211
++  catch (mpd_err ex) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   212
++    LOG(ERROR) << "Error: " << ex.message() << endl;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   213
++    g_main_quit(loop);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   214
++    loop = nullptr;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   215
++    exit(1);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   216
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   217
++  return TRUE;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   218
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   219
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   220
++// determines whether the song has been played whole
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   221
++bool played_whole(double elapsed_time, int length)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   222
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   223
++  static const double abs_limit = 20.0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   224
++  static const double coeficient = 0.08;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   225
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   226
++  double rel_limit = double(length) * coeficient;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   227
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   228
++  double limit = (abs_limit < rel_limit) ? abs_limit : rel_limit;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   229
++  return double(length)-elapsed_time < limit; 
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   230
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   231
++// determines whether the song has been skipped early
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   232
++// (thus being set as not a prefed one)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   233
++bool bad(double elapsed_time, int length)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   234
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   235
++  static const double abs_limit = 30.0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   236
++  static const double coeficient = 0.13;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   237
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   238
++  double rel_limit = double(length) * coeficient;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   239
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   240
++  double limit = (rel_limit < abs_limit) ? rel_limit : abs_limit;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   241
++  return elapsed_time < limit;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   242
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   243
++bool next_jumped()
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   244
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   245
++  if(mpd.radnom()) return false;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   246
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   247
++  if(mpd.song(current).pos() == mpd.song(previous).pos()+1)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   248
++    return false;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   249
++  if(mpd.song(current).pos() == 0 &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   250
++      mpd.song(previous).pos() == mpd.playlist_length()-1)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   251
++    return false;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   252
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   253
++  return true;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   254
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   255
++void notify_song_ended(const Song& song, double elapsed_time, bool jumped)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   256
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   257
++  if(song.length() == Song::invalid_time) return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   258
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   259
++  imms.end_song(played_whole(elapsed_time, song.length()), jumped,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   260
++      bad(elapsed_time, song.length()) );
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   261
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   262
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   263
++void notify_song_started(const Song& song, double& elapsed_timer,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   264
++    bool& jumped)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   265
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   266
++  imms.start_song(song.pos(), song.path());
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   267
++  elapsed_timer = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   268
++  jumped = next_jumped();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   269
++  mpd.song_changed(); // clear the change notification
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   270
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   271
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   272
++void update_playqueue()
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   273
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   274
++  static const int timeout_value = 3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   275
++  static int timeout = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   276
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   277
++  if(timeout == 0)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   278
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   279
++    if(playqueue.size() < pq_capacity) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   280
++      list<int>::size_type i;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   281
++      for(i = pq_capacity - playqueue.size(); i!=0; i--) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   282
++	imms.select_next();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   283
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   284
++      timeout = timeout_value;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   285
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   286
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   287
++  else --timeout;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   288
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   289
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   290
++bool playqueue_contains(int song)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   291
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   292
++  list<int>::const_iterator i;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   293
++  for(i = playqueue.begin(); i!= playqueue.end(); i++) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   294
++    if (*i == song) return true;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   295
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   296
++  return false;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   297
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   298
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   299
++void quit(int signum)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   300
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   301
++  if (loop) g_main_quit(loop);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   302
++  loop = nullptr;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   303
++  signal(signum, SIG_DFL);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   304
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   305
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   306
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   307
+diff -r 171db9560cb5 clients/mpd/libmpdclient.c
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   308
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   309
++++ b/clients/mpd/libmpdclient.c	Mon May 19 00:21:51 2008 -0400
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   310
+@@ -0,0 +1,1955 @@
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   311
++/* libmpdclient
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   312
++   (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   313
++   This project's homepage is: http://www.musicpd.org
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   314
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   315
++   Redistribution and use in source and binary forms, with or without
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   316
++   modification, are permitted provided that the following conditions
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   317
++   are met:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   318
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   319
++   - Redistributions of source code must retain the above copyright
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   320
++   notice, this list of conditions and the following disclaimer.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   321
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   322
++   - Redistributions in binary form must reproduce the above copyright
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   323
++   notice, this list of conditions and the following disclaimer in the
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   324
++   documentation and/or other materials provided with the distribution.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   325
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   326
++   - Neither the name of the Music Player Daemon nor the names of its
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   327
++   contributors may be used to endorse or promote products derived from
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   328
++   this software without specific prior written permission.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   329
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   330
++   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   331
++   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   332
++   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   333
++   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   334
++   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   335
++   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   336
++   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   337
++   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   338
++   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   339
++   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   340
++   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   341
++*/
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   342
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   343
++#include "libmpdclient.h"
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   344
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   345
++#include <errno.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   346
++#include <ctype.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   347
++#include <sys/types.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   348
++#include <stdio.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   349
++#include <sys/param.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   350
++#include <string.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   351
++#include <unistd.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   352
++#include <stdlib.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   353
++#include <fcntl.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   354
++#include <limits.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   355
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   356
++#ifdef WIN32
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   357
++#  include <ws2tcpip.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   358
++#  include <winsock.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   359
++#else
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   360
++#  include <netinet/in.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   361
++#  include <arpa/inet.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   362
++#  include <sys/socket.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   363
++#  include <netdb.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   364
++#endif
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   365
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   366
++/* (bits+1)/3 (plus the sign character) */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   367
++#define INTLEN      ((sizeof(int)       * CHAR_BIT + 1) / 3 + 1)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   368
++#define LONGLONGLEN ((sizeof(long long) * CHAR_BIT + 1) / 3 + 1)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   369
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   370
++#define COMMAND_LIST    1
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   371
++#define COMMAND_LIST_OK 2
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   372
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   373
++#ifndef MPD_NO_GAI
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   374
++#  ifdef AI_ADDRCONFIG
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   375
++#    define MPD_HAVE_GAI
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   376
++#  endif
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   377
++#endif
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   378
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   379
++#ifndef MSG_DONTWAIT
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   380
++#  define MSG_DONTWAIT 0
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   381
++#endif
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   382
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   383
++#ifdef WIN32
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   384
++#  define SELECT_ERRNO_IGNORE   (errno == WSAEINTR || errno == WSAEINPROGRESS)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   385
++#  define SENDRECV_ERRNO_IGNORE SELECT_ERRNO_IGNORE
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   386
++#else
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   387
++#  define SELECT_ERRNO_IGNORE   (errno == EINTR)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   388
++#  define SENDRECV_ERRNO_IGNORE (errno == EINTR || errno == EAGAIN)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   389
++#  define winsock_dll_error(c)  0
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   390
++#  define closesocket(s)        close(s)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   391
++#  define WSACleanup()          do { /* nothing */ } while (0)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   392
++#endif
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   393
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   394
++#ifdef WIN32
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   395
++static int winsock_dll_error(mpd_Connection *connection)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   396
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   397
++	WSADATA wsaData;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   398
++	if ((WSAStartup(MAKEWORD(2, 2), &wsaData)) != 0 ||
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   399
++			LOBYTE(wsaData.wVersion) != 2 ||
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   400
++			HIBYTE(wsaData.wVersion) != 2 ) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   401
++		strcpy(connection->errorStr,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   402
++		       "Could not find usable WinSock DLL.");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   403
++		connection->error = MPD_ERROR_SYSTEM;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   404
++		return 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   405
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   406
++	return 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   407
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   408
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   409
++static int do_connect_fail(mpd_Connection *connection,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   410
++                           const struct sockaddr *serv_addr, int addrlen)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   411
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   412
++	int iMode = 1; /* 0 = blocking, else non-blocking */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   413
++	ioctlsocket(connection->sock, FIONBIO, (u_long FAR*) &iMode);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   414
++	return (connect(connection->sock,serv_addr,addrlen) == SOCKET_ERROR
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   415
++			&& WSAGetLastError() != WSAEWOULDBLOCK);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   416
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   417
++#else /* !WIN32 (sane operating systems) */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   418
++static int do_connect_fail(mpd_Connection *connection,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   419
++                           const struct sockaddr *serv_addr, int addrlen)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   420
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   421
++	int flags = fcntl(connection->sock, F_GETFL, 0);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   422
++	fcntl(connection->sock, F_SETFL, flags | O_NONBLOCK);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   423
++	return (connect(connection->sock,serv_addr,addrlen)<0 &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   424
++				errno!=EINPROGRESS);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   425
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   426
++#endif /* !WIN32 */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   427
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   428
++#ifdef MPD_HAVE_GAI
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   429
++static int mpd_connect(mpd_Connection * connection, const char * host, int port,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   430
++                       float timeout)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   431
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   432
++	int error;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   433
++	char service[INTLEN+1];
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   434
++	struct addrinfo hints;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   435
++	struct addrinfo *res = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   436
++	struct addrinfo *addrinfo = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   437
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   438
++	/**
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   439
++	 * Setup hints
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   440
++	 */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   441
++	hints.ai_flags     = AI_ADDRCONFIG;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   442
++	hints.ai_family    = PF_UNSPEC;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   443
++	hints.ai_socktype  = SOCK_STREAM;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   444
++	hints.ai_protocol  = IPPROTO_TCP;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   445
++	hints.ai_addrlen   = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   446
++	hints.ai_addr      = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   447
++	hints.ai_canonname = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   448
++	hints.ai_next      = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   449
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   450
++	snprintf(service, sizeof(service), "%i", port);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   451
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   452
++	error = getaddrinfo(host, service, &hints, &addrinfo);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   453
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   454
++	if (error) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   455
++		snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   456
++		         "host \"%s\" not found: %s",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   457
++		         host, gai_strerror(error));
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   458
++		connection->error = MPD_ERROR_UNKHOST;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   459
++		return -1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   460
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   461
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   462
++	for (res = addrinfo; res; res = res->ai_next) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   463
++		/* create socket */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   464
++		connection->sock = socket(res->ai_family, SOCK_STREAM,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   465
++		                          res->ai_protocol);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   466
++		if (connection->sock < 0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   467
++			snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   468
++			         "problems creating socket: %s",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   469
++			         strerror(errno));
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   470
++			connection->error = MPD_ERROR_SYSTEM;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   471
++			freeaddrinfo(addrinfo);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   472
++			return -1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   473
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   474
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   475
++		mpd_setConnectionTimeout(connection, timeout);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   476
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   477
++		/* connect stuff */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   478
++ 		if (do_connect_fail(connection,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   479
++		                    res->ai_addr, res->ai_addrlen)) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   480
++ 			/* try the next address family */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   481
++ 			closesocket(connection->sock);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   482
++ 			connection->sock = -1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   483
++ 			continue;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   484
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   485
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   486
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   487
++	freeaddrinfo(addrinfo);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   488
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   489
++	if (connection->sock < 0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   490
++		snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   491
++		         "problems connecting to \"%s\" on port %i: %s",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   492
++		         host, port, strerror(errno));
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   493
++		connection->error = MPD_ERROR_CONNPORT;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   494
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   495
++		return -1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   496
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   497
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   498
++	return 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   499
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   500
++#else /* !MPD_HAVE_GAI */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   501
++static int mpd_connect(mpd_Connection * connection, const char * host, int port,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   502
++                       float timeout)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   503
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   504
++	struct hostent * he;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   505
++	struct sockaddr * dest;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   506
++	int destlen;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   507
++	struct sockaddr_in sin;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   508
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   509
++	if(!(he=gethostbyname(host))) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   510
++		snprintf(connection->errorStr,MPD_ERRORSTR_MAX_LENGTH,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   511
++				"host \"%s\" not found",host);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   512
++		connection->error = MPD_ERROR_UNKHOST;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   513
++		return -1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   514
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   515
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   516
++	memset(&sin,0,sizeof(struct sockaddr_in));
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   517
++	/*dest.sin_family = he->h_addrtype;*/
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   518
++	sin.sin_family = AF_INET;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   519
++	sin.sin_port = htons(port);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   520
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   521
++	switch(he->h_addrtype) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   522
++	case AF_INET:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   523
++		memcpy((char *)&sin.sin_addr.s_addr,(char *)he->h_addr,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   524
++				he->h_length);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   525
++		dest = (struct sockaddr *)&sin;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   526
++		destlen = sizeof(struct sockaddr_in);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   527
++		break;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   528
++	default:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   529
++		strcpy(connection->errorStr,"address type is not IPv4");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   530
++		connection->error = MPD_ERROR_SYSTEM;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   531
++		return -1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   532
++		break;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   533
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   534
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   535
++	if((connection->sock = socket(dest->sa_family,SOCK_STREAM,0))<0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   536
++		strcpy(connection->errorStr,"problems creating socket");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   537
++		connection->error = MPD_ERROR_SYSTEM;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   538
++		return -1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   539
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   540
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   541
++	mpd_setConnectionTimeout(connection,timeout);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   542
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   543
++	/* connect stuff */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   544
++	if (do_connect_fail(connection, dest, destlen)) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   545
++		snprintf(connection->errorStr,MPD_ERRORSTR_MAX_LENGTH,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   546
++				"problems connecting to \"%s\" on port"
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   547
++				" %i",host,port);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   548
++		connection->error = MPD_ERROR_CONNPORT;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   549
++		return -1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   550
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   551
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   552
++	return 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   553
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   554
++#endif /* !MPD_HAVE_GAI */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   555
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   556
++char * mpdTagItemKeys[MPD_TAG_NUM_OF_ITEM_TYPES] =
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   557
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   558
++	"Artist",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   559
++	"Album",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   560
++	"Title",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   561
++	"Track",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   562
++	"Name",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   563
++	"Genre",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   564
++	"Date",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   565
++	"Composer",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   566
++	"Performer",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   567
++	"Comment",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   568
++	"Disc",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   569
++	"Filename",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   570
++	"Any"
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   571
++};
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   572
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   573
++static char * mpd_sanitizeArg(const char * arg) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   574
++	size_t i;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   575
++	char * ret;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   576
++	register const char *c;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   577
++	register char *rc;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   578
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   579
++	/* instead of counting in that loop above, just
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   580
++	 * use a bit more memory and half running time
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   581
++	 */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   582
++	ret = (char *)malloc(strlen(arg) * 2 + 1);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   583
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   584
++	c = arg;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   585
++	rc = ret;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   586
++	for(i = strlen(arg)+1; i != 0; --i) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   587
++		if(*c=='"' || *c=='\\')
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   588
++			*rc++ = '\\';
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   589
++		*(rc++) = *(c++);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   590
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   591
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   592
++	return ret;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   593
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   594
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   595
++static mpd_ReturnElement * mpd_newReturnElement(const char * name, const char * value)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   596
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   597
++	mpd_ReturnElement * ret = (mpd_ReturnElement *)malloc(sizeof(mpd_ReturnElement));
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   598
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   599
++	ret->name = strdup(name);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   600
++	ret->value = strdup(value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   601
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   602
++	return ret;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   603
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   604
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   605
++static void mpd_freeReturnElement(mpd_ReturnElement * re) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   606
++	free(re->name);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   607
++	free(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   608
++	free(re);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   609
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   610
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   611
++void mpd_setConnectionTimeout(mpd_Connection * connection, float timeout) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   612
++	connection->timeout.tv_sec = (int)timeout;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   613
++	connection->timeout.tv_usec = (int)(timeout*1e6 -
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   614
++	                                    connection->timeout.tv_sec*1000000 +
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   615
++					    0.5);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   616
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   617
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   618
++static int mpd_parseWelcome(mpd_Connection * connection, const char * host, int port,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   619
++                            char * rt, char * output) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   620
++	char * tmp;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   621
++	char * test;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   622
++	int i;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   623
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   624
++	if(strncmp(output,MPD_WELCOME_MESSAGE,strlen(MPD_WELCOME_MESSAGE))) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   625
++		snprintf(connection->errorStr,MPD_ERRORSTR_MAX_LENGTH,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   626
++				"mpd not running on port %i on host \"%s\"",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   627
++				port,host);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   628
++		connection->error = MPD_ERROR_NOTMPD;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   629
++		return 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   630
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   631
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   632
++	tmp = &output[strlen(MPD_WELCOME_MESSAGE)];
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   633
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   634
++	for(i=0;i<3;i++) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   635
++		if(tmp) connection->version[i] = strtol(tmp,&test,10);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   636
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   637
++		if (!tmp || (test[0] != '.' && test[0] != '\0')) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   638
++			snprintf(connection->errorStr,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   639
++			         MPD_ERRORSTR_MAX_LENGTH,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   640
++			         "error parsing version number at "
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   641
++			         "\"%s\"",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   642
++			         &output[strlen(MPD_WELCOME_MESSAGE)]);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   643
++			connection->error = MPD_ERROR_NOTMPD;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   644
++			return 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   645
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   646
++		tmp = ++test;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   647
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   648
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   649
++	return 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   650
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   651
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   652
++mpd_Connection * mpd_newConnection(const char * host, int port, float timeout) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   653
++	int err;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   654
++	char * rt;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   655
++	char * output =  NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   656
++	mpd_Connection * connection = (mpd_Connection *)malloc(sizeof(mpd_Connection));
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   657
++	struct timeval tv;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   658
++	fd_set fds;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   659
++	strcpy(connection->buffer,"");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   660
++	connection->buflen = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   661
++	connection->bufstart = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   662
++	strcpy(connection->errorStr,"");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   663
++	connection->error = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   664
++	connection->doneProcessing = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   665
++	connection->commandList = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   666
++	connection->listOks = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   667
++	connection->doneListOk = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   668
++	connection->returnElement = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   669
++	connection->request = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   670
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   671
++	if (winsock_dll_error(connection))
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   672
++		return connection;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   673
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   674
++	if (mpd_connect(connection, host, port, timeout) < 0)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   675
++		return connection;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   676
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   677
++	while(!(rt = strstr(connection->buffer,"\n"))) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   678
++		tv.tv_sec = connection->timeout.tv_sec;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   679
++		tv.tv_usec = connection->timeout.tv_usec;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   680
++		FD_ZERO(&fds);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   681
++		FD_SET(connection->sock,&fds);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   682
++		if((err = select(connection->sock+1,&fds,NULL,NULL,&tv)) == 1) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   683
++			int readed;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   684
++			readed = recv(connection->sock,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   685
++					&(connection->buffer[connection->buflen]),
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   686
++					MPD_BUFFER_MAX_LENGTH-connection->buflen,0);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   687
++			if(readed<=0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   688
++				snprintf(connection->errorStr,MPD_ERRORSTR_MAX_LENGTH,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   689
++						"problems getting a response from"
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   690
++						" \"%s\" on port %i : %s",host,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   691
++						port, strerror(errno));
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   692
++				connection->error = MPD_ERROR_NORESPONSE;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   693
++				return connection;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   694
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   695
++			connection->buflen+=readed;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   696
++			connection->buffer[connection->buflen] = '\0';
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   697
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   698
++		else if(err<0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   699
++ 			if (SELECT_ERRNO_IGNORE)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   700
++				continue;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   701
++			snprintf(connection->errorStr,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   702
++					MPD_ERRORSTR_MAX_LENGTH,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   703
++					"problems connecting to \"%s\" on port"
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   704
++					" %i",host,port);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   705
++			connection->error = MPD_ERROR_CONNPORT;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   706
++			return connection;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   707
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   708
++		else {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   709
++			snprintf(connection->errorStr,MPD_ERRORSTR_MAX_LENGTH,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   710
++					"timeout in attempting to get a response from"
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   711
++					" \"%s\" on port %i",host,port);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   712
++			connection->error = MPD_ERROR_NORESPONSE;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   713
++			return connection;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   714
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   715
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   716
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   717
++	*rt = '\0';
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   718
++	output = strdup(connection->buffer);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   719
++	strcpy(connection->buffer,rt+1);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   720
++	connection->buflen = strlen(connection->buffer);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   721
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   722
++	if(mpd_parseWelcome(connection,host,port,rt,output) == 0) connection->doneProcessing = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   723
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   724
++	free(output);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   725
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   726
++	return connection;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   727
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   728
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   729
++void mpd_clearError(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   730
++	connection->error = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   731
++	connection->errorStr[0] = '\0';
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   732
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   733
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   734
++void mpd_closeConnection(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   735
++	closesocket(connection->sock);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   736
++	if(connection->returnElement) free(connection->returnElement);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   737
++	if(connection->request) free(connection->request);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   738
++	free(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   739
++	WSACleanup();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   740
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   741
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   742
++static void mpd_executeCommand(mpd_Connection * connection, char * command) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   743
++	int ret;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   744
++	struct timeval tv;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   745
++	fd_set fds;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   746
++	char * commandPtr = command;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   747
++	int commandLen = strlen(command);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   748
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   749
++	if(!connection->doneProcessing && !connection->commandList) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   750
++		strcpy(connection->errorStr,"not done processing current command");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   751
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   752
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   753
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   754
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   755
++	mpd_clearError(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   756
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   757
++	FD_ZERO(&fds);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   758
++	FD_SET(connection->sock,&fds);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   759
++	tv.tv_sec = connection->timeout.tv_sec;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   760
++	tv.tv_usec = connection->timeout.tv_usec;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   761
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   762
++	while((ret = select(connection->sock+1,NULL,&fds,NULL,&tv)==1) ||
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   763
++			(ret==-1 && SELECT_ERRNO_IGNORE)) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   764
++		ret = send(connection->sock,commandPtr,commandLen,MSG_DONTWAIT);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   765
++		if(ret<=0)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   766
++		{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   767
++			if (SENDRECV_ERRNO_IGNORE) continue;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   768
++			snprintf(connection->errorStr,MPD_ERRORSTR_MAX_LENGTH,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   769
++			         "problems giving command \"%s\"",command);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   770
++			connection->error = MPD_ERROR_SENDING;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   771
++			return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   772
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   773
++		else {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   774
++			commandPtr+=ret;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   775
++			commandLen-=ret;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   776
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   777
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   778
++		if(commandLen<=0) break;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   779
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   780
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   781
++	if(commandLen>0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   782
++		perror("");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   783
++		snprintf(connection->errorStr,MPD_ERRORSTR_MAX_LENGTH,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   784
++		         "timeout sending command \"%s\"",command);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   785
++		connection->error = MPD_ERROR_TIMEOUT;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   786
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   787
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   788
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   789
++	if(!connection->commandList) connection->doneProcessing = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   790
++	else if(connection->commandList == COMMAND_LIST_OK) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   791
++		connection->listOks++;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   792
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   793
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   794
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   795
++static void mpd_getNextReturnElement(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   796
++	char * output = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   797
++	char * rt = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   798
++	char * name = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   799
++	char * value = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   800
++	fd_set fds;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   801
++	struct timeval tv;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   802
++	char * tok = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   803
++	int readed;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   804
++	char * bufferCheck = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   805
++	int err;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   806
++	int pos;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   807
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   808
++	if(connection->returnElement) mpd_freeReturnElement(connection->returnElement);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   809
++	connection->returnElement = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   810
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   811
++	if(connection->doneProcessing || (connection->listOks &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   812
++	   connection->doneListOk))
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   813
++	{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   814
++		strcpy(connection->errorStr,"already done processing current command");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   815
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   816
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   817
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   818
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   819
++	bufferCheck = connection->buffer+connection->bufstart;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   820
++	while(connection->bufstart>=connection->buflen ||
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   821
++			!(rt = strchr(bufferCheck,'\n'))) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   822
++		if(connection->buflen>=MPD_BUFFER_MAX_LENGTH) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   823
++			memmove(connection->buffer,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   824
++					connection->buffer+
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   825
++					connection->bufstart,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   826
++					connection->buflen-
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   827
++					connection->bufstart+1);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   828
++			connection->buflen-=connection->bufstart;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   829
++			connection->bufstart = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   830
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   831
++		if(connection->buflen>=MPD_BUFFER_MAX_LENGTH) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   832
++			strcpy(connection->errorStr,"buffer overrun");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   833
++			connection->error = MPD_ERROR_BUFFEROVERRUN;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   834
++			connection->doneProcessing = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   835
++			connection->doneListOk = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   836
++			return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   837
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   838
++		bufferCheck = connection->buffer+connection->buflen;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   839
++		tv.tv_sec = connection->timeout.tv_sec;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   840
++		tv.tv_usec = connection->timeout.tv_usec;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   841
++		FD_ZERO(&fds);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   842
++		FD_SET(connection->sock,&fds);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   843
++		if((err = select(connection->sock+1,&fds,NULL,NULL,&tv) == 1)) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   844
++			readed = recv(connection->sock,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   845
++					connection->buffer+connection->buflen,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   846
++					MPD_BUFFER_MAX_LENGTH-connection->buflen,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   847
++					MSG_DONTWAIT);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   848
++			if(readed<0 && SENDRECV_ERRNO_IGNORE) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   849
++				continue;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   850
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   851
++			if(readed<=0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   852
++				strcpy(connection->errorStr,"connection"
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   853
++				       " closed");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   854
++				connection->error = MPD_ERROR_CONNCLOSED;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   855
++				connection->doneProcessing = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   856
++				connection->doneListOk = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   857
++				return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   858
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   859
++			connection->buflen+=readed;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   860
++			connection->buffer[connection->buflen] = '\0';
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   861
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   862
++		else if(err<0 && SELECT_ERRNO_IGNORE) continue;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   863
++		else {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   864
++			strcpy(connection->errorStr,"connection timeout");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   865
++			connection->error = MPD_ERROR_TIMEOUT;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   866
++			connection->doneProcessing = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   867
++			connection->doneListOk = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   868
++			return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   869
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   870
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   871
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   872
++	*rt = '\0';
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   873
++	output = connection->buffer+connection->bufstart;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   874
++	connection->bufstart = rt - connection->buffer + 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   875
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   876
++	if(strcmp(output,"OK")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   877
++		if(connection->listOks > 0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   878
++			strcpy(connection->errorStr, "expected more list_OK's");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   879
++			connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   880
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   881
++		connection->listOks = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   882
++		connection->doneProcessing = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   883
++		connection->doneListOk = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   884
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   885
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   886
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   887
++	if(strcmp(output, "list_OK") == 0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   888
++		if(!connection->listOks) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   889
++			strcpy(connection->errorStr,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   890
++					"got an unexpected list_OK");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   891
++			connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   892
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   893
++		else {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   894
++			connection->doneListOk = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   895
++			connection->listOks--;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   896
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   897
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   898
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   899
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   900
++	if(strncmp(output,"ACK",strlen("ACK"))==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   901
++		char * test;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   902
++		char * needle;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   903
++		int val;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   904
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   905
++		strcpy(connection->errorStr, output);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   906
++		connection->error = MPD_ERROR_ACK;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   907
++		connection->errorCode = MPD_ACK_ERROR_UNK;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   908
++		connection->errorAt = MPD_ERROR_AT_UNK;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   909
++		connection->doneProcessing = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   910
++		connection->doneListOk = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   911
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   912
++		needle = strchr(output, '[');
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   913
++		if(!needle) return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   914
++		val = strtol(needle+1, &test, 10);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   915
++		if(*test != '@') return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   916
++		connection->errorCode = val;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   917
++		val = strtol(test+1, &test, 10);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   918
++		if(*test != ']') return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   919
++		connection->errorAt = val;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   920
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   921
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   922
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   923
++	tok = strchr(output, ':');
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   924
++	if (!tok) return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   925
++	pos = tok - output;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   926
++	value = ++tok;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   927
++	name = output;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   928
++	name[pos] = '\0';
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   929
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   930
++	if(value[0]==' ') {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   931
++		connection->returnElement = mpd_newReturnElement(name,&(value[1]));
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   932
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   933
++	else {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   934
++		snprintf(connection->errorStr,MPD_ERRORSTR_MAX_LENGTH,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   935
++					"error parsing: %s:%s",name,value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   936
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   937
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   938
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   939
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   940
++void mpd_finishCommand(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   941
++	while(!connection->doneProcessing) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   942
++		if(connection->doneListOk) connection->doneListOk = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   943
++		mpd_getNextReturnElement(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   944
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   945
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   946
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   947
++static void mpd_finishListOkCommand(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   948
++	while(!connection->doneProcessing && connection->listOks &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   949
++			!connection->doneListOk)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   950
++	{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   951
++		mpd_getNextReturnElement(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   952
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   953
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   954
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   955
++int mpd_nextListOkCommand(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   956
++	mpd_finishListOkCommand(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   957
++	if(!connection->doneProcessing) connection->doneListOk = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   958
++	if(connection->listOks == 0 || connection->doneProcessing) return -1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   959
++	return 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   960
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   961
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   962
++void mpd_sendStatusCommand(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   963
++	mpd_executeCommand(connection,"status\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   964
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   965
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   966
++mpd_Status * mpd_getStatus(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   967
++	mpd_Status * status;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   968
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   969
++	/*mpd_executeCommand(connection,"status\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   970
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   971
++	if(connection->error) return NULL;*/
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   972
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   973
++	if(connection->doneProcessing || (connection->listOks &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   974
++	   connection->doneListOk))
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   975
++	{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   976
++		return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   977
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   978
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   979
++	if(!connection->returnElement) mpd_getNextReturnElement(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   980
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   981
++	status = (mpd_Status *)malloc(sizeof(mpd_Status));
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   982
++	status->volume = -1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   983
++	status->repeat = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   984
++	status->random = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   985
++	status->playlist = -1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   986
++	status->playlistLength = -1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   987
++	status->state = -1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   988
++	status->song = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   989
++	status->songid = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   990
++	status->elapsedTime = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   991
++	status->totalTime = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   992
++	status->bitRate = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   993
++	status->sampleRate = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   994
++	status->bits = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   995
++	status->channels = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   996
++	status->crossfade = -1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   997
++	status->error = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   998
++	status->updatingDb = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   999
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1000
++	if(connection->error) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1001
++		free(status);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1002
++		return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1003
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1004
++	while(connection->returnElement) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1005
++		mpd_ReturnElement * re = connection->returnElement;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1006
++		if(strcmp(re->name,"volume")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1007
++			status->volume = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1008
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1009
++		else if(strcmp(re->name,"repeat")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1010
++			status->repeat = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1011
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1012
++		else if(strcmp(re->name,"random")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1013
++			status->random = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1014
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1015
++		else if(strcmp(re->name,"playlist")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1016
++			status->playlist = strtol(re->value,NULL,10);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1017
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1018
++		else if(strcmp(re->name,"playlistlength")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1019
++			status->playlistLength = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1020
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1021
++		else if(strcmp(re->name,"bitrate")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1022
++			status->bitRate = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1023
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1024
++		else if(strcmp(re->name,"state")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1025
++			if(strcmp(re->value,"play")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1026
++				status->state = MPD_STATUS_STATE_PLAY;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1027
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1028
++			else if(strcmp(re->value,"stop")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1029
++				status->state = MPD_STATUS_STATE_STOP;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1030
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1031
++			else if(strcmp(re->value,"pause")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1032
++				status->state = MPD_STATUS_STATE_PAUSE;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1033
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1034
++			else {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1035
++				status->state = MPD_STATUS_STATE_UNKNOWN;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1036
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1037
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1038
++		else if(strcmp(re->name,"song")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1039
++			status->song = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1040
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1041
++		else if(strcmp(re->name,"songid")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1042
++			status->songid = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1043
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1044
++		else if(strcmp(re->name,"time")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1045
++			char * tok = strchr(re->value,':');
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1046
++			/* the second strchr below is a safety check */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1047
++			if (tok && (strchr(tok,0) > (tok+1))) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1048
++				/* atoi stops at the first non-[0-9] char: */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1049
++				status->elapsedTime = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1050
++				status->totalTime = atoi(tok+1);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1051
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1052
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1053
++		else if(strcmp(re->name,"error")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1054
++			status->error = strdup(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1055
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1056
++		else if(strcmp(re->name,"xfade")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1057
++			status->crossfade = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1058
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1059
++		else if(strcmp(re->name,"updating_db")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1060
++			status->updatingDb = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1061
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1062
++		else if(strcmp(re->name,"audio")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1063
++			char * tok = strchr(re->value,':');
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1064
++			if (tok && (strchr(tok,0) > (tok+1))) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1065
++				status->sampleRate = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1066
++				status->bits = atoi(++tok);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1067
++				tok = strchr(tok,':');
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1068
++				if (tok && (strchr(tok,0) > (tok+1)))
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1069
++					status->channels = atoi(tok+1);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1070
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1071
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1072
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1073
++		mpd_getNextReturnElement(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1074
++		if(connection->error) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1075
++			free(status);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1076
++			return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1077
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1078
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1079
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1080
++	if(connection->error) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1081
++		free(status);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1082
++		return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1083
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1084
++	else if(status->state<0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1085
++		strcpy(connection->errorStr,"state not found");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1086
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1087
++		free(status);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1088
++		return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1089
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1090
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1091
++	return status;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1092
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1093
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1094
++void mpd_freeStatus(mpd_Status * status) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1095
++	if(status->error) free(status->error);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1096
++	free(status);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1097
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1098
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1099
++void mpd_sendStatsCommand(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1100
++	mpd_executeCommand(connection,"stats\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1101
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1102
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1103
++mpd_Stats * mpd_getStats(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1104
++	mpd_Stats * stats;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1105
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1106
++	/*mpd_executeCommand(connection,"stats\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1107
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1108
++	if(connection->error) return NULL;*/
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1109
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1110
++	if(connection->doneProcessing || (connection->listOks &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1111
++	   connection->doneListOk))
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1112
++	{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1113
++		return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1114
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1115
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1116
++	if(!connection->returnElement) mpd_getNextReturnElement(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1117
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1118
++	stats = (mpd_Stats *)malloc(sizeof(mpd_Stats));
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1119
++	stats->numberOfArtists = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1120
++	stats->numberOfAlbums = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1121
++	stats->numberOfSongs = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1122
++	stats->uptime = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1123
++	stats->dbUpdateTime = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1124
++	stats->playTime = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1125
++	stats->dbPlayTime = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1126
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1127
++	if(connection->error) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1128
++		free(stats);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1129
++		return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1130
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1131
++	while(connection->returnElement) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1132
++		mpd_ReturnElement * re = connection->returnElement;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1133
++		if(strcmp(re->name,"artists")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1134
++			stats->numberOfArtists = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1135
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1136
++		else if(strcmp(re->name,"albums")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1137
++			stats->numberOfAlbums = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1138
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1139
++		else if(strcmp(re->name,"songs")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1140
++			stats->numberOfSongs = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1141
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1142
++		else if(strcmp(re->name,"uptime")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1143
++			stats->uptime = strtol(re->value,NULL,10);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1144
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1145
++		else if(strcmp(re->name,"db_update")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1146
++			stats->dbUpdateTime = strtol(re->value,NULL,10);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1147
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1148
++		else if(strcmp(re->name,"playtime")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1149
++			stats->playTime = strtol(re->value,NULL,10);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1150
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1151
++		else if(strcmp(re->name,"db_playtime")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1152
++			stats->dbPlayTime = strtol(re->value,NULL,10);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1153
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1154
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1155
++		mpd_getNextReturnElement(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1156
++		if(connection->error) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1157
++			free(stats);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1158
++			return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1159
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1160
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1161
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1162
++	if(connection->error) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1163
++		free(stats);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1164
++		return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1165
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1166
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1167
++	return stats;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1168
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1169
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1170
++void mpd_freeStats(mpd_Stats * stats) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1171
++	free(stats);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1172
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1173
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1174
++mpd_SearchStats * mpd_getSearchStats(mpd_Connection * connection)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1175
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1176
++	mpd_SearchStats * stats;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1177
++	mpd_ReturnElement * re;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1178
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1179
++	if (connection->doneProcessing ||
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1180
++	    (connection->listOks && connection->doneListOk)) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1181
++		return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1182
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1183
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1184
++	if (!connection->returnElement) mpd_getNextReturnElement(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1185
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1186
++	if (connection->error)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1187
++		return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1188
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1189
++	stats = (mpd_SearchStats *)malloc(sizeof(mpd_SearchStats));
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1190
++	stats->numberOfSongs = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1191
++	stats->playTime = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1192
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1193
++	while (connection->returnElement) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1194
++		re = connection->returnElement;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1195
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1196
++		if (strcmp(re->name, "songs") == 0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1197
++			stats->numberOfSongs = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1198
++		} else if (strcmp(re->name, "playtime") == 0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1199
++			stats->playTime = strtol(re->value, NULL, 10);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1200
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1201
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1202
++		mpd_getNextReturnElement(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1203
++		if (connection->error) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1204
++			free(stats);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1205
++			return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1206
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1207
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1208
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1209
++	if (connection->error) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1210
++		free(stats);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1211
++		return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1212
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1213
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1214
++	return stats;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1215
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1216
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1217
++void mpd_freeSearchStats(mpd_SearchStats * stats)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1218
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1219
++	free(stats);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1220
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1221
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1222
++static void mpd_initSong(mpd_Song * song) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1223
++	song->file = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1224
++	song->artist = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1225
++	song->album = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1226
++	song->track = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1227
++	song->title = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1228
++	song->name = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1229
++	song->date = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1230
++	/* added by Qball */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1231
++	song->genre = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1232
++	song->composer = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1233
++	song->performer = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1234
++	song->disc = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1235
++	song->comment = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1236
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1237
++	song->time = MPD_SONG_NO_TIME;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1238
++	song->pos = MPD_SONG_NO_NUM;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1239
++	song->id = MPD_SONG_NO_ID;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1240
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1241
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1242
++static void mpd_finishSong(mpd_Song * song) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1243
++	if(song->file) free(song->file);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1244
++	if(song->artist) free(song->artist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1245
++	if(song->album) free(song->album);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1246
++	if(song->title) free(song->title);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1247
++	if(song->track) free(song->track);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1248
++	if(song->name) free(song->name);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1249
++	if(song->date) free(song->date);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1250
++	if(song->genre) free(song->genre);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1251
++	if(song->composer) free(song->composer);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1252
++	if(song->disc) free(song->disc);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1253
++	if(song->comment) free(song->comment);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1254
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1255
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1256
++mpd_Song * mpd_newSong(void) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1257
++	mpd_Song * ret = (mpd_Song *)malloc(sizeof(mpd_Song));
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1258
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1259
++	mpd_initSong(ret);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1260
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1261
++	return ret;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1262
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1263
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1264
++void mpd_freeSong(mpd_Song * song) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1265
++	mpd_finishSong(song);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1266
++	free(song);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1267
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1268
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1269
++mpd_Song * mpd_songDup(mpd_Song * song) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1270
++	mpd_Song * ret = mpd_newSong();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1271
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1272
++	if(song->file) ret->file = strdup(song->file);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1273
++	if(song->artist) ret->artist = strdup(song->artist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1274
++	if(song->album) ret->album = strdup(song->album);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1275
++	if(song->title) ret->title = strdup(song->title);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1276
++	if(song->track) ret->track = strdup(song->track);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1277
++	if(song->name) ret->name = strdup(song->name);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1278
++	if(song->date) ret->date = strdup(song->date);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1279
++	if(song->genre) ret->genre= strdup(song->genre);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1280
++	if(song->composer) ret->composer= strdup(song->composer);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1281
++	if(song->disc) ret->disc = strdup(song->disc);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1282
++	if(song->comment) ret->comment = strdup(song->comment);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1283
++	ret->time = song->time;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1284
++	ret->pos = song->pos;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1285
++	ret->id = song->id;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1286
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1287
++	return ret;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1288
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1289
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1290
++static void mpd_initDirectory(mpd_Directory * directory) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1291
++	directory->path = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1292
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1293
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1294
++static void mpd_finishDirectory(mpd_Directory * directory) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1295
++	if(directory->path) free(directory->path);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1296
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1297
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1298
++mpd_Directory * mpd_newDirectory(void) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1299
++	mpd_Directory * directory = (mpd_Directory *)malloc(sizeof(mpd_Directory));;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1300
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1301
++	mpd_initDirectory(directory);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1302
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1303
++	return directory;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1304
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1305
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1306
++void mpd_freeDirectory(mpd_Directory * directory) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1307
++	mpd_finishDirectory(directory);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1308
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1309
++	free(directory);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1310
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1311
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1312
++mpd_Directory * mpd_directoryDup(mpd_Directory * directory) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1313
++	mpd_Directory * ret = mpd_newDirectory();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1314
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1315
++	if(directory->path) ret->path = strdup(directory->path);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1316
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1317
++	return ret;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1318
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1319
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1320
++static void mpd_initPlaylistFile(mpd_PlaylistFile * playlist) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1321
++	playlist->path = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1322
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1323
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1324
++static void mpd_finishPlaylistFile(mpd_PlaylistFile * playlist) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1325
++	if(playlist->path) free(playlist->path);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1326
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1327
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1328
++mpd_PlaylistFile * mpd_newPlaylistFile(void) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1329
++	mpd_PlaylistFile * playlist = (mpd_PlaylistFile *)malloc(sizeof(mpd_PlaylistFile));
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1330
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1331
++	mpd_initPlaylistFile(playlist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1332
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1333
++	return playlist;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1334
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1335
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1336
++void mpd_freePlaylistFile(mpd_PlaylistFile * playlist) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1337
++	mpd_finishPlaylistFile(playlist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1338
++	free(playlist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1339
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1340
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1341
++mpd_PlaylistFile * mpd_playlistFileDup(mpd_PlaylistFile * playlist) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1342
++	mpd_PlaylistFile * ret = mpd_newPlaylistFile();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1343
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1344
++	if(playlist->path) ret->path = strdup(playlist->path);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1345
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1346
++	return ret;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1347
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1348
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1349
++static void mpd_initInfoEntity(mpd_InfoEntity * entity) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1350
++	entity->info.directory = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1351
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1352
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1353
++static void mpd_finishInfoEntity(mpd_InfoEntity * entity) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1354
++	if(entity->info.directory) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1355
++		if(entity->type == MPD_INFO_ENTITY_TYPE_DIRECTORY) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1356
++			mpd_freeDirectory(entity->info.directory);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1357
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1358
++		else if(entity->type == MPD_INFO_ENTITY_TYPE_SONG) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1359
++			mpd_freeSong(entity->info.song);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1360
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1361
++		else if(entity->type == MPD_INFO_ENTITY_TYPE_PLAYLISTFILE) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1362
++			mpd_freePlaylistFile(entity->info.playlistFile);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1363
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1364
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1365
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1366
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1367
++mpd_InfoEntity * mpd_newInfoEntity(void) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1368
++	mpd_InfoEntity * entity = (mpd_InfoEntity *)malloc(sizeof(mpd_InfoEntity));
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1369
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1370
++	mpd_initInfoEntity(entity);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1371
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1372
++	return entity;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1373
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1374
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1375
++void mpd_freeInfoEntity(mpd_InfoEntity * entity) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1376
++	mpd_finishInfoEntity(entity);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1377
++	free(entity);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1378
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1379
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1380
++static void mpd_sendInfoCommand(mpd_Connection * connection, char * command) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1381
++	mpd_executeCommand(connection,command);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1382
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1383
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1384
++mpd_InfoEntity * mpd_getNextInfoEntity(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1385
++	mpd_InfoEntity * entity = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1386
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1387
++	if(connection->doneProcessing || (connection->listOks &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1388
++	   connection->doneListOk))
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1389
++	{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1390
++		return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1391
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1392
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1393
++	if(!connection->returnElement) mpd_getNextReturnElement(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1394
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1395
++	if(connection->returnElement) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1396
++		if(strcmp(connection->returnElement->name,"file")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1397
++			entity = mpd_newInfoEntity();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1398
++			entity->type = MPD_INFO_ENTITY_TYPE_SONG;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1399
++			entity->info.song = mpd_newSong();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1400
++			entity->info.song->file =
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1401
++				strdup(connection->returnElement->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1402
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1403
++		else if(strcmp(connection->returnElement->name,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1404
++					"directory")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1405
++			entity = mpd_newInfoEntity();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1406
++			entity->type = MPD_INFO_ENTITY_TYPE_DIRECTORY;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1407
++			entity->info.directory = mpd_newDirectory();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1408
++			entity->info.directory->path =
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1409
++				strdup(connection->returnElement->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1410
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1411
++		else if(strcmp(connection->returnElement->name,"playlist")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1412
++			entity = mpd_newInfoEntity();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1413
++			entity->type = MPD_INFO_ENTITY_TYPE_PLAYLISTFILE;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1414
++			entity->info.playlistFile = mpd_newPlaylistFile();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1415
++			entity->info.playlistFile->path =
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1416
++				strdup(connection->returnElement->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1417
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1418
++		else if(strcmp(connection->returnElement->name, "cpos") == 0){
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1419
++			entity = mpd_newInfoEntity();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1420
++			entity->type = MPD_INFO_ENTITY_TYPE_SONG;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1421
++			entity->info.song = mpd_newSong();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1422
++			entity->info.song->pos = atoi(connection->returnElement->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1423
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1424
++		else {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1425
++			connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1426
++			strcpy(connection->errorStr,"problem parsing song info");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1427
++			return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1428
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1429
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1430
++	else return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1431
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1432
++	mpd_getNextReturnElement(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1433
++	while(connection->returnElement) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1434
++		mpd_ReturnElement * re = connection->returnElement;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1435
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1436
++		if(strcmp(re->name,"file")==0) return entity;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1437
++		else if(strcmp(re->name,"directory")==0) return entity;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1438
++		else if(strcmp(re->name,"playlist")==0) return entity;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1439
++		else if(strcmp(re->name,"cpos")==0) return entity;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1440
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1441
++		if(entity->type == MPD_INFO_ENTITY_TYPE_SONG &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1442
++				strlen(re->value)) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1443
++			if(!entity->info.song->artist &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1444
++					strcmp(re->name,"Artist")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1445
++				entity->info.song->artist = strdup(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1446
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1447
++			else if(!entity->info.song->album &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1448
++					strcmp(re->name,"Album")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1449
++				entity->info.song->album = strdup(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1450
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1451
++			else if(!entity->info.song->title &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1452
++					strcmp(re->name,"Title")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1453
++				entity->info.song->title = strdup(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1454
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1455
++			else if(!entity->info.song->track &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1456
++					strcmp(re->name,"Track")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1457
++				entity->info.song->track = strdup(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1458
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1459
++			else if(!entity->info.song->name &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1460
++					strcmp(re->name,"Name")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1461
++				entity->info.song->name = strdup(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1462
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1463
++			else if(entity->info.song->time==MPD_SONG_NO_TIME &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1464
++					strcmp(re->name,"Time")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1465
++				entity->info.song->time = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1466
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1467
++			else if(entity->info.song->pos==MPD_SONG_NO_NUM &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1468
++					strcmp(re->name,"Pos")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1469
++				entity->info.song->pos = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1470
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1471
++			else if(entity->info.song->id==MPD_SONG_NO_ID &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1472
++					strcmp(re->name,"Id")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1473
++				entity->info.song->id = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1474
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1475
++			else if(!entity->info.song->date &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1476
++					strcmp(re->name, "Date") == 0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1477
++				entity->info.song->date = strdup(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1478
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1479
++			else if(!entity->info.song->genre &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1480
++					strcmp(re->name, "Genre") == 0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1481
++				entity->info.song->genre = strdup(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1482
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1483
++			else if(!entity->info.song->composer &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1484
++					strcmp(re->name, "Composer") == 0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1485
++				entity->info.song->composer = strdup(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1486
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1487
++			else if(!entity->info.song->performer &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1488
++					strcmp(re->name, "Performer") == 0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1489
++				entity->info.song->performer = strdup(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1490
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1491
++			else if(!entity->info.song->disc &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1492
++					strcmp(re->name, "Disc") == 0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1493
++				entity->info.song->disc = strdup(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1494
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1495
++			else if(!entity->info.song->comment &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1496
++					strcmp(re->name, "Comment") == 0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1497
++				entity->info.song->comment = strdup(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1498
++			}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1499
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1500
++		else if(entity->type == MPD_INFO_ENTITY_TYPE_DIRECTORY) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1501
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1502
++		else if(entity->type == MPD_INFO_ENTITY_TYPE_PLAYLISTFILE) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1503
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1504
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1505
++		mpd_getNextReturnElement(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1506
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1507
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1508
++	return entity;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1509
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1510
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1511
++static char * mpd_getNextReturnElementNamed(mpd_Connection * connection,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1512
++		const char * name)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1513
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1514
++	if(connection->doneProcessing || (connection->listOks &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1515
++				connection->doneListOk))
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1516
++	{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1517
++		return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1518
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1519
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1520
++	mpd_getNextReturnElement(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1521
++	while(connection->returnElement) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1522
++		mpd_ReturnElement * re = connection->returnElement;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1523
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1524
++		if(strcmp(re->name,name)==0) return strdup(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1525
++		mpd_getNextReturnElement(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1526
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1527
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1528
++	return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1529
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1530
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1531
++char *mpd_getNextTag(mpd_Connection *connection, int type)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1532
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1533
++	if (type < 0 || type >= MPD_TAG_NUM_OF_ITEM_TYPES ||
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1534
++	    type == MPD_TAG_ITEM_ANY)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1535
++		return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1536
++	if (type == MPD_TAG_ITEM_FILENAME)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1537
++		return mpd_getNextReturnElementNamed(connection, "file");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1538
++	return mpd_getNextReturnElementNamed(connection, mpdTagItemKeys[type]);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1539
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1540
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1541
++char * mpd_getNextArtist(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1542
++	return mpd_getNextReturnElementNamed(connection,"Artist");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1543
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1544
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1545
++char * mpd_getNextAlbum(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1546
++	return mpd_getNextReturnElementNamed(connection,"Album");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1547
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1548
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1549
++void mpd_sendPlaylistInfoCommand(mpd_Connection * connection, int songPos) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1550
++	int len = strlen("playlistinfo")+2+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1551
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1552
++	snprintf(string, len, "playlistinfo \"%i\"\n", songPos);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1553
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1554
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1555
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1556
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1557
++void mpd_sendPlaylistIdCommand(mpd_Connection * connection, int id) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1558
++	int len = strlen("playlistid")+2+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1559
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1560
++	snprintf(string, len, "playlistid \"%i\"\n", id);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1561
++	mpd_sendInfoCommand(connection, string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1562
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1563
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1564
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1565
++void mpd_sendPlChangesCommand(mpd_Connection * connection, long long playlist) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1566
++	int len = strlen("plchanges")+2+LONGLONGLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1567
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1568
++	snprintf(string, len, "plchanges \"%lld\"\n", playlist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1569
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1570
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1571
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1572
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1573
++void mpd_sendPlChangesPosIdCommand(mpd_Connection * connection, long long playlist) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1574
++	int len = strlen("plchangesposid")+2+LONGLONGLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1575
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1576
++	snprintf(string, len, "plchangesposid \"%lld\"\n", playlist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1577
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1578
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1579
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1580
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1581
++void mpd_sendListallCommand(mpd_Connection * connection, const char * dir) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1582
++	char * sDir = mpd_sanitizeArg(dir);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1583
++	int len = strlen("listall")+2+strlen(sDir)+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1584
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1585
++	snprintf(string, len, "listall \"%s\"\n", sDir);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1586
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1587
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1588
++	free(sDir);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1589
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1590
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1591
++void mpd_sendListallInfoCommand(mpd_Connection * connection, const char * dir) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1592
++	char * sDir = mpd_sanitizeArg(dir);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1593
++	int len = strlen("listallinfo")+2+strlen(sDir)+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1594
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1595
++	snprintf(string, len, "listallinfo \"%s\"\n", sDir);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1596
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1597
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1598
++	free(sDir);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1599
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1600
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1601
++void mpd_sendLsInfoCommand(mpd_Connection * connection, const char * dir) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1602
++	char * sDir = mpd_sanitizeArg(dir);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1603
++	int len = strlen("lsinfo")+2+strlen(sDir)+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1604
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1605
++	snprintf(string, len, "lsinfo \"%s\"\n", sDir);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1606
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1607
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1608
++	free(sDir);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1609
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1610
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1611
++void mpd_sendCurrentSongCommand(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1612
++	mpd_executeCommand(connection,"currentsong\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1613
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1614
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1615
++void mpd_sendSearchCommand(mpd_Connection * connection, int table,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1616
++		const char * str)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1617
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1618
++	mpd_startSearch(connection, 0);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1619
++	mpd_addConstraintSearch(connection, table, str);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1620
++	mpd_commitSearch(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1621
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1622
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1623
++void mpd_sendFindCommand(mpd_Connection * connection, int table,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1624
++		const char * str)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1625
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1626
++	mpd_startSearch(connection, 1);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1627
++	mpd_addConstraintSearch(connection, table, str);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1628
++	mpd_commitSearch(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1629
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1630
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1631
++void mpd_sendListCommand(mpd_Connection * connection, int table,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1632
++		const char * arg1)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1633
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1634
++	char st[10];
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1635
++	int len;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1636
++	char *string;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1637
++	if(table == MPD_TABLE_ARTIST) strcpy(st,"artist");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1638
++	else if(table == MPD_TABLE_ALBUM) strcpy(st,"album");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1639
++	else {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1640
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1641
++		strcpy(connection->errorStr,"unknown table for list");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1642
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1643
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1644
++	if(arg1) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1645
++		char * sanitArg1 = mpd_sanitizeArg(arg1);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1646
++		len = strlen("list")+1+strlen(sanitArg1)+2+strlen(st)+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1647
++		string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1648
++		snprintf(string, len, "list %s \"%s\"\n", st, sanitArg1);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1649
++		free(sanitArg1);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1650
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1651
++	else {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1652
++		len = strlen("list")+1+strlen(st)+2;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1653
++		string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1654
++		snprintf(string, len, "list %s\n", st);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1655
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1656
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1657
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1658
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1659
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1660
++void mpd_sendAddCommand(mpd_Connection * connection, const char * file) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1661
++	char * sFile = mpd_sanitizeArg(file);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1662
++	int len = strlen("add")+2+strlen(sFile)+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1663
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1664
++	snprintf(string, len, "add \"%s\"\n", sFile);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1665
++	mpd_executeCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1666
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1667
++	free(sFile);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1668
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1669
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1670
++int mpd_sendAddIdCommand(mpd_Connection *connection, const char *file)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1671
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1672
++	int retval = -1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1673
++	char *sFile = mpd_sanitizeArg(file);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1674
++	int len = strlen("addid")+2+strlen(sFile)+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1675
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1676
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1677
++	snprintf(string, len, "addid \"%s\"\n", sFile);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1678
++	mpd_sendInfoCommand(connection, string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1679
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1680
++	free(sFile);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1681
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1682
++	string = mpd_getNextReturnElementNamed(connection, "Id");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1683
++	if (string) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1684
++		retval = atoi(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1685
++		free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1686
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1687
++	
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1688
++	return retval;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1689
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1690
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1691
++void mpd_sendDeleteCommand(mpd_Connection * connection, int songPos) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1692
++	int len = strlen("delete")+2+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1693
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1694
++	snprintf(string, len, "delete \"%i\"\n", songPos);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1695
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1696
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1697
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1698
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1699
++void mpd_sendDeleteIdCommand(mpd_Connection * connection, int id) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1700
++	int len = strlen("deleteid")+2+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1701
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1702
++	snprintf(string, len, "deleteid \"%i\"\n", id);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1703
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1704
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1705
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1706
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1707
++void mpd_sendSaveCommand(mpd_Connection * connection, const char * name) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1708
++	char * sName = mpd_sanitizeArg(name);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1709
++	int len = strlen("save")+2+strlen(sName)+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1710
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1711
++	snprintf(string, len, "save \"%s\"\n", sName);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1712
++	mpd_executeCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1713
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1714
++	free(sName);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1715
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1716
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1717
++void mpd_sendLoadCommand(mpd_Connection * connection, const char * name) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1718
++	char * sName = mpd_sanitizeArg(name);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1719
++	int len = strlen("load")+2+strlen(sName)+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1720
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1721
++	snprintf(string, len, "load \"%s\"\n", sName);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1722
++	mpd_executeCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1723
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1724
++	free(sName);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1725
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1726
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1727
++void mpd_sendRmCommand(mpd_Connection * connection, const char * name) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1728
++	char * sName = mpd_sanitizeArg(name);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1729
++	int len = strlen("rm")+2+strlen(sName)+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1730
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1731
++	snprintf(string, len, "rm \"%s\"\n", sName);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1732
++	mpd_executeCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1733
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1734
++	free(sName);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1735
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1736
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1737
++void mpd_sendRenameCommand(mpd_Connection *connection, const char *from,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1738
++                           const char *to)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1739
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1740
++	char *sFrom = mpd_sanitizeArg(from);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1741
++	char *sTo = mpd_sanitizeArg(to);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1742
++	int len = strlen("rename")+2+strlen(sFrom)+3+strlen(sTo)+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1743
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1744
++	snprintf(string, len, "rename \"%s\" \"%s\"\n", sFrom, sTo);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1745
++	mpd_executeCommand(connection, string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1746
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1747
++	free(sFrom);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1748
++	free(sTo);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1749
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1750
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1751
++void mpd_sendShuffleCommand(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1752
++	mpd_executeCommand(connection,"shuffle\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1753
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1754
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1755
++void mpd_sendClearCommand(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1756
++	mpd_executeCommand(connection,"clear\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1757
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1758
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1759
++void mpd_sendPlayCommand(mpd_Connection * connection, int songPos) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1760
++	int len = strlen("play")+2+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1761
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1762
++	snprintf(string, len, "play \"%i\"\n", songPos);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1763
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1764
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1765
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1766
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1767
++void mpd_sendPlayIdCommand(mpd_Connection * connection, int id) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1768
++	int len = strlen("playid")+2+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1769
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1770
++	snprintf(string, len, "playid \"%i\"\n", id);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1771
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1772
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1773
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1774
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1775
++void mpd_sendStopCommand(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1776
++	mpd_executeCommand(connection,"stop\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1777
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1778
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1779
++void mpd_sendPauseCommand(mpd_Connection * connection, int pauseMode) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1780
++	int len = strlen("pause")+2+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1781
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1782
++	snprintf(string, len, "pause \"%i\"\n", pauseMode);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1783
++	mpd_executeCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1784
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1785
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1786
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1787
++void mpd_sendNextCommand(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1788
++	mpd_executeCommand(connection,"next\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1789
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1790
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1791
++void mpd_sendMoveCommand(mpd_Connection * connection, int from, int to) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1792
++	int len = strlen("move")+2+INTLEN+3+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1793
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1794
++	snprintf(string, len, "move \"%i\" \"%i\"\n", from, to);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1795
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1796
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1797
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1798
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1799
++void mpd_sendMoveIdCommand(mpd_Connection * connection, int id, int to) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1800
++	int len = strlen("moveid")+2+INTLEN+3+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1801
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1802
++	snprintf(string, len, "moveid \"%i\" \"%i\"\n", id, to);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1803
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1804
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1805
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1806
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1807
++void mpd_sendSwapCommand(mpd_Connection * connection, int song1, int song2) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1808
++	int len = strlen("swap")+2+INTLEN+3+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1809
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1810
++	snprintf(string, len, "swap \"%i\" \"%i\"\n", song1, song2);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1811
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1812
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1813
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1814
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1815
++void mpd_sendSwapIdCommand(mpd_Connection * connection, int id1, int id2) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1816
++	int len = strlen("swapid")+2+INTLEN+3+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1817
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1818
++	snprintf(string, len, "swapid \"%i\" \"%i\"\n", id1, id2);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1819
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1820
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1821
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1822
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1823
++void mpd_sendSeekCommand(mpd_Connection * connection, int song, int time) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1824
++	int len = strlen("seek")+2+INTLEN+3+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1825
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1826
++	snprintf(string, len, "seek \"%i\" \"%i\"\n", song, time);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1827
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1828
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1829
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1830
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1831
++void mpd_sendSeekIdCommand(mpd_Connection * connection, int id, int time) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1832
++	int len = strlen("seekid")+2+INTLEN+3+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1833
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1834
++	snprintf(string, len, "seekid \"%i\" \"%i\"\n", id, time);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1835
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1836
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1837
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1838
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1839
++void mpd_sendUpdateCommand(mpd_Connection * connection, char * path) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1840
++	char * sPath = mpd_sanitizeArg(path);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1841
++	int len = strlen("update")+2+strlen(sPath)+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1842
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1843
++	snprintf(string, len, "update \"%s\"\n", sPath);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1844
++	mpd_sendInfoCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1845
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1846
++	free(sPath);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1847
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1848
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1849
++int mpd_getUpdateId(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1850
++	char * jobid;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1851
++	int ret = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1852
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1853
++	jobid = mpd_getNextReturnElementNamed(connection,"updating_db");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1854
++	if(jobid) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1855
++		ret = atoi(jobid);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1856
++		free(jobid);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1857
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1858
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1859
++	return ret;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1860
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1861
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1862
++void mpd_sendPrevCommand(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1863
++	mpd_executeCommand(connection,"previous\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1864
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1865
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1866
++void mpd_sendRepeatCommand(mpd_Connection * connection, int repeatMode) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1867
++	int len = strlen("repeat")+2+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1868
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1869
++	snprintf(string, len, "repeat \"%i\"\n", repeatMode);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1870
++	mpd_executeCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1871
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1872
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1873
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1874
++void mpd_sendRandomCommand(mpd_Connection * connection, int randomMode) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1875
++	int len = strlen("random")+2+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1876
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1877
++	snprintf(string, len, "random \"%i\"\n", randomMode);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1878
++	mpd_executeCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1879
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1880
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1881
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1882
++void mpd_sendSetvolCommand(mpd_Connection * connection, int volumeChange) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1883
++	int len = strlen("setvol")+2+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1884
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1885
++	snprintf(string, len, "setvol \"%i\"\n", volumeChange);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1886
++	mpd_executeCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1887
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1888
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1889
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1890
++void mpd_sendVolumeCommand(mpd_Connection * connection, int volumeChange) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1891
++	int len = strlen("volume")+2+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1892
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1893
++	snprintf(string, len, "volume \"%i\"\n", volumeChange);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1894
++	mpd_executeCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1895
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1896
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1897
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1898
++void mpd_sendCrossfadeCommand(mpd_Connection * connection, int seconds) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1899
++	int len = strlen("crossfade")+2+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1900
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1901
++	snprintf(string, len, "crossfade \"%i\"\n", seconds);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1902
++	mpd_executeCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1903
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1904
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1905
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1906
++void mpd_sendPasswordCommand(mpd_Connection * connection, const char * pass) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1907
++	char * sPass = mpd_sanitizeArg(pass);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1908
++	int len = strlen("password")+2+strlen(sPass)+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1909
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1910
++	snprintf(string, len, "password \"%s\"\n", sPass);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1911
++	mpd_executeCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1912
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1913
++	free(sPass);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1914
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1915
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1916
++void mpd_sendCommandListBegin(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1917
++	if(connection->commandList) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1918
++		strcpy(connection->errorStr,"already in command list mode");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1919
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1920
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1921
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1922
++	connection->commandList = COMMAND_LIST;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1923
++	mpd_executeCommand(connection,"command_list_begin\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1924
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1925
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1926
++void mpd_sendCommandListOkBegin(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1927
++	if(connection->commandList) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1928
++		strcpy(connection->errorStr,"already in command list mode");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1929
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1930
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1931
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1932
++	connection->commandList = COMMAND_LIST_OK;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1933
++	mpd_executeCommand(connection,"command_list_ok_begin\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1934
++	connection->listOks = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1935
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1936
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1937
++void mpd_sendCommandListEnd(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1938
++	if(!connection->commandList) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1939
++		strcpy(connection->errorStr,"not in command list mode");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1940
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1941
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1942
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1943
++	connection->commandList = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1944
++	mpd_executeCommand(connection,"command_list_end\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1945
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1946
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1947
++void mpd_sendOutputsCommand(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1948
++	mpd_executeCommand(connection,"outputs\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1949
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1950
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1951
++mpd_OutputEntity * mpd_getNextOutput(mpd_Connection * connection) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1952
++	mpd_OutputEntity * output = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1953
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1954
++	if(connection->doneProcessing || (connection->listOks &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1955
++				connection->doneListOk))
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1956
++	{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1957
++		return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1958
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1959
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1960
++	if(connection->error) return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1961
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1962
++	output = (mpd_OutputEntity *)malloc(sizeof(mpd_OutputEntity));
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1963
++	output->id = -10;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1964
++	output->name = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1965
++	output->enabled = 0;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1966
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1967
++	if(!connection->returnElement) mpd_getNextReturnElement(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1968
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1969
++	while(connection->returnElement) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1970
++		mpd_ReturnElement * re = connection->returnElement;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1971
++		if(strcmp(re->name,"outputid")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1972
++			if(output!=NULL && output->id>=0) return output;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1973
++			output->id = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1974
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1975
++		else if(strcmp(re->name,"outputname")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1976
++			output->name = strdup(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1977
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1978
++		else if(strcmp(re->name,"outputenabled")==0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1979
++			output->enabled = atoi(re->value);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1980
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1981
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1982
++		mpd_getNextReturnElement(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1983
++		if(connection->error) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1984
++			free(output);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1985
++			return NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1986
++		}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1987
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1988
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1989
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1990
++	return output;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1991
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1992
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1993
++void mpd_sendEnableOutputCommand(mpd_Connection * connection, int outputId) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1994
++	int len = strlen("enableoutput")+2+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1995
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1996
++	snprintf(string, len, "enableoutput \"%i\"\n", outputId);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1997
++	mpd_executeCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1998
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  1999
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2000
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2001
++void mpd_sendDisableOutputCommand(mpd_Connection * connection, int outputId) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2002
++	int len = strlen("disableoutput")+2+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2003
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2004
++	snprintf(string, len, "disableoutput \"%i\"\n", outputId);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2005
++	mpd_executeCommand(connection,string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2006
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2007
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2008
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2009
++void mpd_freeOutputElement(mpd_OutputEntity * output) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2010
++	free(output->name);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2011
++	free(output);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2012
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2013
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2014
++/**
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2015
++ * mpd_sendNotCommandsCommand
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2016
++ * odd naming, but it gets the not allowed commands
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2017
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2018
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2019
++void mpd_sendNotCommandsCommand(mpd_Connection * connection)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2020
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2021
++	mpd_executeCommand(connection, "notcommands\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2022
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2023
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2024
++/**
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2025
++ * mpd_sendCommandsCommand
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2026
++ * odd naming, but it gets the allowed commands
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2027
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2028
++void mpd_sendCommandsCommand(mpd_Connection * connection)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2029
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2030
++	mpd_executeCommand(connection, "commands\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2031
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2032
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2033
++/**
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2034
++ * Get the next returned command
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2035
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2036
++char * mpd_getNextCommand(mpd_Connection * connection)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2037
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2038
++	return mpd_getNextReturnElementNamed(connection, "command");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2039
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2040
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2041
++void mpd_sendUrlHandlersCommand(mpd_Connection * connection)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2042
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2043
++	mpd_executeCommand(connection, "urlhandlers\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2044
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2045
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2046
++char * mpd_getNextHandler(mpd_Connection * connection)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2047
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2048
++	return mpd_getNextReturnElementNamed(connection, "handler");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2049
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2050
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2051
++void mpd_sendTagTypesCommand(mpd_Connection * connection)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2052
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2053
++	mpd_executeCommand(connection, "tagtypes\n");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2054
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2055
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2056
++char * mpd_getNextTagType(mpd_Connection * connection)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2057
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2058
++	return mpd_getNextReturnElementNamed(connection, "tagtype");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2059
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2060
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2061
++void mpd_startSearch(mpd_Connection *connection, int exact)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2062
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2063
++	if (connection->request) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2064
++		strcpy(connection->errorStr, "search already in progress");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2065
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2066
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2067
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2068
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2069
++	if (exact) connection->request = strdup("find");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2070
++	else connection->request = strdup("search");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2071
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2072
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2073
++void mpd_startStatsSearch(mpd_Connection *connection)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2074
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2075
++	if (connection->request) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2076
++		strcpy(connection->errorStr, "search already in progress");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2077
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2078
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2079
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2080
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2081
++	connection->request = strdup("count");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2082
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2083
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2084
++void mpd_startPlaylistSearch(mpd_Connection *connection, int exact)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2085
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2086
++	if (connection->request) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2087
++		strcpy(connection->errorStr, "search already in progress");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2088
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2089
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2090
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2091
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2092
++	if (exact) connection->request = strdup("playlistfind");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2093
++	else connection->request = strdup("playlistsearch");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2094
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2095
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2096
++void mpd_startFieldSearch(mpd_Connection *connection, int type)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2097
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2098
++	char *strtype;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2099
++	int len;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2100
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2101
++	if (connection->request) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2102
++		strcpy(connection->errorStr, "search already in progress");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2103
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2104
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2105
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2106
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2107
++	if (type < 0 || type >= MPD_TAG_NUM_OF_ITEM_TYPES) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2108
++		strcpy(connection->errorStr, "invalid type specified");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2109
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2110
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2111
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2112
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2113
++	strtype = mpdTagItemKeys[type];
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2114
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2115
++	len = 5+strlen(strtype)+1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2116
++	connection->request = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2117
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2118
++	snprintf(connection->request, len, "list %c%s",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2119
++	         tolower(strtype[0]), strtype+1);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2120
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2121
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2122
++void mpd_addConstraintSearch(mpd_Connection *connection, int type, const char *name)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2123
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2124
++	char *strtype;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2125
++	char *arg;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2126
++	int len;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2127
++	char *string;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2128
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2129
++	if (!connection->request) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2130
++		strcpy(connection->errorStr, "no search in progress");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2131
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2132
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2133
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2134
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2135
++	if (type < 0 || type >= MPD_TAG_NUM_OF_ITEM_TYPES) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2136
++		strcpy(connection->errorStr, "invalid type specified");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2137
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2138
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2139
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2140
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2141
++	if (name == NULL) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2142
++		strcpy(connection->errorStr, "no name specified");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2143
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2144
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2145
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2146
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2147
++	string = strdup(connection->request);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2148
++	strtype = mpdTagItemKeys[type];
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2149
++	arg = mpd_sanitizeArg(name);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2150
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2151
++	len = strlen(string)+1+strlen(strtype)+2+strlen(arg)+2;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2152
++	connection->request = (char *)realloc(connection->request, len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2153
++	snprintf(connection->request, len, "%s %c%s \"%s\"",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2154
++	         string, tolower(strtype[0]), strtype+1, arg);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2155
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2156
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2157
++	free(arg);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2158
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2159
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2160
++void mpd_commitSearch(mpd_Connection *connection)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2161
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2162
++	int len;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2163
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2164
++	if (!connection->request) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2165
++		strcpy(connection->errorStr, "no search in progress");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2166
++		connection->error = 1;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2167
++		return;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2168
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2169
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2170
++	len = strlen(connection->request)+2;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2171
++	connection->request = (char *)realloc(connection->request, len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2172
++	connection->request[len-2] = '\n';
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2173
++	connection->request[len-1] = '\0';
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2174
++	mpd_sendInfoCommand(connection, connection->request);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2175
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2176
++	free(connection->request);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2177
++	connection->request = NULL;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2178
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2179
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2180
++/**
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2181
++ * @param connection a MpdConnection
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2182
++ * @param path	the path to the playlist.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2183
++ *
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2184
++ * List the content, with full metadata, of a stored playlist.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2185
++ *
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2186
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2187
++void mpd_sendListPlaylistInfoCommand(mpd_Connection *connection, char *path)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2188
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2189
++	char *arg = mpd_sanitizeArg(path);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2190
++	int len = strlen("listplaylistinfo")+2+strlen(arg)+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2191
++	char *query = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2192
++	snprintf(query, len, "listplaylistinfo \"%s\"\n", arg);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2193
++	mpd_sendInfoCommand(connection, query);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2194
++	free(arg);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2195
++	free(query);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2196
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2197
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2198
++/**
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2199
++ * @param connection a MpdConnection
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2200
++ * @param path	the path to the playlist.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2201
++ *
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2202
++ * List the content of a stored playlist.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2203
++ *
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2204
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2205
++void mpd_sendListPlaylistCommand(mpd_Connection *connection, char *path)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2206
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2207
++	char *arg = mpd_sanitizeArg(path);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2208
++	int len = strlen("listplaylist")+2+strlen(arg)+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2209
++	char *query = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2210
++	snprintf(query, len, "listplaylist \"%s\"\n", arg);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2211
++	mpd_sendInfoCommand(connection, query);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2212
++	free(arg);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2213
++	free(query);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2214
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2215
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2216
++void mpd_sendPlaylistClearCommand(mpd_Connection *connection, char *path)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2217
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2218
++	char *sPath = mpd_sanitizeArg(path);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2219
++	int len = strlen("playlistclear")+2+strlen(sPath)+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2220
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2221
++	snprintf(string, len, "playlistclear \"%s\"\n", sPath);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2222
++	mpd_executeCommand(connection, string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2223
++	free(sPath);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2224
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2225
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2226
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2227
++void mpd_sendPlaylistAddCommand(mpd_Connection *connection,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2228
++                                char *playlist, char *path)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2229
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2230
++	char *sPlaylist = mpd_sanitizeArg(playlist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2231
++	char *sPath = mpd_sanitizeArg(path);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2232
++	int len = strlen("playlistadd")+2+strlen(sPlaylist)+3+strlen(sPath)+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2233
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2234
++	snprintf(string, len, "playlistadd \"%s\" \"%s\"\n", sPlaylist, sPath);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2235
++	mpd_executeCommand(connection, string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2236
++	free(sPlaylist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2237
++	free(sPath);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2238
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2239
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2240
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2241
++void mpd_sendPlaylistMoveCommand(mpd_Connection *connection,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2242
++                                 char *playlist, int from, int to)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2243
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2244
++	char *sPlaylist = mpd_sanitizeArg(playlist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2245
++	int len = strlen("playlistmove")+
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2246
++	          2+strlen(sPlaylist)+3+INTLEN+3+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2247
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2248
++	snprintf(string, len, "playlistmove \"%s\" \"%i\" \"%i\"\n",
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2249
++	         sPlaylist, from, to);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2250
++	mpd_executeCommand(connection, string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2251
++	free(sPlaylist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2252
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2253
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2254
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2255
++void mpd_sendPlaylistDeleteCommand(mpd_Connection *connection,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2256
++                                   char *playlist, int pos)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2257
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2258
++	char *sPlaylist = mpd_sanitizeArg(playlist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2259
++	int len = strlen("playlistdelete")+2+strlen(sPlaylist)+3+INTLEN+3;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2260
++	char *string = (char *)malloc(len);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2261
++	snprintf(string, len, "playlistdelete \"%s\" \"%i\"\n", sPlaylist, pos);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2262
++	mpd_executeCommand(connection, string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2263
++	free(sPlaylist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2264
++	free(string);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2265
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2266
+diff -r 171db9560cb5 clients/mpd/libmpdclient.h
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2267
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2268
++++ b/clients/mpd/libmpdclient.h	Mon May 19 00:21:51 2008 -0400
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2269
+@@ -0,0 +1,670 @@
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2270
++/* libmpdclient
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2271
++   (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2272
++   This project's homepage is: http://www.musicpd.org
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2273
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2274
++   Redistribution and use in source and binary forms, with or without
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2275
++   modification, are permitted provided that the following conditions
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2276
++   are met:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2277
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2278
++   - Redistributions of source code must retain the above copyright
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2279
++   notice, this list of conditions and the following disclaimer.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2280
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2281
++   - Redistributions in binary form must reproduce the above copyright
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2282
++   notice, this list of conditions and the following disclaimer in the
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2283
++   documentation and/or other materials provided with the distribution.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2284
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2285
++   - Neither the name of the Music Player Daemon nor the names of its
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2286
++   contributors may be used to endorse or promote products derived from
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2287
++   this software without specific prior written permission.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2288
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2289
++   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2290
++   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2291
++   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2292
++   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2293
++   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2294
++   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2295
++   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2296
++   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2297
++   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2298
++   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2299
++   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2300
++*/
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2301
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2302
++#ifndef LIBMPDCLIENT_H
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2303
++#define LIBMPDCLIENT_H
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2304
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2305
++#ifdef WIN32
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2306
++#  define __W32API_USE_DLLIMPORT__ 1
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2307
++#endif
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2308
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2309
++#include <sys/time.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2310
++#include <stdarg.h>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2311
++#define MPD_BUFFER_MAX_LENGTH	50000
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2312
++#define MPD_ERRORSTR_MAX_LENGTH	1000
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2313
++#define MPD_WELCOME_MESSAGE	"OK MPD "
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2314
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2315
++#define MPD_ERROR_TIMEOUT	10 /* timeout trying to talk to mpd */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2316
++#define MPD_ERROR_SYSTEM	11 /* system error */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2317
++#define MPD_ERROR_UNKHOST	12 /* unknown host */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2318
++#define MPD_ERROR_CONNPORT	13 /* problems connecting to port on host */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2319
++#define MPD_ERROR_NOTMPD	14 /* mpd not running on port at host */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2320
++#define MPD_ERROR_NORESPONSE	15 /* no response on attempting to connect */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2321
++#define MPD_ERROR_SENDING	16 /* error sending command */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2322
++#define MPD_ERROR_CONNCLOSED	17 /* connection closed by mpd */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2323
++#define MPD_ERROR_ACK		18 /* ACK returned! */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2324
++#define MPD_ERROR_BUFFEROVERRUN	19 /* Buffer was overrun! */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2325
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2326
++#define MPD_ACK_ERROR_UNK	-1
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2327
++#define MPD_ERROR_AT_UNK	-1
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2328
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2329
++#define MPD_ACK_ERROR_NOT_LIST			1
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2330
++#define MPD_ACK_ERROR_ARG			2
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2331
++#define MPD_ACK_ERROR_PASSWORD			3
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2332
++#define MPD_ACK_ERROR_PERMISSION		4
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2333
++#define MPD_ACK_ERROR_UNKNOWN_CMD		5
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2334
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2335
++#define MPD_ACK_ERROR_NO_EXIST			50
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2336
++#define MPD_ACK_ERROR_PLAYLIST_MAX		51
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2337
++#define MPD_ACK_ERROR_SYSTEM			52
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2338
++#define MPD_ACK_ERROR_PLAYLIST_LOAD		53
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2339
++#define MPD_ACK_ERROR_UPDATE_ALREADY		54
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2340
++#define MPD_ACK_ERROR_PLAYER_SYNC		55
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2341
++#define MPD_ACK_ERROR_EXIST			56
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2342
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2343
++#ifdef __cplusplus
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2344
++extern "C" {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2345
++#endif
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2346
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2347
++typedef enum mpd_TagItems
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2348
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2349
++	MPD_TAG_ITEM_ARTIST,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2350
++	MPD_TAG_ITEM_ALBUM,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2351
++	MPD_TAG_ITEM_TITLE,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2352
++	MPD_TAG_ITEM_TRACK,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2353
++	MPD_TAG_ITEM_NAME,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2354
++	MPD_TAG_ITEM_GENRE,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2355
++	MPD_TAG_ITEM_DATE,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2356
++	MPD_TAG_ITEM_COMPOSER,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2357
++	MPD_TAG_ITEM_PERFORMER,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2358
++	MPD_TAG_ITEM_COMMENT,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2359
++	MPD_TAG_ITEM_DISC,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2360
++	MPD_TAG_ITEM_FILENAME,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2361
++	MPD_TAG_ITEM_ANY,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2362
++	MPD_TAG_NUM_OF_ITEM_TYPES
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2363
++} mpd_TagItems;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2364
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2365
++extern char * mpdTagItemKeys[MPD_TAG_NUM_OF_ITEM_TYPES];
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2366
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2367
++/* internal stuff don't touch this struct */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2368
++typedef struct _mpd_ReturnElement {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2369
++	char * name;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2370
++	char * value;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2371
++} mpd_ReturnElement;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2372
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2373
++/* mpd_Connection
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2374
++ * holds info about connection to mpd
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2375
++ * use error, and errorStr to detect errors
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2376
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2377
++typedef struct _mpd_Connection {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2378
++	/* use this to check the version of mpd */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2379
++	int version[3];
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2380
++	/* IMPORTANT, you want to get the error messages from here */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2381
++	char errorStr[MPD_ERRORSTR_MAX_LENGTH+1];
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2382
++	int errorCode;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2383
++	int errorAt;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2384
++	/* this will be set to MPD_ERROR_* if there is an error, 0 if not */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2385
++	int error;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2386
++	/* DON'T TOUCH any of the rest of this stuff */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2387
++	int sock;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2388
++	char buffer[MPD_BUFFER_MAX_LENGTH+1];
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2389
++	int buflen;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2390
++	int bufstart;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2391
++	int doneProcessing;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2392
++	int listOks;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2393
++	int doneListOk;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2394
++	int commandList;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2395
++	mpd_ReturnElement * returnElement;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2396
++	struct timeval timeout;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2397
++	char *request;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2398
++} mpd_Connection;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2399
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2400
++/* mpd_newConnection
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2401
++ * use this to open a new connection
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2402
++ * you should use mpd_closeConnection, when your done with the connection,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2403
++ * even if an error has occurred
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2404
++ * _timeout_ is the connection timeout period in seconds
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2405
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2406
++mpd_Connection * mpd_newConnection(const char * host, int port, float timeout);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2407
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2408
++void mpd_setConnectionTimeout(mpd_Connection * connection, float timeout);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2409
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2410
++/* mpd_closeConnection
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2411
++ * use this to close a connection and free'ing subsequent memory
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2412
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2413
++void mpd_closeConnection(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2414
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2415
++/* mpd_clearError
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2416
++ * clears error
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2417
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2418
++void mpd_clearError(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2419
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2420
++/* STATUS STUFF */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2421
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2422
++/* use these with status.state to determine what state the player is in */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2423
++#define MPD_STATUS_STATE_UNKNOWN	0
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2424
++#define MPD_STATUS_STATE_STOP		1
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2425
++#define MPD_STATUS_STATE_PLAY		2
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2426
++#define MPD_STATUS_STATE_PAUSE		3
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2427
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2428
++/* us this with status.volume to determine if mpd has volume support */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2429
++#define MPD_STATUS_NO_VOLUME		-1
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2430
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2431
++/* mpd_Status
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2432
++ * holds info return from status command
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2433
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2434
++typedef struct mpd_Status {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2435
++	/* 0-100, or MPD_STATUS_NO_VOLUME when there is no volume support */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2436
++	int volume;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2437
++	/* 1 if repeat is on, 0 otherwise */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2438
++	int repeat;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2439
++	/* 1 if random is on, 0 otherwise */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2440
++	int random;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2441
++	/* playlist length */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2442
++	int playlistLength;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2443
++	/* playlist, use this to determine when the playlist has changed */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2444
++	long long playlist;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2445
++	/* use with MPD_STATUS_STATE_* to determine state of player */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2446
++	int state;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2447
++	/* crossfade setting in seconds */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2448
++	int crossfade;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2449
++	/* if a song is currently selected (always the case when state is
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2450
++	 * PLAY or PAUSE), this is the position of the currently
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2451
++	 * playing song in the playlist, beginning with 0
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2452
++	 */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2453
++	int song;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2454
++	/* Song ID of the currently selected song */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2455
++	int songid;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2456
++	/* time in seconds that have elapsed in the currently playing/paused
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2457
++	 * song
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2458
++	 */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2459
++	int elapsedTime;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2460
++	/* length in seconds of the currently playing/paused song */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2461
++	int totalTime;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2462
++	/* current bit rate in kbs */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2463
++	int bitRate;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2464
++	/* audio sample rate */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2465
++	unsigned int sampleRate;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2466
++	/* audio bits */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2467
++	int bits;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2468
++	/* audio channels */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2469
++	int channels;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2470
++	/* 1 if mpd is updating, 0 otherwise */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2471
++	int updatingDb;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2472
++	/* error */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2473
++	char * error;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2474
++} mpd_Status;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2475
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2476
++void mpd_sendStatusCommand(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2477
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2478
++/* mpd_getStatus
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2479
++ * returns status info, be sure to free it with mpd_freeStatus()
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2480
++ * call this after mpd_sendStatusCommand()
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2481
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2482
++mpd_Status * mpd_getStatus(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2483
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2484
++/* mpd_freeStatus
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2485
++ * free's status info malloc'd and returned by mpd_getStatus
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2486
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2487
++void mpd_freeStatus(mpd_Status * status);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2488
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2489
++typedef struct _mpd_Stats {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2490
++	int numberOfArtists;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2491
++	int numberOfAlbums;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2492
++	int numberOfSongs;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2493
++	unsigned long uptime;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2494
++	unsigned long dbUpdateTime;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2495
++	unsigned long playTime;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2496
++	unsigned long dbPlayTime;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2497
++} mpd_Stats;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2498
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2499
++typedef struct _mpd_SearchStats {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2500
++	int numberOfSongs;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2501
++	unsigned long playTime;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2502
++} mpd_SearchStats;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2503
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2504
++void mpd_sendStatsCommand(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2505
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2506
++mpd_Stats * mpd_getStats(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2507
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2508
++void mpd_freeStats(mpd_Stats * stats);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2509
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2510
++mpd_SearchStats * mpd_getSearchStats(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2511
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2512
++void mpd_freeSearchStats(mpd_SearchStats * stats);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2513
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2514
++/* SONG STUFF */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2515
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2516
++#define MPD_SONG_NO_TIME	-1
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2517
++#define MPD_SONG_NO_NUM		-1
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2518
++#define MPD_SONG_NO_ID		-1
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2519
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2520
++/* mpd_Song
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2521
++ * for storing song info returned by mpd
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2522
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2523
++typedef struct _mpd_Song {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2524
++	/* filename of song */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2525
++	char * file;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2526
++	/* artist, maybe NULL if there is no tag */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2527
++	char * artist;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2528
++	/* title, maybe NULL if there is no tag */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2529
++	char * title;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2530
++	/* album, maybe NULL if there is no tag */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2531
++	char * album;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2532
++	/* track, maybe NULL if there is no tag */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2533
++	char * track;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2534
++	/* name, maybe NULL if there is no tag; it's the name of the current
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2535
++	 * song, f.e. the icyName of the stream */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2536
++	char * name;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2537
++	/* date */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2538
++	char *date;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2539
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2540
++	/* added by qball */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2541
++	/* Genre */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2542
++	char *genre;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2543
++	/* Composer */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2544
++	char *composer;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2545
++	/* Performer */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2546
++	char *performer;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2547
++	/* Disc */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2548
++	char *disc;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2549
++	/* Comment */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2550
++	char *comment;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2551
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2552
++	/* length of song in seconds, check that it is not MPD_SONG_NO_TIME  */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2553
++	int time;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2554
++	/* if plchanges/playlistinfo/playlistid used, is the position of the
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2555
++	 * song in the playlist */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2556
++	int pos;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2557
++	/* song id for a song in the playlist */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2558
++	int id;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2559
++} mpd_Song;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2560
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2561
++/* mpd_newSong
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2562
++ * use to allocate memory for a new mpd_Song
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2563
++ * file, artist, etc all initialized to NULL
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2564
++ * if your going to assign values to file, artist, etc
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2565
++ * be sure to malloc or strdup the memory
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2566
++ * use mpd_freeSong to free the memory for the mpd_Song, it will also
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2567
++ * free memory for file, artist, etc, so don't do it yourself
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2568
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2569
++mpd_Song * mpd_newSong(void);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2570
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2571
++/* mpd_freeSong
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2572
++ * use to free memory allocated by mpd_newSong
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2573
++ * also it will free memory pointed to by file, artist, etc, so be careful
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2574
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2575
++void mpd_freeSong(mpd_Song * song);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2576
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2577
++/* mpd_songDup
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2578
++ * works like strDup, but for a mpd_Song
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2579
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2580
++mpd_Song * mpd_songDup(mpd_Song * song);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2581
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2582
++/* DIRECTORY STUFF */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2583
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2584
++/* mpd_Directory
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2585
++ * used to store info fro directory (right now that just the path)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2586
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2587
++typedef struct _mpd_Directory {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2588
++	char * path;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2589
++} mpd_Directory;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2590
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2591
++/* mpd_newDirectory
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2592
++ * allocates memory for a new directory
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2593
++ * use mpd_freeDirectory to free this memory
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2594
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2595
++mpd_Directory * mpd_newDirectory(void);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2596
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2597
++/* mpd_freeDirectory
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2598
++ * used to free memory allocated with mpd_newDirectory, and it frees
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2599
++ * path of mpd_Directory, so be careful
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2600
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2601
++void mpd_freeDirectory(mpd_Directory * directory);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2602
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2603
++/* mpd_directoryDup
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2604
++ * works like strdup, but for mpd_Directory
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2605
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2606
++mpd_Directory * mpd_directoryDup(mpd_Directory * directory);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2607
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2608
++/* PLAYLISTFILE STUFF */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2609
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2610
++/* mpd_PlaylistFile
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2611
++ * stores info about playlist file returned by lsinfo
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2612
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2613
++typedef struct _mpd_PlaylistFile {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2614
++	char * path;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2615
++} mpd_PlaylistFile;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2616
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2617
++/* mpd_newPlaylistFile
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2618
++ * allocates memory for new mpd_PlaylistFile, path is set to NULL
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2619
++ * free this memory with mpd_freePlaylistFile
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2620
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2621
++mpd_PlaylistFile * mpd_newPlaylistFile(void);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2622
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2623
++/* mpd_freePlaylist
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2624
++ * free memory allocated for freePlaylistFile, will also free
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2625
++ * path, so be careful
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2626
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2627
++void mpd_freePlaylistFile(mpd_PlaylistFile * playlist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2628
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2629
++/* mpd_playlistFileDup
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2630
++ * works like strdup, but for mpd_PlaylistFile
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2631
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2632
++mpd_PlaylistFile * mpd_playlistFileDup(mpd_PlaylistFile * playlist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2633
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2634
++/* INFO ENTITY STUFF */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2635
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2636
++/* the type of entity returned from one of the commands that generates info
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2637
++ * use in conjunction with mpd_InfoEntity.type
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2638
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2639
++#define MPD_INFO_ENTITY_TYPE_DIRECTORY		0
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2640
++#define MPD_INFO_ENTITY_TYPE_SONG		1
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2641
++#define MPD_INFO_ENTITY_TYPE_PLAYLISTFILE	2
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2642
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2643
++/* mpd_InfoEntity
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2644
++ * stores info on stuff returned info commands
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2645
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2646
++typedef struct mpd_InfoEntity {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2647
++	/* the type of entity, use with MPD_INFO_ENTITY_TYPE_* to determine
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2648
++	 * what this entity is (song, directory, etc...)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2649
++	 */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2650
++	int type;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2651
++	/* the actual data you want, mpd_Song, mpd_Directory, etc */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2652
++	union {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2653
++		mpd_Directory * directory;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2654
++		mpd_Song * song;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2655
++		mpd_PlaylistFile * playlistFile;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2656
++	} info;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2657
++} mpd_InfoEntity;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2658
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2659
++mpd_InfoEntity * mpd_newInfoEntity(void);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2660
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2661
++void mpd_freeInfoEntity(mpd_InfoEntity * entity);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2662
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2663
++/* INFO COMMANDS AND STUFF */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2664
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2665
++/* use this function to loop over after calling Info/Listall functions */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2666
++mpd_InfoEntity * mpd_getNextInfoEntity(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2667
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2668
++/* fetches the currently seeletect song (the song referenced by status->song
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2669
++ * and status->songid*/
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2670
++void mpd_sendCurrentSongCommand(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2671
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2672
++/* songNum of -1, means to display the whole list */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2673
++void mpd_sendPlaylistInfoCommand(mpd_Connection * connection, int songNum);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2674
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2675
++/* songId of -1, means to display the whole list */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2676
++void mpd_sendPlaylistIdCommand(mpd_Connection * connection, int songId);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2677
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2678
++/* use this to get the changes in the playlist since version _playlist_ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2679
++void mpd_sendPlChangesCommand(mpd_Connection * connection, long long playlist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2680
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2681
++/**
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2682
++ * @param connection: A valid and connected mpd_Connection.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2683
++ * @param playlist: The playlist version you want the diff with.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2684
++ * A more bandwidth efficient version of the mpd_sendPlChangesCommand.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2685
++ * It only returns the pos+id of the changes song.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2686
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2687
++void mpd_sendPlChangesPosIdCommand(mpd_Connection * connection, long long playlist);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2688
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2689
++/* recursivel fetches all songs/dir/playlists in "dir* (no metadata is
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2690
++ * returned) */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2691
++void mpd_sendListallCommand(mpd_Connection * connection, const char * dir);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2692
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2693
++/* same as sendListallCommand, but also metadata is returned */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2694
++void mpd_sendListallInfoCommand(mpd_Connection * connection, const char * dir);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2695
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2696
++/* non-recursive version of ListallInfo */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2697
++void mpd_sendLsInfoCommand(mpd_Connection * connection, const char * dir);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2698
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2699
++#define MPD_TABLE_ARTIST	MPD_TAG_ITEM_ARTIST
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2700
++#define MPD_TABLE_ALBUM		MPD_TAG_ITEM_ALBUM
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2701
++#define MPD_TABLE_TITLE		MPD_TAG_ITEM_TITLE
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2702
++#define MPD_TABLE_FILENAME	MPD_TAG_ITEM_FILENAME
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2703
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2704
++void mpd_sendSearchCommand(mpd_Connection * connection, int table,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2705
++		const char * str);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2706
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2707
++void mpd_sendFindCommand(mpd_Connection * connection, int table,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2708
++		const char * str);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2709
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2710
++/* LIST TAG COMMANDS */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2711
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2712
++/* use this function fetch next artist entry, be sure to free the returned
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2713
++ * string.  NULL means there are no more.  Best used with sendListArtists
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2714
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2715
++char * mpd_getNextArtist(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2716
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2717
++char * mpd_getNextAlbum(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2718
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2719
++char * mpd_getNextTag(mpd_Connection *connection, int type);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2720
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2721
++/* list artist or albums by artist, arg1 should be set to the artist if
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2722
++ * listing albums by a artist, otherwise NULL for listing all artists or albums
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2723
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2724
++void mpd_sendListCommand(mpd_Connection * connection, int table,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2725
++		const char * arg1);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2726
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2727
++/* SIMPLE COMMANDS */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2728
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2729
++void mpd_sendAddCommand(mpd_Connection * connection, const char * file);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2730
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2731
++int mpd_sendAddIdCommand(mpd_Connection *connection, const char *file);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2732
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2733
++void mpd_sendDeleteCommand(mpd_Connection * connection, int songNum);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2734
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2735
++void mpd_sendDeleteIdCommand(mpd_Connection * connection, int songNum);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2736
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2737
++void mpd_sendSaveCommand(mpd_Connection * connection, const char * name);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2738
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2739
++void mpd_sendLoadCommand(mpd_Connection * connection, const char * name);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2740
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2741
++void mpd_sendRmCommand(mpd_Connection * connection, const char * name);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2742
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2743
++void mpd_sendRenameCommand(mpd_Connection *connection, const char *from,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2744
++                           const char *to);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2745
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2746
++void mpd_sendShuffleCommand(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2747
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2748
++void mpd_sendClearCommand(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2749
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2750
++/* use this to start playing at the beginning, useful when in random mode */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2751
++#define MPD_PLAY_AT_BEGINNING	-1
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2752
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2753
++void mpd_sendPlayCommand(mpd_Connection * connection, int songNum);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2754
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2755
++void mpd_sendPlayIdCommand(mpd_Connection * connection, int songNum);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2756
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2757
++void mpd_sendStopCommand(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2758
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2759
++void mpd_sendPauseCommand(mpd_Connection * connection, int pauseMode);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2760
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2761
++void mpd_sendNextCommand(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2762
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2763
++void mpd_sendPrevCommand(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2764
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2765
++void mpd_sendMoveCommand(mpd_Connection * connection, int from, int to);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2766
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2767
++void mpd_sendMoveIdCommand(mpd_Connection * connection, int from, int to);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2768
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2769
++void mpd_sendSwapCommand(mpd_Connection * connection, int song1, int song2);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2770
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2771
++void mpd_sendSwapIdCommand(mpd_Connection * connection, int song1, int song2);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2772
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2773
++void mpd_sendSeekCommand(mpd_Connection * connection, int song, int time);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2774
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2775
++void mpd_sendSeekIdCommand(mpd_Connection * connection, int song, int time);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2776
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2777
++void mpd_sendRepeatCommand(mpd_Connection * connection, int repeatMode);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2778
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2779
++void mpd_sendRandomCommand(mpd_Connection * connection, int randomMode);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2780
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2781
++void mpd_sendSetvolCommand(mpd_Connection * connection, int volumeChange);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2782
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2783
++/* WARNING: don't use volume command, its depreacted */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2784
++void mpd_sendVolumeCommand(mpd_Connection * connection, int volumeChange);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2785
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2786
++void mpd_sendCrossfadeCommand(mpd_Connection * connection, int seconds);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2787
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2788
++void mpd_sendUpdateCommand(mpd_Connection * connection, char * path);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2789
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2790
++/* returns the update job id, call this after a update command*/
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2791
++int mpd_getUpdateId(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2792
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2793
++void mpd_sendPasswordCommand(mpd_Connection * connection, const char * pass);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2794
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2795
++/* after executing a command, when your done with it to get its status
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2796
++ * (you want to check connection->error for an error)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2797
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2798
++void mpd_finishCommand(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2799
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2800
++/* command list stuff, use this to do things like add files very quickly */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2801
++void mpd_sendCommandListBegin(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2802
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2803
++void mpd_sendCommandListOkBegin(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2804
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2805
++void mpd_sendCommandListEnd(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2806
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2807
++/* advance to the next listOk
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2808
++ * returns 0 if advanced to the next list_OK,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2809
++ * returns -1 if it advanced to an OK or ACK */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2810
++int mpd_nextListOkCommand(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2811
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2812
++typedef struct _mpd_OutputEntity {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2813
++	int id;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2814
++	char * name;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2815
++	int enabled;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2816
++} mpd_OutputEntity;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2817
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2818
++void mpd_sendOutputsCommand(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2819
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2820
++mpd_OutputEntity * mpd_getNextOutput(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2821
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2822
++void mpd_sendEnableOutputCommand(mpd_Connection * connection, int outputId);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2823
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2824
++void mpd_sendDisableOutputCommand(mpd_Connection * connection, int outputId);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2825
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2826
++void mpd_freeOutputElement(mpd_OutputEntity * output);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2827
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2828
++/**
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2829
++ * @param connection a #mpd_Connection
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2830
++ *
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2831
++ * Queries mpd for the allowed commands
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2832
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2833
++void mpd_sendCommandsCommand(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2834
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2835
++/**
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2836
++ * @param connection a #mpd_Connection
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2837
++ *
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2838
++ * Queries mpd for the not allowed commands
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2839
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2840
++void mpd_sendNotCommandsCommand(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2841
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2842
++/**
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2843
++ * @param connection a #mpd_Connection
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2844
++ *
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2845
++ * returns the next supported command.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2846
++ *
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2847
++ * @returns a string, needs to be free'ed
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2848
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2849
++char *mpd_getNextCommand(mpd_Connection *connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2850
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2851
++void mpd_sendUrlHandlersCommand(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2852
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2853
++char *mpd_getNextHandler(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2854
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2855
++void mpd_sendTagTypesCommand(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2856
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2857
++char *mpd_getNextTagType(mpd_Connection * connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2858
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2859
++/**
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2860
++ * @param connection a MpdConnection
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2861
++ * @param path	the path to the playlist.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2862
++ *
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2863
++ * List the content, with full metadata, of a stored playlist.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2864
++ *
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2865
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2866
++void mpd_sendListPlaylistInfoCommand(mpd_Connection *connection, char *path);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2867
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2868
++/**
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2869
++ * @param connection a MpdConnection
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2870
++ * @param path	the path to the playlist.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2871
++ *
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2872
++ * List the content of a stored playlist.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2873
++ *
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2874
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2875
++void mpd_sendListPlaylistCommand(mpd_Connection *connection, char *path);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2876
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2877
++/**
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2878
++ * @param connection a #mpd_Connection
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2879
++ * @param exact if to match exact
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2880
++ *
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2881
++ * starts a search, use mpd_addConstraintSearch to add
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2882
++ * a constraint to the search, and mpd_commitSearch to do the actual search
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2883
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2884
++void mpd_startSearch(mpd_Connection *connection, int exact);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2885
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2886
++/**
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2887
++ * @param connection a #mpd_Connection
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2888
++ * @param type
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2889
++ * @param name
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2890
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2891
++void mpd_addConstraintSearch(mpd_Connection *connection, int type, const char *name);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2892
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2893
++/**
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2894
++ * @param connection a #mpd_Connection
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2895
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2896
++void mpd_commitSearch(mpd_Connection *connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2897
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2898
++/**
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2899
++ * @param connection a #mpd_Connection
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2900
++ * @param type The type to search for
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2901
++ *
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2902
++ * starts a search for fields... f.e. get a list of artists would be:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2903
++ * @code
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2904
++ * mpd_startFieldSearch(connection, MPD_TAG_ITEM_ARTIST);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2905
++ * mpd_commitSearch(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2906
++ * @endcode
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2907
++ *
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2908
++ * or get a list of artist in genre "jazz" would be:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2909
++ * @code
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2910
++ * mpd_startFieldSearch(connection, MPD_TAG_ITEM_ARTIST);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2911
++ * mpd_addConstraintSearch(connection, MPD_TAG_ITEM_GENRE, "jazz")
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2912
++ * mpd_commitSearch(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2913
++ * @endcode
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2914
++ *
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2915
++ * mpd_startSearch will return  a list of songs (and you need mpd_getNextInfoEntity)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2916
++ * this one will return a list of only one field (the one specified with type) and you need
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2917
++ * mpd_getNextTag to get the results
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2918
++ */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2919
++void mpd_startFieldSearch(mpd_Connection *connection, int type);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2920
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2921
++void mpd_startPlaylistSearch(mpd_Connection *connection, int exact);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2922
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2923
++void mpd_startStatsSearch(mpd_Connection *connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2924
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2925
++void mpd_sendPlaylistClearCommand(mpd_Connection *connection, char *path);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2926
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2927
++void mpd_sendPlaylistAddCommand(mpd_Connection *connection,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2928
++                                char *playlist, char *path);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2929
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2930
++void mpd_sendPlaylistMoveCommand(mpd_Connection *connection,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2931
++                                 char *playlist, int from, int to);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2932
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2933
++void mpd_sendPlaylistDeleteCommand(mpd_Connection *connection,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2934
++                                   char *playlist, int pos);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2935
++#ifdef __cplusplus
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2936
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2937
++#endif
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2938
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2939
++#endif
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2940
+diff -r 171db9560cb5 clients/mpd/mpdinterface.cc
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2941
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2942
++++ b/clients/mpd/mpdinterface.cc	Mon May 19 00:21:51 2008 -0400
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2943
+@@ -0,0 +1,404 @@
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2944
++#include "mpdinterface.h"
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2945
++#include "immsutil.h"
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2946
++#include <cctype>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2947
++#include <fstream>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2948
++#include <sstream>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2949
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2950
++namespace mpd_interface
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2951
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2952
++  position_err::position_err(int position, int playlist_length)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2953
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2954
++    std::ostringstream s;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2955
++    s << "Attempted to access song of invalid position in playlist. "
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2956
++      "Used position: " << position << ", playlist size: "
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2957
++      << playlist_length;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2958
++    msg = s.str();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2959
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2960
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2961
++  std::string Song::music_directory = "";
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2962
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2963
++  void Song::set_default_dir(std::string path)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2964
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2965
++    music_directory = path;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2966
++    if(!path.empty() && path[path.length()-1]!='/') {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2967
++      music_directory.append("/");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2968
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2969
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2970
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2971
++  bool operator==(const Song& first, const Song& second)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2972
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2973
++    return (first.song_path == second.song_path) &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2974
++      (first.pl_pos == second.pl_pos) &&
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2975
++      (first.song_length == second.song_length);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2976
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2977
++  bool operator!=(const Song& first, const Song& second)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2978
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2979
++    return !(first == second);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2980
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2981
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2982
++  // determines whether the line contains the given parameter in the
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2983
++  // mpd.conf fashion
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2984
++  bool contains_parameter(const std::string& line, const std::string& parameter)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2985
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2986
++    if(line.empty() || line[0]=='#') return false;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2987
++    
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2988
++    std::string::size_type pos = line.find(parameter);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2989
++    if(pos == std::string::npos) return false;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2990
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2991
++    while(pos>0) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2992
++      if(!isspace(line[pos-1])) return false;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2993
++      --pos;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2994
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2995
++    return true;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2996
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2997
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2998
++  // returns the value of the given parameter from an mpd.config line
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  2999
++  std::string get_value(const std::string& line,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3000
++      const std::string& parameter)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3001
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3002
++    if(!contains_parameter(line, parameter)) return "";
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3003
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3004
++    std::string::size_type start = line.find_first_of("\"");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3005
++    ++start; // position of the first non-quote char
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3006
++    if(start == std::string::npos || start>=line.size()) return "";
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3007
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3008
++    std::string::size_type end = line.find_last_of("\"");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3009
++    if(end == std::string::npos) return "";
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3010
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3011
++    std::string result = line.substr(start, end-start);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3012
++    return result;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3013
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3014
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3015
++  config read_configuration(std::string conf_path) throw(config_err)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3016
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3017
++    static const std::string address_param = "bind_to_address";
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3018
++    static const std::string port_param = "port";
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3019
++    static const std::string dir_param = "music_directory";
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3020
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3021
++    if(conf_path == "")
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3022
++    {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3023
++      std::string user_path = getenv("HOME");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3024
++      if(user_path[user_path.size()-1] != '/') user_path.append("/");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3025
++      user_path.append(".mpdconf");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3026
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3027
++      try {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3028
++	// read the "~/.mpdconf" file
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3029
++	return read_configuration(user_path);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3030
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3031
++      catch (config_err) { // "~/.mpdconf" not found
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3032
++	  // read the "/etc/mpd.conf" instead
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3033
++	  return read_configuration("/etc/mpd.conf");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3034
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3035
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3036
++    else
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3037
++    {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3038
++      std::ifstream con_f(conf_path.c_str());
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3039
++      if(!con_f) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3040
++	throw config_err("cannot open the MPD config file \"" +
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3041
++	    conf_path + "\"");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3042
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3043
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3044
++      config result;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3045
++      std::string line;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3046
++      while(getline(con_f, line)) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3047
++	if(contains_parameter(line, address_param)) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3048
++	  result.hostname = get_value(line, address_param);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3049
++	  if(result.hostname.empty()) result.hostname = "localhost";
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3050
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3051
++	else if(contains_parameter(line, port_param)) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3052
++	  std::stringstream s;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3053
++	  s << get_value(line, port_param);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3054
++	  if(!(s >> result.port)) result.port = 6600;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3055
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3056
++	else if(contains_parameter(line, dir_param)) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3057
++	  result.music_dir = get_value(line, dir_param);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3058
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3059
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3060
++      con_f.close();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3061
++      if(result.music_dir.empty()) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3062
++	throw config_err("infalid format of the MPD config file \"" + 
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3063
++	    conf_path + "\"");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3064
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3065
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3066
++      return result;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3067
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3068
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3069
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3070
++  
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3071
++  bool Server::connect(const std::string& hostname, int port)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3072
++    throw(connection_err)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3073
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3074
++    if(connected()) disconnect();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3075
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3076
++    try {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3077
++      connection = mpd_newConnection(hostname.c_str(), port, 10);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3078
++      if(mpd_error()) throw connection_err(connection->errorStr);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3079
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3080
++    catch(connection_err) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3081
++      disconnect();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3082
++      throw;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3083
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3084
++    
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3085
++    if(connected()) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3086
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3087
++    return connected();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3088
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3089
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3090
++  void Server::disconnect()
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3091
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3092
++    if(connection!=nullptr) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3093
++      mpd_closeConnection(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3094
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3095
++    connection = nullptr;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3096
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3097
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3098
++  bool Server::ack_error() const throw(connection_err)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3099
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3100
++    if(!connected()) throw connection_err();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3101
++    return connection->error == MPD_ERROR_ACK;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3102
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3103
++  // determines whether the MPD is in error state which is not the ACK error
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3104
++  bool Server::mpd_error() const throw(connection_err)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3105
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3106
++    if(!connected()) throw connection_err();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3107
++    return connection->error!=0 && !ack_error();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3108
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3109
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3110
++  // changes the mpd internal status to the playback_status type
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3111
++  playback_status resolve_state(int mpd_state)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3112
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3113
++    switch(mpd_state)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3114
++    {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3115
++      case MPD_STATUS_STATE_PLAY:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3116
++	return playing;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3117
++      case MPD_STATUS_STATE_STOP:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3118
++	return stopped;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3119
++      case MPD_STATUS_STATE_PAUSE:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3120
++	return paused;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3121
++      default:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3122
++	return playing;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3123
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3124
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3125
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3126
++  void Server::refresh() throw(connection_err)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3127
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3128
++    if(!connected()) throw connection_err();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3129
++    try {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3130
++      
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3131
++// the mess below is here because otherwise the results in nasty problems
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3132
++// when MPD connection times out
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3133
++//TODO prolly doesn't have to be everywhere, though. Weed it out
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3134
++if(mpd_error()) throw connection_err(connection->errorStr);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3135
++      mpd_sendCommandListOkBegin(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3136
++if(mpd_error()) throw connection_err(connection->errorStr);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3137
++      mpd_sendStatusCommand(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3138
++if(mpd_error()) throw connection_err(connection->errorStr);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3139
++      mpd_sendCurrentSongCommand(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3140
++if(mpd_error()) throw connection_err(connection->errorStr);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3141
++      mpd_sendCommandListEnd(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3142
++if(mpd_error()) throw connection_err(connection->errorStr);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3143
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3144
++      mpd_Status * status = mpd_getStatus(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3145
++      if(status!=nullptr) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3146
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3147
++      pl_length = status->playlistLength;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3148
++      pl_version = status->playlist;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3149
++      pb_status = resolve_state(status->state);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3150
++      current_song.set_elapsed(status->elapsedTime);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3151
++      random = status->random;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3152
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3153
++      mpd_freeStatus(status);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3154
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3155
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3156
++      if(mpd_error()) throw connection_err(connection->errorStr);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3157
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3158
++      mpd_nextListOkCommand(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3159
++      mpd_InfoEntity *entity;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3160
++      while((entity = mpd_getNextInfoEntity(connection))) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3161
++	mpd_Song *song = entity->info.song;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3162
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3163
++	if(entity->type!=MPD_INFO_ENTITY_TYPE_SONG) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3164
++	  mpd_freeInfoEntity(entity);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3165
++	  continue;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3166
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3167
++	
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3168
++	current_song.set_path(song->file);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3169
++	current_song.set_pos(song->pos);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3170
++	current_song.set_length(song->time);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3171
++	mpd_freeInfoEntity(entity);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3172
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3173
++      if(mpd_error()) throw connection_err(connection->errorStr);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3174
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3175
++      mpd_finishCommand(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3176
++      if(mpd_error()) throw connection_err(connection->errorStr);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3177
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3178
++    catch(connection_err) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3179
++      disconnect();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3180
++      throw;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3181
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3182
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3183
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3184
++  Song Server::get_song_info(int pl_pos)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3185
++    throw(connection_err, position_err)   
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3186
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3187
++    if(!connected()) throw connection_err();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3188
++    if(pl_pos < 0 || pl_pos >= get_playlist_length()) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3189
++      throw position_err(pl_pos, get_playlist_length());
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3190
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3191
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3192
++    Song result;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3193
++    try {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3194
++      mpd_sendPlaylistInfoCommand(connection, pl_pos);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3195
++      if(mpd_error()) throw connection_err(connection->errorStr);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3196
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3197
++      mpd_InfoEntity *entity;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3198
++      while((entity = mpd_getNextInfoEntity(connection)))
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3199
++      {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3200
++	mpd_Song *song = entity->info.song;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3201
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3202
++	if(entity->type!=MPD_INFO_ENTITY_TYPE_SONG)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3203
++	{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3204
++	  mpd_freeInfoEntity(entity);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3205
++	  continue;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3206
++	}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3207
++	
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3208
++	result = Song(song->file,song->pos,song->time);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3209
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3210
++	mpd_freeInfoEntity(entity);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3211
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3212
++      if(mpd_error()) throw connection_err(connection->errorStr);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3213
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3214
++      mpd_finishCommand(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3215
++      if(mpd_error()) throw connection_err(connection->errorStr);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3216
++      // shouldn't happen, but just in case
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3217
++      if(ack_error())  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3218
++	refresh();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3219
++	throw position_err(pl_pos, get_playlist_length());
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3220
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3221
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3222
++    catch(connection_err)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3223
++    {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3224
++      disconnect();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3225
++      throw;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3226
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3227
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3228
++    return result;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3229
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3230
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3231
++  void Server::play_song(int pl_pos) throw(connection_err, position_err)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3232
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3233
++    if(!connected()) throw connection_err();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3234
++    if(pl_pos < 0 || pl_pos >= pl_length) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3235
++      throw position_err(pl_pos, get_playlist_length());
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3236
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3237
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3238
++    try {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3239
++      mpd_sendPlayCommand(connection, pl_pos);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3240
++      mpd_finishCommand(connection);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3241
++      if(mpd_error()) throw connection_err(connection->errorStr);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3242
++      if(ack_error()) throw position_err(pl_pos, get_playlist_length());
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3243
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3244
++    catch(connection_err) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3245
++      disconnect();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3246
++      throw;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3247
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3248
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3249
++  // end of SERVER section
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3250
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3251
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3252
++  // Player class
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3253
++  Player::Player(): previous_status(stopped), current_status(stopped),
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3254
++  previous_song_pos(Song::invalid_pos), current_song_pos(Song::invalid_pos),
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3255
++  null_song()
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3256
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3257
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3258
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3259
++  bool Player::connect() throw(config_err, connection_err)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3260
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3261
++    config conf = read_configuration();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3262
++    Song::set_default_dir(conf.music_dir);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3263
++    return mpd.connect(conf.hostname, conf.port);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3264
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3265
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3266
++  void Player::disconnect()
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3267
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3268
++    mpd.disconnect();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3269
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3270
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3271
++  void Player::refresh()
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3272
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3273
++    mpd.refresh();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3274
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3275
++    playlist__changed = pl_ver != mpd.get_playlist_version();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3276
++    if(playlist__changed) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3277
++      pl_ver = mpd.get_playlist_version();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3278
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3279
++      // update the internal playlist
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3280
++      playlist.clear();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3281
++      playlist.reserve(mpd.get_playlist_length());
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3282
++      for(int i = 0; i<mpd.get_playlist_length(); i++) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3283
++	playlist.push_back(mpd.get_song_info(i));
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3284
++      }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3285
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3286
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3287
++    song__changed = mpd.get_current_song() != song(current);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3288
++    if(song__changed) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3289
++      previous_song_pos = current_song_pos;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3290
++      current_song_pos = mpd.get_current_song().pos();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3291
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3292
++    else if(!playlist.empty() && current_song_pos != Song::invalid_pos) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3293
++      playlist[current_song_pos].set_elapsed(mpd.get_current_song().
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3294
++	  elapsed());
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3295
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3296
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3297
++    status__changed = current_status != mpd.get_playback_status();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3298
++    if(status__changed) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3299
++      previous_status = current_status;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3300
++      current_status = mpd.get_playback_status();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3301
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3302
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3303
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3304
++  const Song& Player::song(recent value) const
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3305
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3306
++    if(playlist.empty()) return null_song;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3307
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3308
++    switch(value) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3309
++      case previous:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3310
++	return previous_song_pos == Song::invalid_pos ?
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3311
++	  null_song : song(previous_song_pos);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3312
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3313
++      case current:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3314
++      default:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3315
++	return current_song_pos == Song::invalid_pos ?
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3316
++	  null_song : song(current_song_pos);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3317
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3318
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3319
++  const Song& Player::song(int position) const throw(position_err)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3320
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3321
++    try {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3322
++      return playlist.at(position);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3323
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3324
++    catch (...) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3325
++      throw position_err(position, playlist.size());
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3326
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3327
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3328
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3329
++  playback_status Player::status(recent value) const
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3330
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3331
++    switch (value) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3332
++      case previous: return previous_status;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3333
++      case current:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3334
++      default: return current_status;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3335
++    }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3336
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3337
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3338
++  void Player::play_song(int pl_pos)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3339
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3340
++    mpd.play_song(pl_pos);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3341
++  }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3342
++  // end of Player class
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3343
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3344
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3345
++} // namespace end
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3346
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3347
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3348
+diff -r 171db9560cb5 clients/mpd/mpdinterface.h
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3349
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3350
++++ b/clients/mpd/mpdinterface.h	Mon May 19 00:21:51 2008 -0400
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3351
+@@ -0,0 +1,209 @@
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3352
++#ifndef MPDINTERFACE_H
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3353
++#define MPDINTERFACE_H
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3354
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3355
++#include "libmpdclient.h"
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3356
++#include <string>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3357
++#include <vector>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3358
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3359
++namespace mpd_interface
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3360
++{
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3361
++const int nullptr = 0; 
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3362
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3363
++/* list of thrown exceptions */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3364
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3365
++  // generic exception that can be thrown by MPD
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3366
++  class mpd_err
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3367
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3368
++  protected:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3369
++    std::string msg;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3370
++  public:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3371
++    mpd_err(const std::string& message = "unknown error"): msg(message) { }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3372
++    std::string message() const { return msg; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3373
++  };
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3374
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3375
++  // thrown when for whatever reason the connection cannot be maintained
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3376
++  // the Player is always set to the disconnected state when this is thrown
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3377
++  class connection_err: public mpd_err
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3378
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3379
++  public:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3380
++    connection_err(const std::string& message = "not connected"):
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3381
++      mpd_err(message) { }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3382
++  };
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3383
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3384
++  class config_err: public mpd_err
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3385
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3386
++  public:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3387
++    config_err(const std::string& message = "") : mpd_err(message) { }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3388
++  };
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3389
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3390
++  // thrown when trying to access element out of the playlist range
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3391
++  // contains information about the length of the playlist
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3392
++  // and the invalid position
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3393
++  class position_err: public mpd_err
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3394
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3395
++    int invalid_position;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3396
++    int pl_length;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3397
++  public:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3398
++    position_err(int position, int playlist_length);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3399
++    int pos() const { return invalid_position; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3400
++    int playlist_length() const {return pl_length; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3401
++  };
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3402
++/* end of the exception list */
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3403
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3404
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3405
++  // information about the configuration of MPD
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3406
++  // it's the relevant info read from the mpd.config file
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3407
++  struct config
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3408
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3409
++    std::string hostname;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3410
++    int port;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3411
++    std::string music_dir;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3412
++  };
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3413
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3414
++  // attempts to read the configuration file
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3415
++  // if no path is specified following actions are taken:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3416
++  // first, the ~/.mpdconf file is looked for
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3417
++  // then, the /etc/mpd.conf file is tried.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3418
++  config read_configuration(std::string conf_path="") throw(config_err);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3419
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3420
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3421
++  // Represents one song in playlist.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3422
++  // Note that when one song is twice in a playlist (their positions differ)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3423
++  // they are two different songs from this class' point of view.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3424
++  class Song
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3425
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3426
++    static std::string music_directory; // directory in which the songs are
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3427
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3428
++    std::string song_path; 
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3429
++    int pl_pos; 
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3430
++    int song_length; // time - in seconds
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3431
++    int song_elapsed; // time - in seconds
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3432
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3433
++  public:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3434
++    static const int invalid_pos = MPD_SONG_NO_NUM;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3435
++    static const int invalid_time = MPD_SONG_NO_TIME;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3436
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3437
++    static void set_default_dir(std::string path); // set the music directory
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3438
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3439
++    Song(std::string path = "", int position = invalid_pos,
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3440
++	int length = invalid_time, int elapsed = invalid_time):
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3441
++      song_path(music_directory+path), pl_pos(position),
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3442
++      song_length(length), song_elapsed(elapsed) { }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3443
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3444
++    friend bool operator==(const Song& first, const Song& second);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3445
++    friend bool operator!=(const Song& first, const Song& second);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3446
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3447
++    std::string path() const { return song_path; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3448
++    void set_path(std::string path) { song_path = music_directory+path; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3449
++    int pos() const { return pl_pos; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3450
++    void set_pos(int position) { pl_pos = position; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3451
++    int length() const { return song_length; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3452
++    void set_length(int length) { song_length = length; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3453
++    int elapsed() const {return song_elapsed; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3454
++    void set_elapsed(int elapsed) { song_elapsed = elapsed; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3455
++  };
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3456
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3457
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3458
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3459
++  // the status of the playback - whether it's stopped, paused
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3460
++  // or is playing a song right now
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3461
++  enum playback_status {playing, stopped, paused} ;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3462
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3463
++  // represents the communication with the MPD server
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3464
++  // It's a confortable wrapper around the libmpdclient library
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3465
++  // When its refresh() method is called it gets all information from server
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3466
++  // and stores them so as not to flood the MPD with commands
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3467
++  class Server
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3468
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3469
++  public:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3470
++    Server(): connection(nullptr) {};
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3471
++    ~Server() { disconnect(); }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3472
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3473
++    bool connect(const std::string& hostname="localhost", int port = 6600)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3474
++      throw(connection_err);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3475
++    void disconnect();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3476
++    bool connected() const {return connection!=nullptr; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3477
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3478
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3479
++    void refresh() throw(connection_err); // the Server asks MPD for new values
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3480
++    int get_playlist_length() const { return pl_length; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3481
++    long long get_playlist_version() { return pl_version; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3482
++    playback_status get_playback_status() { return pb_status; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3483
++    bool get_random() const {return random; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3484
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3485
++    Song get_song_info(int pl_pos) throw(connection_err,position_err);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3486
++    Song get_current_song() const { return current_song; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3487
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3488
++    // plays the song at the specified position
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3489
++    void play_song(int pl_pos) throw(connection_err, position_err);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3490
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3491
++  private:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3492
++    Server& operator=(const Server&);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3493
++    Server(const Server&);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3494
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3495
++    mpd_Connection *connection;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3496
++    int pl_length;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3497
++    long long pl_version;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3498
++    playback_status pb_status;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3499
++    Song current_song;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3500
++    bool random;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3501
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3502
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3503
++    // determines whether the actual MPD error state is the ACK error
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3504
++    bool ack_error() const throw(connection_err);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3505
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3506
++    // determines whether the MPD is in error state which is not the ACK error
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3507
++    bool mpd_error() const throw(connection_err);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3508
++  };
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3509
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3510
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3511
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3512
++  enum recent {previous, current};
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3513
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3514
++  class Player
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3515
++  {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3516
++  public:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3517
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3518
++    Player();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3519
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3520
++    bool connect() throw(config_err, connection_err);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3521
++    void disconnect();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3522
++    bool connected() const { return mpd.connected(); }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3523
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3524
++    void refresh();
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3525
++    
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3526
++    bool song_changed() {return song__changed; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3527
++    bool playlist_changed() { return playlist__changed; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3528
++    bool status_changed() { return status__changed; }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3529
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3530
++    // gets the current or the previously played song
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3531
++    // song(current) returns currently played song
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3532
++    // song(previous) returns the previously played song
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3533
++    const Song& song(recent) const;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3534
++    const Song& song(int position) const throw(position_err);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3535
++    int playlist_length() const { return mpd.get_playlist_length(); }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3536
++    bool radnom() const { return mpd.get_random(); }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3537
++    void play_song(int pl_pos);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3538
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3539
++    // gets the current or the previous playback status
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3540
++    playback_status status(recent) const;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3541
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3542
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3543
++  private:
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3544
++    Player& operator=(const Player&);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3545
++    Player(const Player&);
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3546
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3547
++    Server mpd;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3548
++    long long pl_ver;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3549
++    playback_status previous_status, current_status;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3550
++    int previous_song_pos, current_song_pos;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3551
++    const Song null_song;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3552
++    std::vector<Song> playlist;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3553
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3554
++    bool song__changed, playlist__changed, status__changed;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3555
++  };
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3556
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3557
++}
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3558
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3559
++#endif
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3560
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3561
+diff -r 171db9560cb5 clients/mpd/rules.mk
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3562
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3563
++++ b/clients/mpd/rules.mk	Mon May 19 00:21:51 2008 -0400
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3564
+@@ -0,0 +1,16 @@
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3565
++MDPCPPFLAGS= $(GLIB2CPPFLAGS)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3566
++MPDLDFLAGS= $(GLIB2LDFLAGS)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3567
++MPDCOMMON= mpdinterface.o libmpdclient.o clientstubbase.o libimmscore.a libmodel.a
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3568
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3569
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3570
++immsmpd: immsmpd.o $(MPDCOMMON)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3571
++immsmpd: $(call objects,../clients/mpd)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3572
++immsmpd-CPPFLAGS=$(MDPCPPFLAGS)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3573
++immsmpd-LIBS=$(MPDLDFLAGS)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3574
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3575
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3576
++MPDDESTDIR=/usr/bin
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3577
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3578
++immsmpd_install: immsmpd
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3579
++	${INSTALL} -D $^ $(MPDDESTDIR)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3580
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3581
+diff -r 171db9560cb5 configure.ac
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3582
+--- a/configure.ac	Mon May 19 00:16:56 2008 -0400
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3583
++++ b/configure.ac	Mon May 19 00:21:51 2008 -0400
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3584
+@@ -260,6 +260,13 @@
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3585
+ saved_libs="$LIBS"
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3586
+ 
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3587
+ PLUGINS=""
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3588
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3589
++AC_CHECK_PROG(with_mdp, mpd --help, "yes", "no")
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3590
++if test "$with_mpd" != "no"; then
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3591
++    AC_APPEND(PLUGINS, immsmpd)
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3592
++fi
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3593
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3594
++
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3595
+ AC_CHECK_PROG(with_xmms, xmms-config, "yes", "no")
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3596
+ if test "$with_xmms" != "no"; then
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3597
+     CPPFLAGS=`xmms-config --cflags`
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3598
+diff -r 171db9560cb5 vars.mk.in
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3599
+--- a/vars.mk.in	Mon May 19 00:16:56 2008 -0400
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3600
++++ b/vars.mk.in	Mon May 19 00:21:51 2008 -0400
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3601
+@@ -10,7 +10,7 @@
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3602
+ bindir = @bindir@
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3603
+ datadir = @datadir@
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3604
+ 
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3605
+-VPATH = ../immscore:../analyzer:../model:../autotag:../immsremote:../utils:../clients:../immsd:../data:../clients/xmms:../clients/bmp:../clients/audacious
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3606
++VPATH = ../immscore:../analyzer:../model:../autotag:../immsremote:../utils:../clients:../immsd:../data:../clients/xmms:../clients/bmp:../clients/audacious:../clients/mpd
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3607
+ ARFLAGS = rs
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3608
+ 
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3609
+ SHELL = bash
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3610
diff -r fb5042644071 debian/patches/04mpd-client-config-init.dpatch
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3611
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3612
+++ b/debian/patches/04mpd-client-config-init.dpatch	Mon May 19 01:12:49 2008 -0400
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3613
@@ -0,0 +1,20 @@
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3614
+#! /bin/sh /usr/share/dpatch/dpatch-run
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3615
+## mpd-client-config-init.dpatch by Fabien Niñoles <fabien@tzone.org>
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3616
+##
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3617
+## All lines beginning with `## DP:' are a description of the patch.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3618
+## DP: Initialize default configuration.
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3619
+
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3620
+@DPATCH@
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3621
+
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3622
+diff -r 019508c19157 clients/mpd/mpdinterface.cc
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3623
+--- a/clients/mpd/mpdinterface.cc	Mon May 19 00:21:51 2008 -0400
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3624
++++ b/clients/mpd/mpdinterface.cc	Mon May 19 00:51:06 2008 -0400
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3625
+@@ -98,7 +98,7 @@
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3626
+ 	    conf_path + "\"");
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3627
+       }
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3628
+ 
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3629
+-      config result;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3630
++      config result = { "localhost", 6600, "" };
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3631
+       std::string line;
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3632
+       while(getline(con_f, line)) {
a17355c8ffbd First import of mpd-client.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
  3633
+ 	if(contains_parameter(line, address_param)) {