2018-05-24 17:50:05 +00:00
|
|
|
/* myMPD
|
|
|
|
(c) 2018 Juergen Mang <mail@jcgames.de>
|
2018-06-21 21:29:49 +00:00
|
|
|
This project's homepage is: https://github.com/jcorporation/mympd
|
2018-05-24 17:50:05 +00:00
|
|
|
|
|
|
|
myMPD ist fork of:
|
|
|
|
|
|
|
|
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__
|
|
|
|
|
2018-07-30 22:05:37 +00:00
|
|
|
#include "../dist/src/mongoose/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)); \
|
2018-06-18 16:53:30 +00:00
|
|
|
len = json_printf(&out, "{ type:error, data : %Q }", \
|
|
|
|
mpd_connection_get_error_message(mpd.conn) \
|
|
|
|
); \
|
2014-02-22 00:57:26 +00:00
|
|
|
if (!mpd_connection_clear_error(mpd.conn)) \
|
|
|
|
mpd.conn_state = MPD_FAILURE; \
|
2018-06-18 16:53:30 +00:00
|
|
|
return len; \
|
2018-08-06 21:29:20 +00:00
|
|
|
} while (0)
|
2014-02-22 00:57:26 +00:00
|
|
|
|
|
|
|
|
2018-05-27 21:34:39 +00:00
|
|
|
#define MAX_SIZE 1024 * 100
|
|
|
|
#define MAX_ELEMENTS_PER_PAGE 100
|
2014-02-22 01:11:45 +00:00
|
|
|
|
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) \
|
2018-06-14 19:56:12 +00:00
|
|
|
X(MPD_API_GET_FILESYSTEM) \
|
2018-07-05 19:34:16 +00:00
|
|
|
X(MPD_API_ADD_TRACK_AFTER) \
|
2014-02-16 18:46:53 +00:00
|
|
|
X(MPD_API_ADD_TRACK) \
|
|
|
|
X(MPD_API_ADD_PLAY_TRACK) \
|
2018-07-05 19:34:16 +00:00
|
|
|
X(MPD_API_REPLACE_TRACK) \
|
2014-02-22 00:57:26 +00:00
|
|
|
X(MPD_API_ADD_PLAYLIST) \
|
2018-07-05 19:34:16 +00:00
|
|
|
X(MPD_API_REPLACE_PLAYLIST) \
|
2018-07-22 19:00:26 +00:00
|
|
|
X(MPD_API_RM_PLAYLIST_TRACK) \
|
|
|
|
X(MPD_API_PLAYLIST_CLEAR) \
|
|
|
|
X(MPD_API_PLAYLIST_RENAME) \
|
2018-07-26 21:48:03 +00:00
|
|
|
X(MPD_API_PLAYLIST_MOVE_TRACK) \
|
2018-07-22 19:00:26 +00:00
|
|
|
X(MPD_API_ADD_TO_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) \
|
2017-04-08 09:25:40 +00:00
|
|
|
X(MPD_API_RM_RANGE) \
|
2018-08-05 22:02:29 +00:00
|
|
|
X(MPD_API_QUEUE_CLEAR) \
|
|
|
|
X(MPD_API_QUEUE_CROP) \
|
2015-09-04 14:43:16 +00:00
|
|
|
X(MPD_API_MOVE_TRACK) \
|
2018-05-24 22:21:19 +00:00
|
|
|
X(MPD_API_SEARCH_QUEUE) \
|
2018-07-31 20:46:53 +00:00
|
|
|
X(MPD_API_SEARCH_ADD_PLIST) \
|
2018-05-31 23:05:49 +00:00
|
|
|
X(MPD_API_SEARCH_ADD) \
|
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_UPDATE_DB) \
|
2018-08-06 18:57:42 +00:00
|
|
|
X(MPD_API_GET_OUTPUTS) \
|
2015-04-28 09:08:21 +00:00
|
|
|
X(MPD_API_TOGGLE_OUTPUT) \
|
2018-05-27 21:34:39 +00:00
|
|
|
X(MPD_API_SEND_SHUFFLE) \
|
2018-05-28 18:48:43 +00:00
|
|
|
X(MPD_API_GET_STATS) \
|
2018-05-29 20:12:11 +00:00
|
|
|
X(MPD_API_GET_PLAYLISTS) \
|
2018-07-22 19:00:26 +00:00
|
|
|
X(MPD_API_GET_PLAYLIST_LIST) \
|
2018-05-31 20:23:57 +00:00
|
|
|
X(MPD_API_RM_PLAYLIST) \
|
2018-06-03 16:36:06 +00:00
|
|
|
X(MPD_API_GET_ARTISTALBUMS) \
|
|
|
|
X(MPD_API_GET_ARTISTALBUMTITLES) \
|
2018-06-11 17:33:11 +00:00
|
|
|
X(MPD_API_GET_ARTISTS) \
|
2018-06-14 20:19:36 +00:00
|
|
|
X(MPD_API_GET_CURRENT_SONG) \
|
2018-07-09 17:28:28 +00:00
|
|
|
X(MPD_API_GET_SONGDETAILS) \
|
2018-06-19 22:43:36 +00:00
|
|
|
X(MPD_API_WELCOME) \
|
2018-06-21 16:57:40 +00:00
|
|
|
X(MPD_API_GET_SETTINGS) \
|
2018-07-19 17:58:23 +00:00
|
|
|
X(MPD_API_SET_SETTINGS) \
|
2018-08-09 22:52:58 +00:00
|
|
|
X(MPD_API_GET_STATE) \
|
2018-07-19 17:58:23 +00:00
|
|
|
X(MPD_API_UNKNOWN)
|
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 {
|
|
|
|
struct mpd_connection *conn;
|
|
|
|
enum mpd_conn_states conn_state;
|
|
|
|
|
|
|
|
/* Reponse Buffer */
|
|
|
|
char buf[MAX_SIZE];
|
|
|
|
size_t buf_size;
|
|
|
|
|
|
|
|
int song_id;
|
2018-05-28 18:48:43 +00:00
|
|
|
int next_song_id;
|
2014-02-16 18:46:53 +00:00
|
|
|
unsigned queue_version;
|
2018-08-09 21:15:00 +00:00
|
|
|
int timeout;
|
2014-02-16 18:46:53 +00:00
|
|
|
} mpd;
|
|
|
|
|
2018-08-06 20:51:48 +00:00
|
|
|
typedef struct {
|
|
|
|
int mpdport;
|
|
|
|
const char* mpdhost;
|
|
|
|
const char* mpdpass;
|
|
|
|
const char* webport;
|
|
|
|
bool ssl;
|
|
|
|
const char* sslport;
|
|
|
|
const char* sslcert;
|
|
|
|
const char* sslkey;
|
|
|
|
const char* user;
|
|
|
|
int streamport;
|
|
|
|
const char* coverimage;
|
|
|
|
const char* statefile;
|
|
|
|
} configuration;
|
|
|
|
|
|
|
|
configuration config;
|
2018-05-24 17:50:05 +00:00
|
|
|
|
2018-06-12 00:07:03 +00:00
|
|
|
static int is_websocket(const struct mg_connection *nc) {
|
|
|
|
return nc->flags & MG_F_IS_WEBSOCKET;
|
2018-06-12 23:29:58 +00:00
|
|
|
}
|
2018-06-12 00:07:03 +00:00
|
|
|
|
2018-08-09 21:15:00 +00:00
|
|
|
void mympd_poll(struct mg_mgr *sm, int timeout);
|
|
|
|
void mympd_parse_idle(struct mg_mgr *s);
|
2018-06-14 22:00:54 +00:00
|
|
|
void callback_mympd(struct mg_connection *nc, const struct mg_str msg);
|
|
|
|
int mympd_close_handler(struct mg_connection *c);
|
|
|
|
int mympd_put_state(char *buffer, int *current_song_id, int *next_song_id, unsigned *queue_version);
|
2018-08-06 18:57:42 +00:00
|
|
|
int mympd_put_outputs(char *buffer);
|
2018-06-14 22:00:54 +00:00
|
|
|
int mympd_put_current_song(char *buffer);
|
|
|
|
int mympd_put_queue(char *buffer, unsigned int offset);
|
|
|
|
int mympd_put_browse(char *buffer, char *path, unsigned int offset, char *filter);
|
|
|
|
int mympd_search(char *buffer, char *mpdtagtype, unsigned int offset, char *searchstr);
|
|
|
|
int mympd_search_add(char *buffer, char *mpdtagtype, char *searchstr);
|
2018-08-05 22:02:29 +00:00
|
|
|
int mympd_search_add_plist(char *plist, char *mpdtagtype, char *searchstr);
|
2018-06-14 22:00:54 +00:00
|
|
|
int mympd_search_queue(char *buffer, char *mpdtagtype, unsigned int offset, char *searchstr);
|
|
|
|
int mympd_put_welcome(char *buffer);
|
2018-08-06 21:29:20 +00:00
|
|
|
int mympd_put_stats(char *buffer);
|
2018-05-29 21:05:34 +00:00
|
|
|
int mympd_put_settings(char *buffer);
|
2018-06-04 18:31:05 +00:00
|
|
|
int mympd_put_db_tag(char *buffer, unsigned int offset, char *mpdtagtype, char *mpdsearchtagtype, char *searchstr, char *filter);
|
2018-06-03 16:36:06 +00:00
|
|
|
int mympd_put_songs_in_album(char *buffer, char *albumartist, char *album);
|
2018-06-04 18:31:05 +00:00
|
|
|
int mympd_put_playlists(char *buffer, unsigned int offset, char *filter);
|
2018-07-22 19:00:26 +00:00
|
|
|
int mympd_put_playlist_list(char *buffer, char *uri, unsigned int offset, char *filter);
|
2018-07-09 17:28:28 +00:00
|
|
|
int mympd_put_songdetails(char *buffer, char *uri);
|
2018-08-05 22:02:29 +00:00
|
|
|
int mympd_queue_crop(char *buffer);
|
2018-06-14 22:00:54 +00:00
|
|
|
void mympd_disconnect();
|
2014-01-08 01:23:02 +00:00
|
|
|
#endif
|
|
|
|
|