2014-01-17 18:41:41 +00:00
|
|
|
/* ympd
|
2014-02-22 00:57:26 +00:00
|
|
|
(c) 2013-2014 Andrew Karpow <andy@ndyk.de>
|
2014-01-17 18:41:41 +00:00
|
|
|
This project's homepage is: http://www.ympd.org
|
2014-02-22 00:57:26 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
2014-01-17 18:41:41 +00:00
|
|
|
|
2014-02-22 00:57:26 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2014-01-17 18:41:41 +00:00
|
|
|
|
2014-02-22 00:57:26 +00:00
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2014-01-17 18:41:41 +00:00
|
|
|
*/
|
|
|
|
|
2014-01-08 01:23:02 +00:00
|
|
|
#ifndef __MPD_CLIENT_H__
|
|
|
|
#define __MPD_CLIENT_H__
|
|
|
|
|
2014-02-16 18:46:53 +00:00
|
|
|
#include "mongoose.h"
|
2013-11-04 17:18:38 +00:00
|
|
|
|
2014-02-22 00:57:26 +00:00
|
|
|
#define RETURN_ERROR_AND_RECOVER(X) do { \
|
|
|
|
fprintf(stderr, "MPD X: %s\n", mpd_connection_get_error_message(mpd.conn)); \
|
|
|
|
cur += snprintf(cur, end - cur, "{\"type\":\"error\",\"data\":\"%s\"}", \
|
|
|
|
mpd_connection_get_error_message(mpd.conn)); \
|
|
|
|
if (!mpd_connection_clear_error(mpd.conn)) \
|
|
|
|
mpd.conn_state = MPD_FAILURE; \
|
|
|
|
return cur - buffer; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
2014-01-08 01:23:02 +00:00
|
|
|
#define MAX_SIZE 1024 * 100
|
2014-02-22 01:11:45 +00:00
|
|
|
#define MAX_ELEMENTS_PER_PAGE 512
|
|
|
|
|
2014-02-16 18:46:53 +00:00
|
|
|
#define GEN_ENUM(X) X,
|
|
|
|
#define GEN_STR(X) #X,
|
|
|
|
#define MPD_CMDS(X) \
|
2014-02-22 00:57:26 +00:00
|
|
|
X(MPD_API_GET_QUEUE) \
|
2014-02-16 18:46:53 +00:00
|
|
|
X(MPD_API_GET_BROWSE) \
|
|
|
|
X(MPD_API_GET_MPDHOST) \
|
|
|
|
X(MPD_API_ADD_TRACK) \
|
|
|
|
X(MPD_API_ADD_PLAY_TRACK) \
|
2014-02-22 00:57:26 +00:00
|
|
|
X(MPD_API_ADD_PLAYLIST) \
|
2014-02-16 18:46:53 +00:00
|
|
|
X(MPD_API_PLAY_TRACK) \
|
2015-09-02 17:24:52 +00:00
|
|
|
X(MPD_API_SAVE_QUEUE) \
|
2014-02-16 18:46:53 +00:00
|
|
|
X(MPD_API_RM_TRACK) \
|
|
|
|
X(MPD_API_RM_ALL) \
|
2014-02-22 00:57:26 +00:00
|
|
|
X(MPD_API_SEARCH) \
|
2017-03-18 12:31:26 +00:00
|
|
|
X(MPD_API_SEND_MESSAGE) \
|
2014-02-16 18:46:53 +00:00
|
|
|
X(MPD_API_SET_VOLUME) \
|
|
|
|
X(MPD_API_SET_PAUSE) \
|
|
|
|
X(MPD_API_SET_PLAY) \
|
|
|
|
X(MPD_API_SET_STOP) \
|
|
|
|
X(MPD_API_SET_SEEK) \
|
|
|
|
X(MPD_API_SET_NEXT) \
|
|
|
|
X(MPD_API_SET_PREV) \
|
|
|
|
X(MPD_API_SET_MPDHOST) \
|
|
|
|
X(MPD_API_SET_MPDPASS) \
|
|
|
|
X(MPD_API_UPDATE_DB) \
|
2015-04-28 09:08:21 +00:00
|
|
|
X(MPD_API_GET_OUTPUTS) \
|
|
|
|
X(MPD_API_TOGGLE_OUTPUT) \
|
2014-02-16 18:46:53 +00:00
|
|
|
X(MPD_API_TOGGLE_RANDOM) \
|
|
|
|
X(MPD_API_TOGGLE_CONSUME) \
|
|
|
|
X(MPD_API_TOGGLE_SINGLE) \
|
2015-02-17 14:45:26 +00:00
|
|
|
X(MPD_API_TOGGLE_CROSSFADE) \
|
2014-02-16 18:46:53 +00:00
|
|
|
X(MPD_API_TOGGLE_REPEAT)
|
2014-01-08 01:23:02 +00:00
|
|
|
|
2014-02-16 18:46:53 +00:00
|
|
|
enum mpd_cmd_ids {
|
|
|
|
MPD_CMDS(GEN_ENUM)
|
2013-11-09 01:07:03 +00:00
|
|
|
};
|
2013-11-04 17:18:38 +00:00
|
|
|
|
2013-11-09 01:07:03 +00:00
|
|
|
enum mpd_conn_states {
|
|
|
|
MPD_DISCONNECTED,
|
2014-02-16 18:46:53 +00:00
|
|
|
MPD_FAILURE,
|
2014-02-04 16:58:10 +00:00
|
|
|
MPD_CONNECTED,
|
2014-02-16 18:46:53 +00:00
|
|
|
MPD_RECONNECT,
|
|
|
|
MPD_DISCONNECT
|
2013-11-09 01:07:03 +00:00
|
|
|
};
|
2013-11-04 17:18:38 +00:00
|
|
|
|
2014-02-16 18:46:53 +00:00
|
|
|
struct t_mpd {
|
|
|
|
int port;
|
|
|
|
char host[128];
|
|
|
|
char *password;
|
|
|
|
|
|
|
|
struct mpd_connection *conn;
|
|
|
|
enum mpd_conn_states conn_state;
|
|
|
|
|
|
|
|
/* Reponse Buffer */
|
|
|
|
char buf[MAX_SIZE];
|
|
|
|
size_t buf_size;
|
|
|
|
|
|
|
|
int song_id;
|
|
|
|
unsigned queue_version;
|
|
|
|
} mpd;
|
|
|
|
|
|
|
|
struct t_mpd_client_session {
|
|
|
|
int song_id;
|
|
|
|
unsigned queue_version;
|
|
|
|
};
|
|
|
|
|
|
|
|
void mpd_poll(struct mg_server *s);
|
|
|
|
int callback_mpd(struct mg_connection *c);
|
|
|
|
int mpd_close_handler(struct mg_connection *c);
|
2014-01-17 15:26:26 +00:00
|
|
|
int mpd_put_state(char *buffer, int *current_song_id, unsigned *queue_version);
|
2015-05-01 21:51:44 +00:00
|
|
|
int mpd_put_outputs(char *buffer, int putnames);
|
2013-11-07 09:09:40 +00:00
|
|
|
int mpd_put_current_song(char *buffer);
|
2014-02-22 01:11:45 +00:00
|
|
|
int mpd_put_queue(char *buffer, unsigned int offset);
|
|
|
|
int mpd_put_browse(char *buffer, char *path, unsigned int offset);
|
2014-02-22 00:57:26 +00:00
|
|
|
int mpd_search(char *buffer, char *searchstr);
|
2014-02-16 18:46:53 +00:00
|
|
|
void mpd_disconnect();
|
2014-01-08 01:23:02 +00:00
|
|
|
#endif
|
|
|
|
|