1 diff -urN lcd4linux-r870.orig/libmpdclient.c lcd4linux-r870/libmpdclient.c
2 --- lcd4linux-r870.orig/libmpdclient.c 1970-01-01 01:00:00.000000000 +0100
3 +++ lcd4linux-r870/libmpdclient.c 2008-03-26 04:43:31.000000000 +0100
6 + (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
7 + This project's homepage is: http://www.musicpd.org
9 + Redistribution and use in source and binary forms, with or without
10 + modification, are permitted provided that the following conditions
13 + - Redistributions of source code must retain the above copyright
14 + notice, this list of conditions and the following disclaimer.
16 + - Redistributions in binary form must reproduce the above copyright
17 + notice, this list of conditions and the following disclaimer in the
18 + documentation and/or other materials provided with the distribution.
20 + - Neither the name of the Music Player Daemon nor the names of its
21 + contributors may be used to endorse or promote products derived from
22 + this software without specific prior written permission.
24 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
28 + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 +#include "libmpdclient.h"
41 +#include <sys/types.h>
43 +#include <sys/param.h>
51 +# include <ws2tcpip.h>
52 +# include <winsock.h>
54 +# include <netinet/in.h>
55 +# include <arpa/inet.h>
56 +# include <sys/socket.h>
60 +/* (bits+1)/3 (plus the sign character) */
61 +#define INTLEN ((sizeof(int) * CHAR_BIT + 1) / 3 + 1)
62 +#define LONGLONGLEN ((sizeof(long long) * CHAR_BIT + 1) / 3 + 1)
64 +#define COMMAND_LIST 1
65 +#define COMMAND_LIST_OK 2
68 +# ifdef AI_ADDRCONFIG
69 +# define MPD_HAVE_GAI
74 +# define MSG_DONTWAIT 0
78 +# define SELECT_ERRNO_IGNORE (errno == WSAEINTR || errno == WSAEINPROGRESS)
79 +# define SENDRECV_ERRNO_IGNORE SELECT_ERRNO_IGNORE
81 +# define SELECT_ERRNO_IGNORE (errno == EINTR)
82 +# define SENDRECV_ERRNO_IGNORE (errno == EINTR || errno == EAGAIN)
83 +# define winsock_dll_error(c) 0
84 +# define closesocket(s) close(s)
85 +# define WSACleanup() do { /* nothing */ } while (0)
89 +static int winsock_dll_error(mpd_Connection * connection)
92 + if ((WSAStartup(MAKEWORD(2, 2), &wsaData)) != 0 || LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
93 + strcpy(connection->errorStr, "Could not find usable WinSock DLL.");
94 + connection->error = MPD_ERROR_SYSTEM;
100 +static int do_connect_fail(mpd_Connection * connection, const struct sockaddr *serv_addr, int addrlen)
102 + int iMode = 1; /* 0 = blocking, else non-blocking */
103 + ioctlsocket(connection->sock, FIONBIO, (u_long FAR *) & iMode);
104 + return (connect(connection->sock, serv_addr, addrlen) == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK);
106 +#else /* !WIN32 (sane operating systems) */
107 +static int do_connect_fail(mpd_Connection * connection, const struct sockaddr *serv_addr, int addrlen)
109 + int flags = fcntl(connection->sock, F_GETFL, 0);
110 + fcntl(connection->sock, F_SETFL, flags | O_NONBLOCK);
111 + return (connect(connection->sock, serv_addr, addrlen) < 0 && errno != EINPROGRESS);
116 +static int mpd_connect(mpd_Connection * connection, const char *host, int port, float timeout)
119 + char service[INTLEN + 1];
120 + struct addrinfo hints;
121 + struct addrinfo *res = NULL;
122 + struct addrinfo *addrinfo = NULL;
127 + hints.ai_flags = AI_ADDRCONFIG;
128 + hints.ai_family = PF_UNSPEC;
129 + hints.ai_socktype = SOCK_STREAM;
130 + hints.ai_protocol = IPPROTO_TCP;
131 + hints.ai_addrlen = 0;
132 + hints.ai_addr = NULL;
133 + hints.ai_canonname = NULL;
134 + hints.ai_next = NULL;
136 + snprintf(service, sizeof(service), "%i", port);
138 + error = getaddrinfo(host, service, &hints, &addrinfo);
141 + snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH, "host \"%s\" not found: %s", host, gai_strerror(error));
142 + connection->error = MPD_ERROR_UNKHOST;
146 + for (res = addrinfo; res; res = res->ai_next) {
147 + /* create socket */
148 + connection->sock = socket(res->ai_family, SOCK_STREAM, res->ai_protocol);
149 + if (connection->sock < 0) {
150 + snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH, "problems creating socket: %s", strerror(errno));
151 + connection->error = MPD_ERROR_SYSTEM;
152 + freeaddrinfo(addrinfo);
156 + mpd_setConnectionTimeout(connection, timeout);
158 + /* connect stuff */
159 + if (do_connect_fail(connection, res->ai_addr, res->ai_addrlen)) {
160 + /* try the next address family */
161 + closesocket(connection->sock);
162 + connection->sock = -1;
167 + freeaddrinfo(addrinfo);
169 + if (connection->sock < 0) {
170 + snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH,
171 + "problems connecting to \"%s\" on port %i: %s", host, port, strerror(errno));
172 + connection->error = MPD_ERROR_CONNPORT;
179 +#else /* !MPD_HAVE_GAI */
180 +static int mpd_connect(mpd_Connection * connection, const char *host, int port, float timeout)
182 + struct hostent *he;
183 + struct sockaddr *dest;
185 + struct sockaddr_in sin;
187 + if (!(he = gethostbyname(host))) {
188 + snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH, "host \"%s\" not found", host);
189 + connection->error = MPD_ERROR_UNKHOST;
193 + memset(&sin, 0, sizeof(struct sockaddr_in));
194 + /*dest.sin_family = he->h_addrtype; */
195 + sin.sin_family = AF_INET;
196 + sin.sin_port = htons(port);
198 + switch (he->h_addrtype) {
200 + memcpy((char *) &sin.sin_addr.s_addr, (char *) he->h_addr, he->h_length);
201 + dest = (struct sockaddr *) &sin;
202 + destlen = sizeof(struct sockaddr_in);
205 + strcpy(connection->errorStr, "address type is not IPv4");
206 + connection->error = MPD_ERROR_SYSTEM;
211 + if ((connection->sock = socket(dest->sa_family, SOCK_STREAM, 0)) < 0) {
212 + strcpy(connection->errorStr, "problems creating socket");
213 + connection->error = MPD_ERROR_SYSTEM;
217 + mpd_setConnectionTimeout(connection, timeout);
219 + /* connect stuff */
220 + if (do_connect_fail(connection, dest, destlen)) {
221 + snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH,
222 + "problems connecting to \"%s\" on port" " %i", host, port);
223 + connection->error = MPD_ERROR_CONNPORT;
229 +#endif /* !MPD_HAVE_GAI */
231 +char *mpdTagItemKeys[MPD_TAG_NUM_OF_ITEM_TYPES] = {
247 +static char *mpd_sanitizeArg(const char *arg)
251 + register const char *c;
254 + /* instead of counting in that loop above, just
255 + * use a bit more memory and half running time
257 + ret = malloc(strlen(arg) * 2 + 1);
261 + for (i = strlen(arg) + 1; i != 0; --i) {
262 + if (*c == '"' || *c == '\\')
270 +static mpd_ReturnElement *mpd_newReturnElement(const char *name, const char *value)
272 + mpd_ReturnElement *ret = malloc(sizeof(mpd_ReturnElement));
274 + ret->name = strdup(name);
275 + ret->value = strdup(value);
280 +static void mpd_freeReturnElement(mpd_ReturnElement * re)
287 +void mpd_setConnectionTimeout(mpd_Connection * connection, float timeout)
289 + connection->timeout.tv_sec = (int) timeout;
290 + connection->timeout.tv_usec = (int) (timeout * 1e6 - connection->timeout.tv_sec * 1000000 + 0.5);
293 +static int mpd_parseWelcome(mpd_Connection * connection, const char *host, int port, char *rt, char *output)
299 + if (strncmp(output, MPD_WELCOME_MESSAGE, strlen(MPD_WELCOME_MESSAGE))) {
300 + snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH,
301 + "mpd not running on port %i on host \"%s\"", port, host);
302 + connection->error = MPD_ERROR_NOTMPD;
306 + tmp = &output[strlen(MPD_WELCOME_MESSAGE)];
308 + for (i = 0; i < 3; i++) {
310 + connection->version[i] = strtol(tmp, &test, 10);
312 + if (!tmp || (test[0] != '.' && test[0] != '\0')) {
313 + snprintf(connection->errorStr,
314 + MPD_ERRORSTR_MAX_LENGTH,
315 + "error parsing version number at " "\"%s\"", &output[strlen(MPD_WELCOME_MESSAGE)]);
316 + connection->error = MPD_ERROR_NOTMPD;
325 +mpd_Connection *mpd_newConnection(const char *host, int port, float timeout)
329 + char *output = NULL;
330 + mpd_Connection *connection = malloc(sizeof(mpd_Connection));
333 + strcpy(connection->buffer, "");
334 + connection->buflen = 0;
335 + connection->bufstart = 0;
336 + strcpy(connection->errorStr, "");
337 + connection->error = 0;
338 + connection->doneProcessing = 0;
339 + connection->commandList = 0;
340 + connection->listOks = 0;
341 + connection->doneListOk = 0;
342 + connection->returnElement = NULL;
343 + connection->request = NULL;
345 + if (winsock_dll_error(connection))
348 + if (mpd_connect(connection, host, port, timeout) < 0)
351 + while (!(rt = strstr(connection->buffer, "\n"))) {
352 + tv.tv_sec = connection->timeout.tv_sec;
353 + tv.tv_usec = connection->timeout.tv_usec;
355 + FD_SET(connection->sock, &fds);
356 + if ((err = select(connection->sock + 1, &fds, NULL, NULL, &tv)) == 1) {
358 + readed = recv(connection->sock,
359 + &(connection->buffer[connection->buflen]), MPD_BUFFER_MAX_LENGTH - connection->buflen, 0);
361 + snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH,
362 + "problems getting a response from" " \"%s\" on port %i : %s", host, port, strerror(errno));
363 + connection->error = MPD_ERROR_NORESPONSE;
366 + connection->buflen += readed;
367 + connection->buffer[connection->buflen] = '\0';
368 + } else if (err < 0) {
369 + if (SELECT_ERRNO_IGNORE)
371 + snprintf(connection->errorStr,
372 + MPD_ERRORSTR_MAX_LENGTH, "problems connecting to \"%s\" on port" " %i", host, port);
373 + connection->error = MPD_ERROR_CONNPORT;
376 + snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH,
377 + "timeout in attempting to get a response from" " \"%s\" on port %i", host, port);
378 + connection->error = MPD_ERROR_NORESPONSE;
384 + output = strdup(connection->buffer);
385 + strcpy(connection->buffer, rt + 1);
386 + connection->buflen = strlen(connection->buffer);
388 + if (mpd_parseWelcome(connection, host, port, rt, output) == 0)
389 + connection->doneProcessing = 1;
396 +void mpd_clearError(mpd_Connection * connection)
398 + connection->error = 0;
399 + connection->errorStr[0] = '\0';
402 +void mpd_closeConnection(mpd_Connection * connection)
404 + closesocket(connection->sock);
405 + if (connection->returnElement)
406 + free(connection->returnElement);
407 + if (connection->request)
408 + free(connection->request);
413 +static void mpd_executeCommand(mpd_Connection * connection, char *command)
418 + char *commandPtr = command;
419 + int commandLen = strlen(command);
421 + if (!connection->doneProcessing && !connection->commandList) {
422 + strcpy(connection->errorStr, "not done processing current command");
423 + connection->error = 1;
427 + mpd_clearError(connection);
430 + FD_SET(connection->sock, &fds);
431 + tv.tv_sec = connection->timeout.tv_sec;
432 + tv.tv_usec = connection->timeout.tv_usec;
434 + while ((ret = select(connection->sock + 1, NULL, &fds, NULL, &tv) == 1) || (ret == -1 && SELECT_ERRNO_IGNORE)) {
435 + ret = send(connection->sock, commandPtr, commandLen, MSG_DONTWAIT);
437 + if (SENDRECV_ERRNO_IGNORE)
439 + snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH, "problems giving command \"%s\"", command);
440 + connection->error = MPD_ERROR_SENDING;
447 + if (commandLen <= 0)
451 + if (commandLen > 0) {
453 + snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH, "timeout sending command \"%s\"", command);
454 + connection->error = MPD_ERROR_TIMEOUT;
458 + if (!connection->commandList)
459 + connection->doneProcessing = 0;
460 + else if (connection->commandList == COMMAND_LIST_OK) {
461 + connection->listOks++;
465 +static void mpd_getNextReturnElement(mpd_Connection * connection)
467 + char *output = NULL;
470 + char *value = NULL;
475 + char *bufferCheck = NULL;
479 + if (connection->returnElement)
480 + mpd_freeReturnElement(connection->returnElement);
481 + connection->returnElement = NULL;
483 + if (connection->doneProcessing || (connection->listOks && connection->doneListOk)) {
484 + strcpy(connection->errorStr, "already done processing current command");
485 + connection->error = 1;
489 + bufferCheck = connection->buffer + connection->bufstart;
490 + while (connection->bufstart >= connection->buflen || !(rt = strchr(bufferCheck, '\n'))) {
491 + if (connection->buflen >= MPD_BUFFER_MAX_LENGTH) {
492 + memmove(connection->buffer,
493 + connection->buffer + connection->bufstart, connection->buflen - connection->bufstart + 1);
494 + connection->buflen -= connection->bufstart;
495 + connection->bufstart = 0;
497 + if (connection->buflen >= MPD_BUFFER_MAX_LENGTH) {
498 + strcpy(connection->errorStr, "buffer overrun");
499 + connection->error = MPD_ERROR_BUFFEROVERRUN;
500 + connection->doneProcessing = 1;
501 + connection->doneListOk = 0;
504 + bufferCheck = connection->buffer + connection->buflen;
505 + tv.tv_sec = connection->timeout.tv_sec;
506 + tv.tv_usec = connection->timeout.tv_usec;
508 + FD_SET(connection->sock, &fds);
509 + if ((err = select(connection->sock + 1, &fds, NULL, NULL, &tv) == 1)) {
510 + readed = recv(connection->sock,
511 + connection->buffer + connection->buflen,
512 + MPD_BUFFER_MAX_LENGTH - connection->buflen, MSG_DONTWAIT);
513 + if (readed < 0 && SENDRECV_ERRNO_IGNORE) {
517 + strcpy(connection->errorStr, "connection" " closed");
518 + connection->error = MPD_ERROR_CONNCLOSED;
519 + connection->doneProcessing = 1;
520 + connection->doneListOk = 0;
523 + connection->buflen += readed;
524 + connection->buffer[connection->buflen] = '\0';
525 + } else if (err < 0 && SELECT_ERRNO_IGNORE)
528 + strcpy(connection->errorStr, "connection timeout");
529 + connection->error = MPD_ERROR_TIMEOUT;
530 + connection->doneProcessing = 1;
531 + connection->doneListOk = 0;
537 + output = connection->buffer + connection->bufstart;
538 + connection->bufstart = rt - connection->buffer + 1;
540 + if (strcmp(output, "OK") == 0) {
541 + if (connection->listOks > 0) {
542 + strcpy(connection->errorStr, "expected more list_OK's");
543 + connection->error = 1;
545 + connection->listOks = 0;
546 + connection->doneProcessing = 1;
547 + connection->doneListOk = 0;
551 + if (strcmp(output, "list_OK") == 0) {
552 + if (!connection->listOks) {
553 + strcpy(connection->errorStr, "got an unexpected list_OK");
554 + connection->error = 1;
556 + connection->doneListOk = 1;
557 + connection->listOks--;
562 + if (strncmp(output, "ACK", strlen("ACK")) == 0) {
567 + strcpy(connection->errorStr, output);
568 + connection->error = MPD_ERROR_ACK;
569 + connection->errorCode = MPD_ACK_ERROR_UNK;
570 + connection->errorAt = MPD_ERROR_AT_UNK;
571 + connection->doneProcessing = 1;
572 + connection->doneListOk = 0;
574 + needle = strchr(output, '[');
577 + val = strtol(needle + 1, &test, 10);
580 + connection->errorCode = val;
581 + val = strtol(test + 1, &test, 10);
584 + connection->errorAt = val;
588 + tok = strchr(output, ':');
591 + pos = tok - output;
596 + if (value[0] == ' ') {
597 + connection->returnElement = mpd_newReturnElement(name, &(value[1]));
599 + snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH, "error parsing: %s:%s", name, value);
600 + connection->error = 1;
604 +void mpd_finishCommand(mpd_Connection * connection)
606 + while (!connection->doneProcessing) {
607 + if (connection->doneListOk)
608 + connection->doneListOk = 0;
609 + mpd_getNextReturnElement(connection);
613 +static void mpd_finishListOkCommand(mpd_Connection * connection)
615 + while (!connection->doneProcessing && connection->listOks && !connection->doneListOk) {
616 + mpd_getNextReturnElement(connection);
620 +int mpd_nextListOkCommand(mpd_Connection * connection)
622 + mpd_finishListOkCommand(connection);
623 + if (!connection->doneProcessing)
624 + connection->doneListOk = 0;
625 + if (connection->listOks == 0 || connection->doneProcessing)
630 +void mpd_sendStatusCommand(mpd_Connection * connection)
632 + mpd_executeCommand(connection, "status\n");
635 +mpd_Status *mpd_getStatus(mpd_Connection * connection)
637 + mpd_Status *status;
639 + /*mpd_executeCommand(connection,"status\n");
641 + if(connection->error) return NULL; */
643 + if (connection->doneProcessing || (connection->listOks && connection->doneListOk)) {
647 + if (!connection->returnElement)
648 + mpd_getNextReturnElement(connection);
650 + status = malloc(sizeof(mpd_Status));
651 + status->volume = -1;
652 + status->repeat = 0;
653 + status->random = 0;
654 + status->playlist = -1;
655 + status->playlistLength = -1;
656 + status->state = -1;
658 + status->songid = 0;
659 + status->elapsedTime = 0;
660 + status->totalTime = 0;
661 + status->bitRate = 0;
662 + status->sampleRate = 0;
664 + status->channels = 0;
665 + status->crossfade = -1;
666 + status->error = NULL;
667 + status->updatingDb = 0;
669 + if (connection->error) {
673 + while (connection->returnElement) {
674 + mpd_ReturnElement *re = connection->returnElement;
675 + if (strcmp(re->name, "volume") == 0) {
676 + status->volume = atoi(re->value);
677 + } else if (strcmp(re->name, "repeat") == 0) {
678 + status->repeat = atoi(re->value);
679 + } else if (strcmp(re->name, "random") == 0) {
680 + status->random = atoi(re->value);
681 + } else if (strcmp(re->name, "playlist") == 0) {
682 + status->playlist = strtol(re->value, NULL, 10);
683 + } else if (strcmp(re->name, "playlistlength") == 0) {
684 + status->playlistLength = atoi(re->value);
685 + } else if (strcmp(re->name, "bitrate") == 0) {
686 + status->bitRate = atoi(re->value);
687 + } else if (strcmp(re->name, "state") == 0) {
688 + if (strcmp(re->value, "play") == 0) {
689 + status->state = MPD_STATUS_STATE_PLAY;
690 + } else if (strcmp(re->value, "stop") == 0) {
691 + status->state = MPD_STATUS_STATE_STOP;
692 + } else if (strcmp(re->value, "pause") == 0) {
693 + status->state = MPD_STATUS_STATE_PAUSE;
695 + status->state = MPD_STATUS_STATE_UNKNOWN;
697 + } else if (strcmp(re->name, "song") == 0) {
698 + status->song = atoi(re->value);
699 + } else if (strcmp(re->name, "songid") == 0) {
700 + status->songid = atoi(re->value);
701 + } else if (strcmp(re->name, "time") == 0) {
702 + char *tok = strchr(re->value, ':');
703 + /* the second strchr below is a safety check */
704 + if (tok && (strchr(tok, 0) > (tok + 1))) {
705 + /* atoi stops at the first non-[0-9] char: */
706 + status->elapsedTime = atoi(re->value);
707 + status->totalTime = atoi(tok + 1);
709 + } else if (strcmp(re->name, "error") == 0) {
710 + status->error = strdup(re->value);
711 + } else if (strcmp(re->name, "xfade") == 0) {
712 + status->crossfade = atoi(re->value);
713 + } else if (strcmp(re->name, "updating_db") == 0) {
714 + status->updatingDb = atoi(re->value);
715 + } else if (strcmp(re->name, "audio") == 0) {
716 + char *tok = strchr(re->value, ':');
717 + if (tok && (strchr(tok, 0) > (tok + 1))) {
718 + status->sampleRate = atoi(re->value);
719 + status->bits = atoi(++tok);
720 + tok = strchr(tok, ':');
721 + if (tok && (strchr(tok, 0) > (tok + 1)))
722 + status->channels = atoi(tok + 1);
726 + mpd_getNextReturnElement(connection);
727 + if (connection->error) {
733 + if (connection->error) {
736 + } else if (status->state < 0) {
737 + strcpy(connection->errorStr, "state not found");
738 + connection->error = 1;
746 +void mpd_freeStatus(mpd_Status * status)
749 + free(status->error);
753 +void mpd_sendStatsCommand(mpd_Connection * connection)
755 + mpd_executeCommand(connection, "stats\n");
758 +mpd_Stats *mpd_getStats(mpd_Connection * connection)
762 + /*mpd_executeCommand(connection,"stats\n");
764 + if(connection->error) return NULL; */
766 + if (connection->doneProcessing || (connection->listOks && connection->doneListOk)) {
770 + if (!connection->returnElement)
771 + mpd_getNextReturnElement(connection);
773 + stats = malloc(sizeof(mpd_Stats));
774 + stats->numberOfArtists = 0;
775 + stats->numberOfAlbums = 0;
776 + stats->numberOfSongs = 0;
778 + stats->dbUpdateTime = 0;
779 + stats->playTime = 0;
780 + stats->dbPlayTime = 0;
782 + if (connection->error) {
786 + while (connection->returnElement) {
787 + mpd_ReturnElement *re = connection->returnElement;
788 + if (strcmp(re->name, "artists") == 0) {
789 + stats->numberOfArtists = atoi(re->value);
790 + } else if (strcmp(re->name, "albums") == 0) {
791 + stats->numberOfAlbums = atoi(re->value);
792 + } else if (strcmp(re->name, "songs") == 0) {
793 + stats->numberOfSongs = atoi(re->value);
794 + } else if (strcmp(re->name, "uptime") == 0) {
795 + stats->uptime = strtol(re->value, NULL, 10);
796 + } else if (strcmp(re->name, "db_update") == 0) {
797 + stats->dbUpdateTime = strtol(re->value, NULL, 10);
798 + } else if (strcmp(re->name, "playtime") == 0) {
799 + stats->playTime = strtol(re->value, NULL, 10);
800 + } else if (strcmp(re->name, "db_playtime") == 0) {
801 + stats->dbPlayTime = strtol(re->value, NULL, 10);
804 + mpd_getNextReturnElement(connection);
805 + if (connection->error) {
811 + if (connection->error) {
819 +void mpd_freeStats(mpd_Stats * stats)
824 +mpd_SearchStats *mpd_getSearchStats(mpd_Connection * connection)
826 + mpd_SearchStats *stats;
827 + mpd_ReturnElement *re;
829 + if (connection->doneProcessing || (connection->listOks && connection->doneListOk)) {
833 + if (!connection->returnElement)
834 + mpd_getNextReturnElement(connection);
836 + if (connection->error)
839 + stats = malloc(sizeof(mpd_SearchStats));
840 + stats->numberOfSongs = 0;
841 + stats->playTime = 0;
843 + while (connection->returnElement) {
844 + re = connection->returnElement;
846 + if (strcmp(re->name, "songs") == 0) {
847 + stats->numberOfSongs = atoi(re->value);
848 + } else if (strcmp(re->name, "playtime") == 0) {
849 + stats->playTime = strtol(re->value, NULL, 10);
852 + mpd_getNextReturnElement(connection);
853 + if (connection->error) {
859 + if (connection->error) {
867 +void mpd_freeSearchStats(mpd_SearchStats * stats)
872 +static void mpd_initSong(mpd_Song * song)
875 + song->artist = NULL;
876 + song->album = NULL;
877 + song->track = NULL;
878 + song->title = NULL;
881 + /* added by Qball */
882 + song->genre = NULL;
883 + song->composer = NULL;
884 + song->performer = NULL;
886 + song->comment = NULL;
888 + song->time = MPD_SONG_NO_TIME;
889 + song->pos = MPD_SONG_NO_NUM;
890 + song->id = MPD_SONG_NO_ID;
893 +static void mpd_finishSong(mpd_Song * song)
898 + free(song->artist);
911 + if (song->composer)
912 + free(song->composer);
916 + free(song->comment);
919 +mpd_Song *mpd_newSong(void)
921 + mpd_Song *ret = malloc(sizeof(mpd_Song));
928 +void mpd_freeSong(mpd_Song * song)
930 + mpd_finishSong(song);
934 +mpd_Song *mpd_songDup(mpd_Song * song)
936 + mpd_Song *ret = mpd_newSong();
939 + ret->file = strdup(song->file);
941 + ret->artist = strdup(song->artist);
943 + ret->album = strdup(song->album);
945 + ret->title = strdup(song->title);
947 + ret->track = strdup(song->track);
949 + ret->name = strdup(song->name);
951 + ret->date = strdup(song->date);
953 + ret->genre = strdup(song->genre);
954 + if (song->composer)
955 + ret->composer = strdup(song->composer);
957 + ret->disc = strdup(song->disc);
959 + ret->comment = strdup(song->comment);
960 + ret->time = song->time;
961 + ret->pos = song->pos;
962 + ret->id = song->id;
967 +static void mpd_initDirectory(mpd_Directory * directory)
969 + directory->path = NULL;
972 +static void mpd_finishDirectory(mpd_Directory * directory)
974 + if (directory->path)
975 + free(directory->path);
978 +mpd_Directory *mpd_newDirectory(void)
980 + mpd_Directory *directory = malloc(sizeof(mpd_Directory));;
982 + mpd_initDirectory(directory);
987 +void mpd_freeDirectory(mpd_Directory * directory)
989 + mpd_finishDirectory(directory);
994 +mpd_Directory *mpd_directoryDup(mpd_Directory * directory)
996 + mpd_Directory *ret = mpd_newDirectory();
998 + if (directory->path)
999 + ret->path = strdup(directory->path);
1004 +static void mpd_initPlaylistFile(mpd_PlaylistFile * playlist)
1006 + playlist->path = NULL;
1009 +static void mpd_finishPlaylistFile(mpd_PlaylistFile * playlist)
1011 + if (playlist->path)
1012 + free(playlist->path);
1015 +mpd_PlaylistFile *mpd_newPlaylistFile(void)
1017 + mpd_PlaylistFile *playlist = malloc(sizeof(mpd_PlaylistFile));
1019 + mpd_initPlaylistFile(playlist);
1024 +void mpd_freePlaylistFile(mpd_PlaylistFile * playlist)
1026 + mpd_finishPlaylistFile(playlist);
1030 +mpd_PlaylistFile *mpd_playlistFileDup(mpd_PlaylistFile * playlist)
1032 + mpd_PlaylistFile *ret = mpd_newPlaylistFile();
1034 + if (playlist->path)
1035 + ret->path = strdup(playlist->path);
1040 +static void mpd_initInfoEntity(mpd_InfoEntity * entity)
1042 + entity->info.directory = NULL;
1045 +static void mpd_finishInfoEntity(mpd_InfoEntity * entity)
1047 + if (entity->info.directory) {
1048 + if (entity->type == MPD_INFO_ENTITY_TYPE_DIRECTORY) {
1049 + mpd_freeDirectory(entity->info.directory);
1050 + } else if (entity->type == MPD_INFO_ENTITY_TYPE_SONG) {
1051 + mpd_freeSong(entity->info.song);
1052 + } else if (entity->type == MPD_INFO_ENTITY_TYPE_PLAYLISTFILE) {
1053 + mpd_freePlaylistFile(entity->info.playlistFile);
1058 +mpd_InfoEntity *mpd_newInfoEntity(void)
1060 + mpd_InfoEntity *entity = malloc(sizeof(mpd_InfoEntity));
1062 + mpd_initInfoEntity(entity);
1067 +void mpd_freeInfoEntity(mpd_InfoEntity * entity)
1069 + mpd_finishInfoEntity(entity);
1073 +static void mpd_sendInfoCommand(mpd_Connection * connection, char *command)
1075 + mpd_executeCommand(connection, command);
1078 +mpd_InfoEntity *mpd_getNextInfoEntity(mpd_Connection * connection)
1080 + mpd_InfoEntity *entity = NULL;
1082 + if (connection->doneProcessing || (connection->listOks && connection->doneListOk)) {
1086 + if (!connection->returnElement)
1087 + mpd_getNextReturnElement(connection);
1089 + if (connection->returnElement) {
1090 + if (strcmp(connection->returnElement->name, "file") == 0) {
1091 + entity = mpd_newInfoEntity();
1092 + entity->type = MPD_INFO_ENTITY_TYPE_SONG;
1093 + entity->info.song = mpd_newSong();
1094 + entity->info.song->file = strdup(connection->returnElement->value);
1095 + } else if (strcmp(connection->returnElement->name, "directory") == 0) {
1096 + entity = mpd_newInfoEntity();
1097 + entity->type = MPD_INFO_ENTITY_TYPE_DIRECTORY;
1098 + entity->info.directory = mpd_newDirectory();
1099 + entity->info.directory->path = strdup(connection->returnElement->value);
1100 + } else if (strcmp(connection->returnElement->name, "playlist") == 0) {
1101 + entity = mpd_newInfoEntity();
1102 + entity->type = MPD_INFO_ENTITY_TYPE_PLAYLISTFILE;
1103 + entity->info.playlistFile = mpd_newPlaylistFile();
1104 + entity->info.playlistFile->path = strdup(connection->returnElement->value);
1105 + } else if (strcmp(connection->returnElement->name, "cpos") == 0) {
1106 + entity = mpd_newInfoEntity();
1107 + entity->type = MPD_INFO_ENTITY_TYPE_SONG;
1108 + entity->info.song = mpd_newSong();
1109 + entity->info.song->pos = atoi(connection->returnElement->value);
1111 + connection->error = 1;
1112 + strcpy(connection->errorStr, "problem parsing song info");
1118 + mpd_getNextReturnElement(connection);
1119 + while (connection->returnElement) {
1120 + mpd_ReturnElement *re = connection->returnElement;
1122 + if (strcmp(re->name, "file") == 0)
1124 + else if (strcmp(re->name, "directory") == 0)
1126 + else if (strcmp(re->name, "playlist") == 0)
1128 + else if (strcmp(re->name, "cpos") == 0)
1131 + if (entity->type == MPD_INFO_ENTITY_TYPE_SONG && strlen(re->value)) {
1132 + if (!entity->info.song->artist && strcmp(re->name, "Artist") == 0) {
1133 + entity->info.song->artist = strdup(re->value);
1134 + } else if (!entity->info.song->album && strcmp(re->name, "Album") == 0) {
1135 + entity->info.song->album = strdup(re->value);
1136 + } else if (!entity->info.song->title && strcmp(re->name, "Title") == 0) {
1137 + entity->info.song->title = strdup(re->value);
1138 + } else if (!entity->info.song->track && strcmp(re->name, "Track") == 0) {
1139 + entity->info.song->track = strdup(re->value);
1140 + } else if (!entity->info.song->name && strcmp(re->name, "Name") == 0) {
1141 + entity->info.song->name = strdup(re->value);
1142 + } else if (entity->info.song->time == MPD_SONG_NO_TIME && strcmp(re->name, "Time") == 0) {
1143 + entity->info.song->time = atoi(re->value);
1144 + } else if (entity->info.song->pos == MPD_SONG_NO_NUM && strcmp(re->name, "Pos") == 0) {
1145 + entity->info.song->pos = atoi(re->value);
1146 + } else if (entity->info.song->id == MPD_SONG_NO_ID && strcmp(re->name, "Id") == 0) {
1147 + entity->info.song->id = atoi(re->value);
1148 + } else if (!entity->info.song->date && strcmp(re->name, "Date") == 0) {
1149 + entity->info.song->date = strdup(re->value);
1150 + } else if (!entity->info.song->genre && strcmp(re->name, "Genre") == 0) {
1151 + entity->info.song->genre = strdup(re->value);
1152 + } else if (!entity->info.song->composer && strcmp(re->name, "Composer") == 0) {
1153 + entity->info.song->composer = strdup(re->value);
1154 + } else if (!entity->info.song->performer && strcmp(re->name, "Performer") == 0) {
1155 + entity->info.song->performer = strdup(re->value);
1156 + } else if (!entity->info.song->disc && strcmp(re->name, "Disc") == 0) {
1157 + entity->info.song->disc = strdup(re->value);
1158 + } else if (!entity->info.song->comment && strcmp(re->name, "Comment") == 0) {
1159 + entity->info.song->comment = strdup(re->value);
1161 + } else if (entity->type == MPD_INFO_ENTITY_TYPE_DIRECTORY) {
1162 + } else if (entity->type == MPD_INFO_ENTITY_TYPE_PLAYLISTFILE) {
1165 + mpd_getNextReturnElement(connection);
1171 +static char *mpd_getNextReturnElementNamed(mpd_Connection * connection, const char *name)
1173 + if (connection->doneProcessing || (connection->listOks && connection->doneListOk)) {
1177 + mpd_getNextReturnElement(connection);
1178 + while (connection->returnElement) {
1179 + mpd_ReturnElement *re = connection->returnElement;
1181 + if (strcmp(re->name, name) == 0)
1182 + return strdup(re->value);
1183 + mpd_getNextReturnElement(connection);
1189 +char *mpd_getNextTag(mpd_Connection * connection, int type)
1191 + if (type < 0 || type >= MPD_TAG_NUM_OF_ITEM_TYPES || type == MPD_TAG_ITEM_ANY)
1193 + if (type == MPD_TAG_ITEM_FILENAME)
1194 + return mpd_getNextReturnElementNamed(connection, "file");
1195 + return mpd_getNextReturnElementNamed(connection, mpdTagItemKeys[type]);
1198 +char *mpd_getNextArtist(mpd_Connection * connection)
1200 + return mpd_getNextReturnElementNamed(connection, "Artist");
1203 +char *mpd_getNextAlbum(mpd_Connection * connection)
1205 + return mpd_getNextReturnElementNamed(connection, "Album");
1208 +void mpd_sendPlaylistInfoCommand(mpd_Connection * connection, int songPos)
1210 + int len = strlen("playlistinfo") + 2 + INTLEN + 3;
1211 + char *string = malloc(len);
1212 + snprintf(string, len, "playlistinfo \"%i\"\n", songPos);
1213 + mpd_sendInfoCommand(connection, string);
1217 +void mpd_sendPlaylistIdCommand(mpd_Connection * connection, int id)
1219 + int len = strlen("playlistid") + 2 + INTLEN + 3;
1220 + char *string = malloc(len);
1221 + snprintf(string, len, "playlistid \"%i\"\n", id);
1222 + mpd_sendInfoCommand(connection, string);
1226 +void mpd_sendPlChangesCommand(mpd_Connection * connection, long long playlist)
1228 + int len = strlen("plchanges") + 2 + LONGLONGLEN + 3;
1229 + char *string = malloc(len);
1230 + snprintf(string, len, "plchanges \"%lld\"\n", playlist);
1231 + mpd_sendInfoCommand(connection, string);
1235 +void mpd_sendPlChangesPosIdCommand(mpd_Connection * connection, long long playlist)
1237 + int len = strlen("plchangesposid") + 2 + LONGLONGLEN + 3;
1238 + char *string = malloc(len);
1239 + snprintf(string, len, "plchangesposid \"%lld\"\n", playlist);
1240 + mpd_sendInfoCommand(connection, string);
1244 +void mpd_sendListallCommand(mpd_Connection * connection, const char *dir)
1246 + char *sDir = mpd_sanitizeArg(dir);
1247 + int len = strlen("listall") + 2 + strlen(sDir) + 3;
1248 + char *string = malloc(len);
1249 + snprintf(string, len, "listall \"%s\"\n", sDir);
1250 + mpd_sendInfoCommand(connection, string);
1255 +void mpd_sendListallInfoCommand(mpd_Connection * connection, const char *dir)
1257 + char *sDir = mpd_sanitizeArg(dir);
1258 + int len = strlen("listallinfo") + 2 + strlen(sDir) + 3;
1259 + char *string = malloc(len);
1260 + snprintf(string, len, "listallinfo \"%s\"\n", sDir);
1261 + mpd_sendInfoCommand(connection, string);
1266 +void mpd_sendLsInfoCommand(mpd_Connection * connection, const char *dir)
1268 + char *sDir = mpd_sanitizeArg(dir);
1269 + int len = strlen("lsinfo") + 2 + strlen(sDir) + 3;
1270 + char *string = malloc(len);
1271 + snprintf(string, len, "lsinfo \"%s\"\n", sDir);
1272 + mpd_sendInfoCommand(connection, string);
1277 +void mpd_sendCurrentSongCommand(mpd_Connection * connection)
1279 + mpd_executeCommand(connection, "currentsong\n");
1282 +void mpd_sendSearchCommand(mpd_Connection * connection, int table, const char *str)
1284 + mpd_startSearch(connection, 0);
1285 + mpd_addConstraintSearch(connection, table, str);
1286 + mpd_commitSearch(connection);
1289 +void mpd_sendFindCommand(mpd_Connection * connection, int table, const char *str)
1291 + mpd_startSearch(connection, 1);
1292 + mpd_addConstraintSearch(connection, table, str);
1293 + mpd_commitSearch(connection);
1296 +void mpd_sendListCommand(mpd_Connection * connection, int table, const char *arg1)
1301 + if (table == MPD_TABLE_ARTIST)
1302 + strcpy(st, "artist");
1303 + else if (table == MPD_TABLE_ALBUM)
1304 + strcpy(st, "album");
1306 + connection->error = 1;
1307 + strcpy(connection->errorStr, "unknown table for list");
1311 + char *sanitArg1 = mpd_sanitizeArg(arg1);
1312 + len = strlen("list") + 1 + strlen(sanitArg1) + 2 + strlen(st) + 3;
1313 + string = malloc(len);
1314 + snprintf(string, len, "list %s \"%s\"\n", st, sanitArg1);
1317 + len = strlen("list") + 1 + strlen(st) + 2;
1318 + string = malloc(len);
1319 + snprintf(string, len, "list %s\n", st);
1321 + mpd_sendInfoCommand(connection, string);
1325 +void mpd_sendAddCommand(mpd_Connection * connection, const char *file)
1327 + char *sFile = mpd_sanitizeArg(file);
1328 + int len = strlen("add") + 2 + strlen(sFile) + 3;
1329 + char *string = malloc(len);
1330 + snprintf(string, len, "add \"%s\"\n", sFile);
1331 + mpd_executeCommand(connection, string);
1336 +int mpd_sendAddIdCommand(mpd_Connection * connection, const char *file)
1339 + char *sFile = mpd_sanitizeArg(file);
1340 + int len = strlen("addid") + 2 + strlen(sFile) + 3;
1341 + char *string = malloc(len);
1343 + snprintf(string, len, "addid \"%s\"\n", sFile);
1344 + mpd_sendInfoCommand(connection, string);
1348 + string = mpd_getNextReturnElementNamed(connection, "Id");
1350 + retval = atoi(string);
1357 +void mpd_sendDeleteCommand(mpd_Connection * connection, int songPos)
1359 + int len = strlen("delete") + 2 + INTLEN + 3;
1360 + char *string = malloc(len);
1361 + snprintf(string, len, "delete \"%i\"\n", songPos);
1362 + mpd_sendInfoCommand(connection, string);
1366 +void mpd_sendDeleteIdCommand(mpd_Connection * connection, int id)
1368 + int len = strlen("deleteid") + 2 + INTLEN + 3;
1369 + char *string = malloc(len);
1370 + snprintf(string, len, "deleteid \"%i\"\n", id);
1371 + mpd_sendInfoCommand(connection, string);
1375 +void mpd_sendSaveCommand(mpd_Connection * connection, const char *name)
1377 + char *sName = mpd_sanitizeArg(name);
1378 + int len = strlen("save") + 2 + strlen(sName) + 3;
1379 + char *string = malloc(len);
1380 + snprintf(string, len, "save \"%s\"\n", sName);
1381 + mpd_executeCommand(connection, string);
1386 +void mpd_sendLoadCommand(mpd_Connection * connection, const char *name)
1388 + char *sName = mpd_sanitizeArg(name);
1389 + int len = strlen("load") + 2 + strlen(sName) + 3;
1390 + char *string = malloc(len);
1391 + snprintf(string, len, "load \"%s\"\n", sName);
1392 + mpd_executeCommand(connection, string);
1397 +void mpd_sendRmCommand(mpd_Connection * connection, const char *name)
1399 + char *sName = mpd_sanitizeArg(name);
1400 + int len = strlen("rm") + 2 + strlen(sName) + 3;
1401 + char *string = malloc(len);
1402 + snprintf(string, len, "rm \"%s\"\n", sName);
1403 + mpd_executeCommand(connection, string);
1408 +void mpd_sendRenameCommand(mpd_Connection * connection, const char *from, const char *to)
1410 + char *sFrom = mpd_sanitizeArg(from);
1411 + char *sTo = mpd_sanitizeArg(to);
1412 + int len = strlen("rename") + 2 + strlen(sFrom) + 3 + strlen(sTo) + 3;
1413 + char *string = malloc(len);
1414 + snprintf(string, len, "rename \"%s\" \"%s\"\n", sFrom, sTo);
1415 + mpd_executeCommand(connection, string);
1421 +void mpd_sendShuffleCommand(mpd_Connection * connection)
1423 + mpd_executeCommand(connection, "shuffle\n");
1426 +void mpd_sendClearCommand(mpd_Connection * connection)
1428 + mpd_executeCommand(connection, "clear\n");
1431 +void mpd_sendPlayCommand(mpd_Connection * connection, int songPos)
1433 + int len = strlen("play") + 2 + INTLEN + 3;
1434 + char *string = malloc(len);
1435 + snprintf(string, len, "play \"%i\"\n", songPos);
1436 + mpd_sendInfoCommand(connection, string);
1440 +void mpd_sendPlayIdCommand(mpd_Connection * connection, int id)
1442 + int len = strlen("playid") + 2 + INTLEN + 3;
1443 + char *string = malloc(len);
1444 + snprintf(string, len, "playid \"%i\"\n", id);
1445 + mpd_sendInfoCommand(connection, string);
1449 +void mpd_sendStopCommand(mpd_Connection * connection)
1451 + mpd_executeCommand(connection, "stop\n");
1454 +void mpd_sendPauseCommand(mpd_Connection * connection, int pauseMode)
1456 + int len = strlen("pause") + 2 + INTLEN + 3;
1457 + char *string = malloc(len);
1458 + snprintf(string, len, "pause \"%i\"\n", pauseMode);
1459 + mpd_executeCommand(connection, string);
1463 +void mpd_sendNextCommand(mpd_Connection * connection)
1465 + mpd_executeCommand(connection, "next\n");
1468 +void mpd_sendMoveCommand(mpd_Connection * connection, int from, int to)
1470 + int len = strlen("move") + 2 + INTLEN + 3 + INTLEN + 3;
1471 + char *string = malloc(len);
1472 + snprintf(string, len, "move \"%i\" \"%i\"\n", from, to);
1473 + mpd_sendInfoCommand(connection, string);
1477 +void mpd_sendMoveIdCommand(mpd_Connection * connection, int id, int to)
1479 + int len = strlen("moveid") + 2 + INTLEN + 3 + INTLEN + 3;
1480 + char *string = malloc(len);
1481 + snprintf(string, len, "moveid \"%i\" \"%i\"\n", id, to);
1482 + mpd_sendInfoCommand(connection, string);
1486 +void mpd_sendSwapCommand(mpd_Connection * connection, int song1, int song2)
1488 + int len = strlen("swap") + 2 + INTLEN + 3 + INTLEN + 3;
1489 + char *string = malloc(len);
1490 + snprintf(string, len, "swap \"%i\" \"%i\"\n", song1, song2);
1491 + mpd_sendInfoCommand(connection, string);
1495 +void mpd_sendSwapIdCommand(mpd_Connection * connection, int id1, int id2)
1497 + int len = strlen("swapid") + 2 + INTLEN + 3 + INTLEN + 3;
1498 + char *string = malloc(len);
1499 + snprintf(string, len, "swapid \"%i\" \"%i\"\n", id1, id2);
1500 + mpd_sendInfoCommand(connection, string);
1504 +void mpd_sendSeekCommand(mpd_Connection * connection, int song, int time)
1506 + int len = strlen("seek") + 2 + INTLEN + 3 + INTLEN + 3;
1507 + char *string = malloc(len);
1508 + snprintf(string, len, "seek \"%i\" \"%i\"\n", song, time);
1509 + mpd_sendInfoCommand(connection, string);
1513 +void mpd_sendSeekIdCommand(mpd_Connection * connection, int id, int time)
1515 + int len = strlen("seekid") + 2 + INTLEN + 3 + INTLEN + 3;
1516 + char *string = malloc(len);
1517 + snprintf(string, len, "seekid \"%i\" \"%i\"\n", id, time);
1518 + mpd_sendInfoCommand(connection, string);
1522 +void mpd_sendUpdateCommand(mpd_Connection * connection, char *path)
1524 + char *sPath = mpd_sanitizeArg(path);
1525 + int len = strlen("update") + 2 + strlen(sPath) + 3;
1526 + char *string = malloc(len);
1527 + snprintf(string, len, "update \"%s\"\n", sPath);
1528 + mpd_sendInfoCommand(connection, string);
1533 +int mpd_getUpdateId(mpd_Connection * connection)
1538 + jobid = mpd_getNextReturnElementNamed(connection, "updating_db");
1540 + ret = atoi(jobid);
1547 +void mpd_sendPrevCommand(mpd_Connection * connection)
1549 + mpd_executeCommand(connection, "previous\n");
1552 +void mpd_sendRepeatCommand(mpd_Connection * connection, int repeatMode)
1554 + int len = strlen("repeat") + 2 + INTLEN + 3;
1555 + char *string = malloc(len);
1556 + snprintf(string, len, "repeat \"%i\"\n", repeatMode);
1557 + mpd_executeCommand(connection, string);
1561 +void mpd_sendRandomCommand(mpd_Connection * connection, int randomMode)
1563 + int len = strlen("random") + 2 + INTLEN + 3;
1564 + char *string = malloc(len);
1565 + snprintf(string, len, "random \"%i\"\n", randomMode);
1566 + mpd_executeCommand(connection, string);
1570 +void mpd_sendSetvolCommand(mpd_Connection * connection, int volumeChange)
1572 + int len = strlen("setvol") + 2 + INTLEN + 3;
1573 + char *string = malloc(len);
1574 + snprintf(string, len, "setvol \"%i\"\n", volumeChange);
1575 + mpd_executeCommand(connection, string);
1579 +void mpd_sendVolumeCommand(mpd_Connection * connection, int volumeChange)
1581 + int len = strlen("volume") + 2 + INTLEN + 3;
1582 + char *string = malloc(len);
1583 + snprintf(string, len, "volume \"%i\"\n", volumeChange);
1584 + mpd_executeCommand(connection, string);
1588 +void mpd_sendCrossfadeCommand(mpd_Connection * connection, int seconds)
1590 + int len = strlen("crossfade") + 2 + INTLEN + 3;
1591 + char *string = malloc(len);
1592 + snprintf(string, len, "crossfade \"%i\"\n", seconds);
1593 + mpd_executeCommand(connection, string);
1597 +void mpd_sendPasswordCommand(mpd_Connection * connection, const char *pass)
1599 + char *sPass = mpd_sanitizeArg(pass);
1600 + int len = strlen("password") + 2 + strlen(sPass) + 3;
1601 + char *string = malloc(len);
1602 + snprintf(string, len, "password \"%s\"\n", sPass);
1603 + mpd_executeCommand(connection, string);
1608 +void mpd_sendCommandListBegin(mpd_Connection * connection)
1610 + if (connection->commandList) {
1611 + strcpy(connection->errorStr, "already in command list mode");
1612 + connection->error = 1;
1615 + connection->commandList = COMMAND_LIST;
1616 + mpd_executeCommand(connection, "command_list_begin\n");
1619 +void mpd_sendCommandListOkBegin(mpd_Connection * connection)
1621 + if (connection->commandList) {
1622 + strcpy(connection->errorStr, "already in command list mode");
1623 + connection->error = 1;
1626 + connection->commandList = COMMAND_LIST_OK;
1627 + mpd_executeCommand(connection, "command_list_ok_begin\n");
1628 + connection->listOks = 0;
1631 +void mpd_sendCommandListEnd(mpd_Connection * connection)
1633 + if (!connection->commandList) {
1634 + strcpy(connection->errorStr, "not in command list mode");
1635 + connection->error = 1;
1638 + connection->commandList = 0;
1639 + mpd_executeCommand(connection, "command_list_end\n");
1642 +void mpd_sendOutputsCommand(mpd_Connection * connection)
1644 + mpd_executeCommand(connection, "outputs\n");
1647 +mpd_OutputEntity *mpd_getNextOutput(mpd_Connection * connection)
1649 + mpd_OutputEntity *output = NULL;
1651 + if (connection->doneProcessing || (connection->listOks && connection->doneListOk)) {
1655 + if (connection->error)
1658 + output = malloc(sizeof(mpd_OutputEntity));
1660 + output->name = NULL;
1661 + output->enabled = 0;
1663 + if (!connection->returnElement)
1664 + mpd_getNextReturnElement(connection);
1666 + while (connection->returnElement) {
1667 + mpd_ReturnElement *re = connection->returnElement;
1668 + if (strcmp(re->name, "outputid") == 0) {
1669 + if (output != NULL && output->id >= 0)
1671 + output->id = atoi(re->value);
1672 + } else if (strcmp(re->name, "outputname") == 0) {
1673 + output->name = strdup(re->value);
1674 + } else if (strcmp(re->name, "outputenabled") == 0) {
1675 + output->enabled = atoi(re->value);
1678 + mpd_getNextReturnElement(connection);
1679 + if (connection->error) {
1689 +void mpd_sendEnableOutputCommand(mpd_Connection * connection, int outputId)
1691 + int len = strlen("enableoutput") + 2 + INTLEN + 3;
1692 + char *string = malloc(len);
1693 + snprintf(string, len, "enableoutput \"%i\"\n", outputId);
1694 + mpd_executeCommand(connection, string);
1698 +void mpd_sendDisableOutputCommand(mpd_Connection * connection, int outputId)
1700 + int len = strlen("disableoutput") + 2 + INTLEN + 3;
1701 + char *string = malloc(len);
1702 + snprintf(string, len, "disableoutput \"%i\"\n", outputId);
1703 + mpd_executeCommand(connection, string);
1707 +void mpd_freeOutputElement(mpd_OutputEntity * output)
1709 + free(output->name);
1714 + * mpd_sendNotCommandsCommand
1715 + * odd naming, but it gets the not allowed commands
1718 +void mpd_sendNotCommandsCommand(mpd_Connection * connection)
1720 + mpd_executeCommand(connection, "notcommands\n");
1724 + * mpd_sendCommandsCommand
1725 + * odd naming, but it gets the allowed commands
1727 +void mpd_sendCommandsCommand(mpd_Connection * connection)
1729 + mpd_executeCommand(connection, "commands\n");
1733 + * Get the next returned command
1735 +char *mpd_getNextCommand(mpd_Connection * connection)
1737 + return mpd_getNextReturnElementNamed(connection, "command");
1740 +void mpd_sendUrlHandlersCommand(mpd_Connection * connection)
1742 + mpd_executeCommand(connection, "urlhandlers\n");
1745 +char *mpd_getNextHandler(mpd_Connection * connection)
1747 + return mpd_getNextReturnElementNamed(connection, "handler");
1750 +void mpd_sendTagTypesCommand(mpd_Connection * connection)
1752 + mpd_executeCommand(connection, "tagtypes\n");
1755 +char *mpd_getNextTagType(mpd_Connection * connection)
1757 + return mpd_getNextReturnElementNamed(connection, "tagtype");
1760 +void mpd_startSearch(mpd_Connection * connection, int exact)
1762 + if (connection->request) {
1763 + strcpy(connection->errorStr, "search already in progress");
1764 + connection->error = 1;
1769 + connection->request = strdup("find");
1771 + connection->request = strdup("search");
1774 +void mpd_startStatsSearch(mpd_Connection * connection)
1776 + if (connection->request) {
1777 + strcpy(connection->errorStr, "search already in progress");
1778 + connection->error = 1;
1782 + connection->request = strdup("count");
1785 +void mpd_startPlaylistSearch(mpd_Connection * connection, int exact)
1787 + if (connection->request) {
1788 + strcpy(connection->errorStr, "search already in progress");
1789 + connection->error = 1;
1794 + connection->request = strdup("playlistfind");
1796 + connection->request = strdup("playlistsearch");
1799 +void mpd_startFieldSearch(mpd_Connection * connection, int type)
1804 + if (connection->request) {
1805 + strcpy(connection->errorStr, "search already in progress");
1806 + connection->error = 1;
1810 + if (type < 0 || type >= MPD_TAG_NUM_OF_ITEM_TYPES) {
1811 + strcpy(connection->errorStr, "invalid type specified");
1812 + connection->error = 1;
1816 + strtype = mpdTagItemKeys[type];
1818 + len = 5 + strlen(strtype) + 1;
1819 + connection->request = malloc(len);
1821 + snprintf(connection->request, len, "list %c%s", tolower(strtype[0]), strtype + 1);
1824 +void mpd_addConstraintSearch(mpd_Connection * connection, int type, const char *name)
1831 + if (!connection->request) {
1832 + strcpy(connection->errorStr, "no search in progress");
1833 + connection->error = 1;
1837 + if (type < 0 || type >= MPD_TAG_NUM_OF_ITEM_TYPES) {
1838 + strcpy(connection->errorStr, "invalid type specified");
1839 + connection->error = 1;
1843 + if (name == NULL) {
1844 + strcpy(connection->errorStr, "no name specified");
1845 + connection->error = 1;
1849 + string = strdup(connection->request);
1850 + strtype = mpdTagItemKeys[type];
1851 + arg = mpd_sanitizeArg(name);
1853 + len = strlen(string) + 1 + strlen(strtype) + 2 + strlen(arg) + 2;
1854 + connection->request = realloc(connection->request, len);
1855 + snprintf(connection->request, len, "%s %c%s \"%s\"", string, tolower(strtype[0]), strtype + 1, arg);
1861 +void mpd_commitSearch(mpd_Connection * connection)
1865 + if (!connection->request) {
1866 + strcpy(connection->errorStr, "no search in progress");
1867 + connection->error = 1;
1871 + len = strlen(connection->request) + 2;
1872 + connection->request = realloc(connection->request, len);
1873 + connection->request[len - 2] = '\n';
1874 + connection->request[len - 1] = '\0';
1875 + mpd_sendInfoCommand(connection, connection->request);
1877 + free(connection->request);
1878 + connection->request = NULL;
1882 + * @param connection a MpdConnection
1883 + * @param path the path to the playlist.
1885 + * List the content, with full metadata, of a stored playlist.
1888 +void mpd_sendListPlaylistInfoCommand(mpd_Connection * connection, char *path)
1890 + char *arg = mpd_sanitizeArg(path);
1891 + int len = strlen("listplaylistinfo") + 2 + strlen(arg) + 3;
1892 + char *query = malloc(len);
1893 + snprintf(query, len, "listplaylistinfo \"%s\"\n", arg);
1894 + mpd_sendInfoCommand(connection, query);
1900 + * @param connection a MpdConnection
1901 + * @param path the path to the playlist.
1903 + * List the content of a stored playlist.
1906 +void mpd_sendListPlaylistCommand(mpd_Connection * connection, char *path)
1908 + char *arg = mpd_sanitizeArg(path);
1909 + int len = strlen("listplaylist") + 2 + strlen(arg) + 3;
1910 + char *query = malloc(len);
1911 + snprintf(query, len, "listplaylist \"%s\"\n", arg);
1912 + mpd_sendInfoCommand(connection, query);
1917 +void mpd_sendPlaylistClearCommand(mpd_Connection * connection, char *path)
1919 + char *sPath = mpd_sanitizeArg(path);
1920 + int len = strlen("playlistclear") + 2 + strlen(sPath) + 3;
1921 + char *string = malloc(len);
1922 + snprintf(string, len, "playlistclear \"%s\"\n", sPath);
1923 + mpd_executeCommand(connection, string);
1928 +void mpd_sendPlaylistAddCommand(mpd_Connection * connection, char *playlist, char *path)
1930 + char *sPlaylist = mpd_sanitizeArg(playlist);
1931 + char *sPath = mpd_sanitizeArg(path);
1932 + int len = strlen("playlistadd") + 2 + strlen(sPlaylist) + 3 + strlen(sPath) + 3;
1933 + char *string = malloc(len);
1934 + snprintf(string, len, "playlistadd \"%s\" \"%s\"\n", sPlaylist, sPath);
1935 + mpd_executeCommand(connection, string);
1941 +void mpd_sendPlaylistMoveCommand(mpd_Connection * connection, char *playlist, int from, int to)
1943 + char *sPlaylist = mpd_sanitizeArg(playlist);
1944 + int len = strlen("playlistmove") + 2 + strlen(sPlaylist) + 3 + INTLEN + 3 + INTLEN + 3;
1945 + char *string = malloc(len);
1946 + snprintf(string, len, "playlistmove \"%s\" \"%i\" \"%i\"\n", sPlaylist, from, to);
1947 + mpd_executeCommand(connection, string);
1952 +void mpd_sendPlaylistDeleteCommand(mpd_Connection * connection, char *playlist, int pos)
1954 + char *sPlaylist = mpd_sanitizeArg(playlist);
1955 + int len = strlen("playlistdelete") + 2 + strlen(sPlaylist) + 3 + INTLEN + 3;
1956 + char *string = malloc(len);
1957 + snprintf(string, len, "playlistdelete \"%s\" \"%i\"\n", sPlaylist, pos);
1958 + mpd_executeCommand(connection, string);
1962 diff -urN lcd4linux-r870.orig/libmpdclient.h lcd4linux-r870/libmpdclient.h
1963 --- lcd4linux-r870.orig/libmpdclient.h 1970-01-01 01:00:00.000000000 +0100
1964 +++ lcd4linux-r870/libmpdclient.h 2008-03-26 04:43:32.000000000 +0100
1967 + (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
1968 + This project's homepage is: http://www.musicpd.org
1970 + Redistribution and use in source and binary forms, with or without
1971 + modification, are permitted provided that the following conditions
1974 + - Redistributions of source code must retain the above copyright
1975 + notice, this list of conditions and the following disclaimer.
1977 + - Redistributions in binary form must reproduce the above copyright
1978 + notice, this list of conditions and the following disclaimer in the
1979 + documentation and/or other materials provided with the distribution.
1981 + - Neither the name of the Music Player Daemon nor the names of its
1982 + contributors may be used to endorse or promote products derived from
1983 + this software without specific prior written permission.
1985 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1986 + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1987 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1988 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
1989 + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
1990 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
1991 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
1992 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
1993 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
1994 + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1995 + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1998 +#ifndef LIBMPDCLIENT_H
1999 +#define LIBMPDCLIENT_H
2002 +# define __W32API_USE_DLLIMPORT__ 1
2005 +#include <sys/time.h>
2006 +#include <stdarg.h>
2007 +#define MPD_BUFFER_MAX_LENGTH 50000
2008 +#define MPD_ERRORSTR_MAX_LENGTH 1000
2009 +#define MPD_WELCOME_MESSAGE "OK MPD "
2011 +#define MPD_ERROR_TIMEOUT 10 /* timeout trying to talk to mpd */
2012 +#define MPD_ERROR_SYSTEM 11 /* system error */
2013 +#define MPD_ERROR_UNKHOST 12 /* unknown host */
2014 +#define MPD_ERROR_CONNPORT 13 /* problems connecting to port on host */
2015 +#define MPD_ERROR_NOTMPD 14 /* mpd not running on port at host */
2016 +#define MPD_ERROR_NORESPONSE 15 /* no response on attempting to connect */
2017 +#define MPD_ERROR_SENDING 16 /* error sending command */
2018 +#define MPD_ERROR_CONNCLOSED 17 /* connection closed by mpd */
2019 +#define MPD_ERROR_ACK 18 /* ACK returned! */
2020 +#define MPD_ERROR_BUFFEROVERRUN 19 /* Buffer was overrun! */
2022 +#define MPD_ACK_ERROR_UNK -1
2023 +#define MPD_ERROR_AT_UNK -1
2025 +#define MPD_ACK_ERROR_NOT_LIST 1
2026 +#define MPD_ACK_ERROR_ARG 2
2027 +#define MPD_ACK_ERROR_PASSWORD 3
2028 +#define MPD_ACK_ERROR_PERMISSION 4
2029 +#define MPD_ACK_ERROR_UNKNOWN_CMD 5
2031 +#define MPD_ACK_ERROR_NO_EXIST 50
2032 +#define MPD_ACK_ERROR_PLAYLIST_MAX 51
2033 +#define MPD_ACK_ERROR_SYSTEM 52
2034 +#define MPD_ACK_ERROR_PLAYLIST_LOAD 53
2035 +#define MPD_ACK_ERROR_UPDATE_ALREADY 54
2036 +#define MPD_ACK_ERROR_PLAYER_SYNC 55
2037 +#define MPD_ACK_ERROR_EXIST 56
2043 + typedef enum mpd_TagItems {
2044 + MPD_TAG_ITEM_ARTIST,
2045 + MPD_TAG_ITEM_ALBUM,
2046 + MPD_TAG_ITEM_TITLE,
2047 + MPD_TAG_ITEM_TRACK,
2048 + MPD_TAG_ITEM_NAME,
2049 + MPD_TAG_ITEM_GENRE,
2050 + MPD_TAG_ITEM_DATE,
2051 + MPD_TAG_ITEM_COMPOSER,
2052 + MPD_TAG_ITEM_PERFORMER,
2053 + MPD_TAG_ITEM_COMMENT,
2054 + MPD_TAG_ITEM_DISC,
2055 + MPD_TAG_ITEM_FILENAME,
2057 + MPD_TAG_NUM_OF_ITEM_TYPES
2060 + extern char *mpdTagItemKeys[MPD_TAG_NUM_OF_ITEM_TYPES];
2062 +/* internal stuff don't touch this struct */
2063 + typedef struct _mpd_ReturnElement {
2066 + } mpd_ReturnElement;
2069 + * holds info about connection to mpd
2070 + * use error, and errorStr to detect errors
2072 + typedef struct _mpd_Connection {
2073 + /* use this to check the version of mpd */
2075 + /* IMPORTANT, you want to get the error messages from here */
2076 + char errorStr[MPD_ERRORSTR_MAX_LENGTH + 1];
2079 + /* this will be set to MPD_ERROR_* if there is an error, 0 if not */
2081 + /* DON'T TOUCH any of the rest of this stuff */
2083 + char buffer[MPD_BUFFER_MAX_LENGTH + 1];
2086 + int doneProcessing;
2090 + mpd_ReturnElement *returnElement;
2091 + struct timeval timeout;
2095 +/* mpd_newConnection
2096 + * use this to open a new connection
2097 + * you should use mpd_closeConnection, when your done with the connection,
2098 + * even if an error has occurred
2099 + * _timeout_ is the connection timeout period in seconds
2101 + mpd_Connection *mpd_newConnection(const char *host, int port, float timeout);
2103 + void mpd_setConnectionTimeout(mpd_Connection * connection, float timeout);
2105 +/* mpd_closeConnection
2106 + * use this to close a connection and free'ing subsequent memory
2108 + void mpd_closeConnection(mpd_Connection * connection);
2113 + void mpd_clearError(mpd_Connection * connection);
2117 +/* use these with status.state to determine what state the player is in */
2118 +#define MPD_STATUS_STATE_UNKNOWN 0
2119 +#define MPD_STATUS_STATE_STOP 1
2120 +#define MPD_STATUS_STATE_PLAY 2
2121 +#define MPD_STATUS_STATE_PAUSE 3
2123 +/* us this with status.volume to determine if mpd has volume support */
2124 +#define MPD_STATUS_NO_VOLUME -1
2127 + * holds info return from status command
2129 + typedef struct mpd_Status {
2130 + /* 0-100, or MPD_STATUS_NO_VOLUME when there is no volume support */
2132 + /* 1 if repeat is on, 0 otherwise */
2134 + /* 1 if random is on, 0 otherwise */
2136 + /* playlist length */
2137 + int playlistLength;
2138 + /* playlist, use this to determine when the playlist has changed */
2139 + long long playlist;
2140 + /* use with MPD_STATUS_STATE_* to determine state of player */
2142 + /* crossfade setting in seconds */
2144 + /* if a song is currently selected (always the case when state is
2145 + * PLAY or PAUSE), this is the position of the currently
2146 + * playing song in the playlist, beginning with 0
2149 + /* Song ID of the currently selected song */
2151 + /* time in seconds that have elapsed in the currently playing/paused
2155 + /* length in seconds of the currently playing/paused song */
2157 + /* current bit rate in kbs */
2159 + /* audio sample rate */
2160 + unsigned int sampleRate;
2163 + /* audio channels */
2165 + /* 1 if mpd is updating, 0 otherwise */
2171 + void mpd_sendStatusCommand(mpd_Connection * connection);
2174 + * returns status info, be sure to free it with mpd_freeStatus()
2175 + * call this after mpd_sendStatusCommand()
2177 + mpd_Status *mpd_getStatus(mpd_Connection * connection);
2180 + * free's status info malloc'd and returned by mpd_getStatus
2182 + void mpd_freeStatus(mpd_Status * status);
2184 + typedef struct _mpd_Stats {
2185 + int numberOfArtists;
2186 + int numberOfAlbums;
2187 + int numberOfSongs;
2188 + unsigned long uptime;
2189 + unsigned long dbUpdateTime;
2190 + unsigned long playTime;
2191 + unsigned long dbPlayTime;
2194 + typedef struct _mpd_SearchStats {
2195 + int numberOfSongs;
2196 + unsigned long playTime;
2197 + } mpd_SearchStats;
2199 + void mpd_sendStatsCommand(mpd_Connection * connection);
2201 + mpd_Stats *mpd_getStats(mpd_Connection * connection);
2203 + void mpd_freeStats(mpd_Stats * stats);
2205 + mpd_SearchStats *mpd_getSearchStats(mpd_Connection * connection);
2207 + void mpd_freeSearchStats(mpd_SearchStats * stats);
2211 +#define MPD_SONG_NO_TIME -1
2212 +#define MPD_SONG_NO_NUM -1
2213 +#define MPD_SONG_NO_ID -1
2216 + * for storing song info returned by mpd
2218 + typedef struct _mpd_Song {
2219 + /* filename of song */
2221 + /* artist, maybe NULL if there is no tag */
2223 + /* title, maybe NULL if there is no tag */
2225 + /* album, maybe NULL if there is no tag */
2227 + /* track, maybe NULL if there is no tag */
2229 + /* name, maybe NULL if there is no tag; it's the name of the current
2230 + * song, f.e. the icyName of the stream */
2235 + /* added by qball */
2247 + /* length of song in seconds, check that it is not MPD_SONG_NO_TIME */
2249 + /* if plchanges/playlistinfo/playlistid used, is the position of the
2250 + * song in the playlist */
2252 + /* song id for a song in the playlist */
2257 + * use to allocate memory for a new mpd_Song
2258 + * file, artist, etc all initialized to NULL
2259 + * if your going to assign values to file, artist, etc
2260 + * be sure to malloc or strdup the memory
2261 + * use mpd_freeSong to free the memory for the mpd_Song, it will also
2262 + * free memory for file, artist, etc, so don't do it yourself
2264 + mpd_Song *mpd_newSong(void);
2267 + * use to free memory allocated by mpd_newSong
2268 + * also it will free memory pointed to by file, artist, etc, so be careful
2270 + void mpd_freeSong(mpd_Song * song);
2273 + * works like strDup, but for a mpd_Song
2275 + mpd_Song *mpd_songDup(mpd_Song * song);
2277 +/* DIRECTORY STUFF */
2280 + * used to store info fro directory (right now that just the path)
2282 + typedef struct _mpd_Directory {
2286 +/* mpd_newDirectory
2287 + * allocates memory for a new directory
2288 + * use mpd_freeDirectory to free this memory
2290 + mpd_Directory *mpd_newDirectory(void);
2292 +/* mpd_freeDirectory
2293 + * used to free memory allocated with mpd_newDirectory, and it frees
2294 + * path of mpd_Directory, so be careful
2296 + void mpd_freeDirectory(mpd_Directory * directory);
2298 +/* mpd_directoryDup
2299 + * works like strdup, but for mpd_Directory
2301 + mpd_Directory *mpd_directoryDup(mpd_Directory * directory);
2303 +/* PLAYLISTFILE STUFF */
2305 +/* mpd_PlaylistFile
2306 + * stores info about playlist file returned by lsinfo
2308 + typedef struct _mpd_PlaylistFile {
2310 + } mpd_PlaylistFile;
2312 +/* mpd_newPlaylistFile
2313 + * allocates memory for new mpd_PlaylistFile, path is set to NULL
2314 + * free this memory with mpd_freePlaylistFile
2316 + mpd_PlaylistFile *mpd_newPlaylistFile(void);
2318 +/* mpd_freePlaylist
2319 + * free memory allocated for freePlaylistFile, will also free
2320 + * path, so be careful
2322 + void mpd_freePlaylistFile(mpd_PlaylistFile * playlist);
2324 +/* mpd_playlistFileDup
2325 + * works like strdup, but for mpd_PlaylistFile
2327 + mpd_PlaylistFile *mpd_playlistFileDup(mpd_PlaylistFile * playlist);
2329 +/* INFO ENTITY STUFF */
2331 +/* the type of entity returned from one of the commands that generates info
2332 + * use in conjunction with mpd_InfoEntity.type
2334 +#define MPD_INFO_ENTITY_TYPE_DIRECTORY 0
2335 +#define MPD_INFO_ENTITY_TYPE_SONG 1
2336 +#define MPD_INFO_ENTITY_TYPE_PLAYLISTFILE 2
2339 + * stores info on stuff returned info commands
2341 + typedef struct mpd_InfoEntity {
2342 + /* the type of entity, use with MPD_INFO_ENTITY_TYPE_* to determine
2343 + * what this entity is (song, directory, etc...)
2346 + /* the actual data you want, mpd_Song, mpd_Directory, etc */
2348 + mpd_Directory *directory;
2350 + mpd_PlaylistFile *playlistFile;
2354 + mpd_InfoEntity *mpd_newInfoEntity(void);
2356 + void mpd_freeInfoEntity(mpd_InfoEntity * entity);
2358 +/* INFO COMMANDS AND STUFF */
2360 +/* use this function to loop over after calling Info/Listall functions */
2361 + mpd_InfoEntity *mpd_getNextInfoEntity(mpd_Connection * connection);
2363 +/* fetches the currently seeletect song (the song referenced by status->song
2364 + * and status->songid*/
2365 + void mpd_sendCurrentSongCommand(mpd_Connection * connection);
2367 +/* songNum of -1, means to display the whole list */
2368 + void mpd_sendPlaylistInfoCommand(mpd_Connection * connection, int songNum);
2370 +/* songId of -1, means to display the whole list */
2371 + void mpd_sendPlaylistIdCommand(mpd_Connection * connection, int songId);
2373 +/* use this to get the changes in the playlist since version _playlist_ */
2374 + void mpd_sendPlChangesCommand(mpd_Connection * connection, long long playlist);
2377 + * @param connection: A valid and connected mpd_Connection.
2378 + * @param playlist: The playlist version you want the diff with.
2379 + * A more bandwidth efficient version of the mpd_sendPlChangesCommand.
2380 + * It only returns the pos+id of the changes song.
2382 + void mpd_sendPlChangesPosIdCommand(mpd_Connection * connection, long long playlist);
2384 +/* recursivel fetches all songs/dir/playlists in "dir* (no metadata is
2386 + void mpd_sendListallCommand(mpd_Connection * connection, const char *dir);
2388 +/* same as sendListallCommand, but also metadata is returned */
2389 + void mpd_sendListallInfoCommand(mpd_Connection * connection, const char *dir);
2391 +/* non-recursive version of ListallInfo */
2392 + void mpd_sendLsInfoCommand(mpd_Connection * connection, const char *dir);
2394 +#define MPD_TABLE_ARTIST MPD_TAG_ITEM_ARTIST
2395 +#define MPD_TABLE_ALBUM MPD_TAG_ITEM_ALBUM
2396 +#define MPD_TABLE_TITLE MPD_TAG_ITEM_TITLE
2397 +#define MPD_TABLE_FILENAME MPD_TAG_ITEM_FILENAME
2399 + void mpd_sendSearchCommand(mpd_Connection * connection, int table, const char *str);
2401 + void mpd_sendFindCommand(mpd_Connection * connection, int table, const char *str);
2403 +/* LIST TAG COMMANDS */
2405 +/* use this function fetch next artist entry, be sure to free the returned
2406 + * string. NULL means there are no more. Best used with sendListArtists
2408 + char *mpd_getNextArtist(mpd_Connection * connection);
2410 + char *mpd_getNextAlbum(mpd_Connection * connection);
2412 + char *mpd_getNextTag(mpd_Connection * connection, int type);
2414 +/* list artist or albums by artist, arg1 should be set to the artist if
2415 + * listing albums by a artist, otherwise NULL for listing all artists or albums
2417 + void mpd_sendListCommand(mpd_Connection * connection, int table, const char *arg1);
2419 +/* SIMPLE COMMANDS */
2421 + void mpd_sendAddCommand(mpd_Connection * connection, const char *file);
2423 + int mpd_sendAddIdCommand(mpd_Connection * connection, const char *file);
2425 + void mpd_sendDeleteCommand(mpd_Connection * connection, int songNum);
2427 + void mpd_sendDeleteIdCommand(mpd_Connection * connection, int songNum);
2429 + void mpd_sendSaveCommand(mpd_Connection * connection, const char *name);
2431 + void mpd_sendLoadCommand(mpd_Connection * connection, const char *name);
2433 + void mpd_sendRmCommand(mpd_Connection * connection, const char *name);
2435 + void mpd_sendRenameCommand(mpd_Connection * connection, const char *from, const char *to);
2437 + void mpd_sendShuffleCommand(mpd_Connection * connection);
2439 + void mpd_sendClearCommand(mpd_Connection * connection);
2441 +/* use this to start playing at the beginning, useful when in random mode */
2442 +#define MPD_PLAY_AT_BEGINNING -1
2444 + void mpd_sendPlayCommand(mpd_Connection * connection, int songNum);
2446 + void mpd_sendPlayIdCommand(mpd_Connection * connection, int songNum);
2448 + void mpd_sendStopCommand(mpd_Connection * connection);
2450 + void mpd_sendPauseCommand(mpd_Connection * connection, int pauseMode);
2452 + void mpd_sendNextCommand(mpd_Connection * connection);
2454 + void mpd_sendPrevCommand(mpd_Connection * connection);
2456 + void mpd_sendMoveCommand(mpd_Connection * connection, int from, int to);
2458 + void mpd_sendMoveIdCommand(mpd_Connection * connection, int from, int to);
2460 + void mpd_sendSwapCommand(mpd_Connection * connection, int song1, int song2);
2462 + void mpd_sendSwapIdCommand(mpd_Connection * connection, int song1, int song2);
2464 + void mpd_sendSeekCommand(mpd_Connection * connection, int song, int time);
2466 + void mpd_sendSeekIdCommand(mpd_Connection * connection, int song, int time);
2468 + void mpd_sendRepeatCommand(mpd_Connection * connection, int repeatMode);
2470 + void mpd_sendRandomCommand(mpd_Connection * connection, int randomMode);
2472 + void mpd_sendSetvolCommand(mpd_Connection * connection, int volumeChange);
2474 +/* WARNING: don't use volume command, its depreacted */
2475 + void mpd_sendVolumeCommand(mpd_Connection * connection, int volumeChange);
2477 + void mpd_sendCrossfadeCommand(mpd_Connection * connection, int seconds);
2479 + void mpd_sendUpdateCommand(mpd_Connection * connection, char *path);
2481 +/* returns the update job id, call this after a update command*/
2482 + int mpd_getUpdateId(mpd_Connection * connection);
2484 + void mpd_sendPasswordCommand(mpd_Connection * connection, const char *pass);
2486 +/* after executing a command, when your done with it to get its status
2487 + * (you want to check connection->error for an error)
2489 + void mpd_finishCommand(mpd_Connection * connection);
2491 +/* command list stuff, use this to do things like add files very quickly */
2492 + void mpd_sendCommandListBegin(mpd_Connection * connection);
2494 + void mpd_sendCommandListOkBegin(mpd_Connection * connection);
2496 + void mpd_sendCommandListEnd(mpd_Connection * connection);
2498 +/* advance to the next listOk
2499 + * returns 0 if advanced to the next list_OK,
2500 + * returns -1 if it advanced to an OK or ACK */
2501 + int mpd_nextListOkCommand(mpd_Connection * connection);
2503 + typedef struct _mpd_OutputEntity {
2507 + } mpd_OutputEntity;
2509 + void mpd_sendOutputsCommand(mpd_Connection * connection);
2511 + mpd_OutputEntity *mpd_getNextOutput(mpd_Connection * connection);
2513 + void mpd_sendEnableOutputCommand(mpd_Connection * connection, int outputId);
2515 + void mpd_sendDisableOutputCommand(mpd_Connection * connection, int outputId);
2517 + void mpd_freeOutputElement(mpd_OutputEntity * output);
2520 + * @param connection a #mpd_Connection
2522 + * Queries mpd for the allowed commands
2524 + void mpd_sendCommandsCommand(mpd_Connection * connection);
2527 + * @param connection a #mpd_Connection
2529 + * Queries mpd for the not allowed commands
2531 + void mpd_sendNotCommandsCommand(mpd_Connection * connection);
2534 + * @param connection a #mpd_Connection
2536 + * returns the next supported command.
2538 + * @returns a string, needs to be free'ed
2540 + char *mpd_getNextCommand(mpd_Connection * connection);
2542 + void mpd_sendUrlHandlersCommand(mpd_Connection * connection);
2544 + char *mpd_getNextHandler(mpd_Connection * connection);
2546 + void mpd_sendTagTypesCommand(mpd_Connection * connection);
2548 + char *mpd_getNextTagType(mpd_Connection * connection);
2551 + * @param connection a MpdConnection
2552 + * @param path the path to the playlist.
2554 + * List the content, with full metadata, of a stored playlist.
2557 + void mpd_sendListPlaylistInfoCommand(mpd_Connection * connection, char *path);
2560 + * @param connection a MpdConnection
2561 + * @param path the path to the playlist.
2563 + * List the content of a stored playlist.
2566 + void mpd_sendListPlaylistCommand(mpd_Connection * connection, char *path);
2569 + * @param connection a #mpd_Connection
2570 + * @param exact if to match exact
2572 + * starts a search, use mpd_addConstraintSearch to add
2573 + * a constraint to the search, and mpd_commitSearch to do the actual search
2575 + void mpd_startSearch(mpd_Connection * connection, int exact);
2578 + * @param connection a #mpd_Connection
2582 + void mpd_addConstraintSearch(mpd_Connection * connection, int type, const char *name);
2585 + * @param connection a #mpd_Connection
2587 + void mpd_commitSearch(mpd_Connection * connection);
2590 + * @param connection a #mpd_Connection
2591 + * @param type The type to search for
2593 + * starts a search for fields... f.e. get a list of artists would be:
2595 + * mpd_startFieldSearch(connection, MPD_TAG_ITEM_ARTIST);
2596 + * mpd_commitSearch(connection);
2599 + * or get a list of artist in genre "jazz" would be:
2601 + * mpd_startFieldSearch(connection, MPD_TAG_ITEM_ARTIST);
2602 + * mpd_addConstraintSearch(connection, MPD_TAG_ITEM_GENRE, "jazz")
2603 + * mpd_commitSearch(connection);
2606 + * mpd_startSearch will return a list of songs (and you need mpd_getNextInfoEntity)
2607 + * this one will return a list of only one field (the one specified with type) and you need
2608 + * mpd_getNextTag to get the results
2610 + void mpd_startFieldSearch(mpd_Connection * connection, int type);
2612 + void mpd_startPlaylistSearch(mpd_Connection * connection, int exact);
2614 + void mpd_startStatsSearch(mpd_Connection * connection);
2616 + void mpd_sendPlaylistClearCommand(mpd_Connection * connection, char *path);
2618 + void mpd_sendPlaylistAddCommand(mpd_Connection * connection, char *playlist, char *path);
2620 + void mpd_sendPlaylistMoveCommand(mpd_Connection * connection, char *playlist, int from, int to);
2622 + void mpd_sendPlaylistDeleteCommand(mpd_Connection * connection, char *playlist, int pos);