diff options
author | Avuton Olrich <avuton@gmail.com> | 2005-01-19 19:00:28 +0000 |
---|---|---|
committer | Avuton Olrich <avuton@gmail.com> | 2005-01-19 19:00:28 +0000 |
commit | 616f275054d41e3db2c43b022a36365d6b9aa4cc (patch) | |
tree | c312276aa5b3caa1654feddd691386eb9d802255 /src | |
parent | c39b8e1361ef3026104dfdf107a9fd57bd5b3022 (diff) | |
download | mpd-616f275054d41e3db2c43b022a36365d6b9aa4cc.tar.gz mpd-616f275054d41e3db2c43b022a36365d6b9aa4cc.tar.xz mpd-616f275054d41e3db2c43b022a36365d6b9aa4cc.zip |
libmpdclient update
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@2889 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r-- | src/libmpdclient.c | 90 | ||||
-rw-r--r-- | src/libmpdclient.h | 18 |
2 files changed, 106 insertions, 2 deletions
diff --git a/src/libmpdclient.c b/src/libmpdclient.c index e536af8a4..2ab4e28cf 100644 --- a/src/libmpdclient.c +++ b/src/libmpdclient.c @@ -52,6 +52,10 @@ #endif #endif +#ifndef MSG_DONTWAIT +#define MSG_DONTWAIT 0 +#endif + #define COMMAND_LIST 1 #define COMMAND_LIST_OK 2 @@ -222,8 +226,8 @@ mpd_Connection * mpd_newConnection(const char * host, int port, float timeout) { if(readed<=0) { snprintf(connection->errorStr,MPD_BUFFER_MAX_LENGTH, "problems getting a response from" - " \"%s\" on port %i",host, - port); + " \"%s\" on port %i : %s",host, + port, strerror(errno)); connection->error = MPD_ERROR_NORESPONSE; return connection; } @@ -345,7 +349,12 @@ void mpd_executeCommand(mpd_Connection * connection, char * command) { while((ret = select(connection->sock+1,NULL,&fds,NULL,&tv)==1) || (ret==-1 && errno==EINTR)) { ret = send(connection->sock,commandPtr,commandLen, +#ifdef WIN32 + ioctlsocket(connection->sock, commandLen, commandPtr)); +#endif +#ifndef WIN32 MSG_DONTWAIT); +#endif if(ret<=0) { if(ret==EAGAIN || ret==EINTR) continue; @@ -428,7 +437,12 @@ void mpd_getNextReturnElement(mpd_Connection * connection) { readed = recv(connection->sock, connection->buffer+connection->buflen, MPD_BUFFER_MAX_LENGTH-connection->buflen, +#ifdef WIN32 + ioctlsocket(connection->sock, commandLen, commandPtr)); +#endif +#ifndef WIN32 MSG_DONTWAIT); +#endif if(readed<0 && (errno==EAGAIN || errno==EINTR)) { continue; } @@ -773,6 +787,7 @@ void mpd_initSong(mpd_Song * song) { song->track = NULL; song->title = NULL; song->name = NULL; + song->date = NULL; song->time = MPD_SONG_NO_TIME; song->pos = MPD_SONG_NO_NUM; song->id = MPD_SONG_NO_ID; @@ -785,6 +800,7 @@ void mpd_finishSong(mpd_Song * song) { if(song->title) free(song->title); if(song->track) free(song->track); if(song->name) free(song->name); + if(song->date) free(song->date); } mpd_Song * mpd_newSong() { @@ -809,6 +825,7 @@ mpd_Song * mpd_songDup(mpd_Song * song) { if(song->title) ret->title = strdup(song->title); if(song->track) ret->track = strdup(song->track); if(song->name) ret->name = strdup(song->name); + if(song->date) ret->date = strdup(song->date); ret->time = song->time; ret->pos = song->pos; ret->id = song->id; @@ -994,6 +1011,10 @@ mpd_InfoEntity * mpd_getNextInfoEntity(mpd_Connection * connection) { strcmp(re->name,"Id")==0) { entity->info.song->id = atoi(re->value); } + else if(!entity->info.song->date && + strcmp(re->name, "Date") == 0) { + entity->info.song->date = strdup(re->value); + } } else if(entity->type == MPD_INFO_ENTITY_TYPE_DIRECTORY) { } @@ -1384,3 +1405,68 @@ void mpd_sendCommandListEnd(mpd_Connection * connection) { connection->commandList = 0; mpd_executeCommand(connection,"command_list_end\n"); } + +void mpd_sendOutputsCommand(mpd_Connection * connection) { + mpd_executeCommand(connection,"outputs\n"); +} + +mpd_OutputEntity * mpd_getNextOutput(mpd_Connection * connection) { + mpd_OutputEntity * output = NULL; + + if(connection->doneProcessing || (connection->listOks && + connection->doneListOk)) + { + return NULL; + } + + if(connection->error) return NULL; + + output = malloc(sizeof(mpd_OutputEntity)); + output->id = -10; + output->name = NULL; + output->enabled = 0; + + if(!connection->returnElement) mpd_getNextReturnElement(connection); + + while(connection->returnElement) { + mpd_ReturnElement * re = connection->returnElement; + if(strcmp(re->name,"outputid")==0) { + if(output!=NULL && output->id>=0) return output; + output->id = atoi(re->value); + } + else if(strcmp(re->name,"outputname")==0) { + output->name = strdup(re->value); + } + else if(strcmp(re->name,"outputenabled")==0) { + output->enabled = atoi(re->value); + } + + mpd_getNextReturnElement(connection); + if(connection->error) { + free(output); + return NULL; + } + + } + + return output; +} + +void mpd_sendEnableOutputCommand(mpd_Connection * connection, int outputId) { + char * string = malloc(strlen("enableoutput")+25); + sprintf(string,"enableoutput \"%i\"\n",outputId); + mpd_executeCommand(connection,string); + free(string); +} + +void mpd_sendDisableOutputCommand(mpd_Connection * connection, int outputId) { + char * string = malloc(strlen("disableoutput")+25); + sprintf(string,"disableoutput \"%i\"\n",outputId); + mpd_executeCommand(connection,string); + free(string); +} + +void mpd_freeOutputElement(mpd_OutputEntity * output) { + free(output->name); + free(output); +} diff --git a/src/libmpdclient.h b/src/libmpdclient.h index 04b70fd94..9298a09c2 100644 --- a/src/libmpdclient.h +++ b/src/libmpdclient.h @@ -231,6 +231,8 @@ typedef struct _mpd_Song { /* name, maybe NULL if there is no tag; it's the name of the current * song, f.e. the icyName of the stream */ char * name; + /* date */ + char *date; /* length of song in seconds, check that it is not MPD_SONG_NO_TIME */ int time; /* if plchanges/playlistinfo/playlistid used, is the position of the @@ -473,6 +475,22 @@ void mpd_sendCommandListEnd(mpd_Connection * connection); * returns -1 if it advanced to an OK or ACK */ int mpd_nextListOkCommand(mpd_Connection * connection); +typedef struct _mpd_OutputEntity { + int id; + char * name; + int enabled; +} mpd_OutputEntity; + +void mpd_sendOutputsCommand(mpd_Connection * connection); + +mpd_OutputEntity * mpd_getNextOutput(mpd_Connection * connection); + +void mpd_sendEnableOutputCommand(mpd_Connection * connection, int outputId); + +void mpd_sendDisableOutputCommand(mpd_Connection * connection, int outputId); + +void mpd_freeOutputElement(mpd_OutputEntity * output); + #ifdef __cplusplus } #endif |