1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-06-25 22:23:16 +00:00
ympd/src/mpd_client.h

230 lines
7.3 KiB
C
Raw Normal View History

/* myMPD
(c) 2018 Juergen Mang <mail@jcgames.de>
This project's homepage is: https://github.com/jcorporation/mympd
myMPD ist fork of:
ympd
(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
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
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
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
*/
#ifndef __MPD_CLIENT_H__
#define __MPD_CLIENT_H__
#include "../dist/src/mongoose/mongoose.h"
2013-11-04 17:18:38 +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) \
); \
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)
#define LOG_ERROR_AND_RECOVER(X) do { \
fprintf(stderr, "MPD X: %s\n", mpd_connection_get_error_message(mpd.conn)); \
if (!mpd_connection_clear_error(mpd.conn)) \
mpd.conn_state = MPD_FAILURE; \
} while (0)
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) \
2018-08-27 18:47:00 +00:00
X(MPD_API_QUEUE_CLEAR) \
X(MPD_API_QUEUE_CROP) \
X(MPD_API_QUEUE_SAVE) \
X(MPD_API_QUEUE_LIST) \
X(MPD_API_QUEUE_SEARCH) \
X(MPD_API_QUEUE_RM_TRACK) \
X(MPD_API_QUEUE_RM_RANGE) \
X(MPD_API_QUEUE_MOVE_TRACK) \
X(MPD_API_QUEUE_ADD_TRACK_AFTER) \
X(MPD_API_QUEUE_ADD_TRACK) \
X(MPD_API_QUEUE_ADD_PLAY_TRACK) \
X(MPD_API_QUEUE_REPLACE_TRACK) \
X(MPD_API_QUEUE_ADD_PLAYLIST) \
X(MPD_API_QUEUE_REPLACE_PLAYLIST) \
X(MPD_API_QUEUE_SHUFFLE) \
X(MPD_API_PLAYLIST_RM) \
2018-07-22 19:00:26 +00:00
X(MPD_API_PLAYLIST_CLEAR) \
X(MPD_API_PLAYLIST_RENAME) \
X(MPD_API_PLAYLIST_MOVE_TRACK) \
2018-08-27 18:47:00 +00:00
X(MPD_API_PLAYLIST_ADD_TRACK) \
X(MPD_API_PLAYLIST_RM_TRACK) \
X(MPD_API_PLAYLIST_LIST) \
X(MPD_API_PLAYLIST_CONTENT_LIST) \
X(MPD_API_SMARTPLS_UPDATE_ALL) \
X(MPD_API_SMARTPLS_SAVE) \
X(MPD_API_SMARTPLS_GET) \
2018-08-27 18:47:00 +00:00
X(MPD_API_DATABASE_SEARCH) \
X(MPD_API_DATABASE_UPDATE) \
2018-09-23 21:48:12 +00:00
X(MPD_API_DATABASE_RESCAN) \
2018-08-27 18:47:00 +00:00
X(MPD_API_DATABASE_FILESYSTEM_LIST) \
X(MPD_API_DATABASE_TAG_LIST) \
X(MPD_API_DATABASE_TAG_ALBUM_LIST) \
X(MPD_API_DATABASE_TAG_ALBUM_TITLE_LIST) \
2018-08-27 18:47:00 +00:00
X(MPD_API_DATABASE_STATS) \
X(MPD_API_DATABASE_SONGDETAILS) \
X(MPD_API_PLAYER_PLAY_TRACK) \
X(MPD_API_PLAYER_VOLUME) \
X(MPD_API_PLAYER_PAUSE) \
X(MPD_API_PLAYER_PLAY) \
X(MPD_API_PLAYER_STOP) \
X(MPD_API_PLAYER_SEEK) \
X(MPD_API_PLAYER_NEXT) \
X(MPD_API_PLAYER_PREV) \
X(MPD_API_PLAYER_OUTPUT_LIST) \
X(MPD_API_PLAYER_TOGGLE_OUTPUT) \
X(MPD_API_PLAYER_CURRENT_SONG) \
X(MPD_API_PLAYER_STATE) \
X(MPD_API_SETTINGS_GET) \
X(MPD_API_SETTINGS_SET) \
X(MPD_API_MESSAGE_SEND) \
2018-06-19 22:43:36 +00:00
X(MPD_API_WELCOME) \
2018-08-27 18:47:00 +00:00
X(MPD_API_LIKE) \
X(MPD_API_UNKNOWN)
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 {
2018-09-03 21:49:55 +00:00
// Connection
2014-02-16 18:46:53 +00:00
struct mpd_connection *conn;
enum mpd_conn_states conn_state;
2018-09-03 21:49:55 +00:00
int timeout;
2014-02-16 18:46:53 +00:00
2018-09-03 21:49:55 +00:00
// Reponse Buffer
2014-02-16 18:46:53 +00:00
char buf[MAX_SIZE];
size_t buf_size;
2018-09-03 21:49:55 +00:00
// States
2014-02-16 18:46:53 +00:00
int song_id;
int next_song_id;
int last_song_id;
2014-02-16 18:46:53 +00:00
unsigned queue_version;
unsigned queue_length;
int last_update_sticker_song_id;
2018-09-03 21:49:55 +00:00
// Features
const unsigned* protocol;
// Supported tags
2018-09-03 21:49:55 +00:00
bool feat_sticker;
bool tag_artist;
bool tag_album;
bool tag_album_artist;
bool tag_title;
bool tag_track;
bool tag_genre;
bool tag_date;
bool tag_composer;
bool tag_performer;
2014-02-16 18:46:53 +00:00
} mpd;
typedef struct {
long mpdport;
2018-08-15 13:06:45 +00:00
const char* mpdhost;
const char* mpdpass;
const char* webport;
bool ssl;
const char* sslport;
const char* sslcert;
const char* sslkey;
const char* user;
long streamport;
2018-08-15 13:06:45 +00:00
const char* coverimage;
bool stickers;
bool mixramp;
const char* taglist;
2018-09-24 22:27:24 +00:00
bool smartpls;
const char* varlibdir;
2018-08-17 09:52:22 +00:00
} t_config;
2018-08-17 09:52:22 +00:00
t_config config;
typedef struct {
long playCount;
long skipCount;
long lastPlayed;
long like;
2018-08-17 09:52:22 +00:00
} t_sticker;
2018-09-17 22:25:05 +00:00
typedef struct {
bool notificationWeb;
bool notificationPage;
int jukeboxMode;
const char* jukeboxPlaylist;
int jukeboxQueueLength;
2018-09-17 22:25:05 +00:00
} t_mympd_state;
t_mympd_state mympd_state;
2018-06-12 00:07:03 +00:00
static int is_websocket(const struct mg_connection *nc) {
2018-08-15 13:06:45 +00:00
return nc->flags & MG_F_IS_WEBSOCKET;
}
2018-06-12 00:07:03 +00:00
void mympd_idle(struct mg_mgr *sm, int timeout);
void mympd_parse_idle(struct mg_mgr *s, int idle_bitmask);
2018-06-14 22:00:54 +00:00
void callback_mympd(struct mg_connection *nc, const struct mg_str msg);
2018-08-15 13:06:45 +00:00
void mympd_notify(struct mg_mgr *s);
2018-08-15 15:23:47 +00:00
void mympd_count_song_id(int song_id, char *name, int value);
void mympd_count_song_uri(const char *uri, char *name, int value);
void mympd_like_song_uri(const char *uri, int value);
2018-08-15 16:06:12 +00:00
void mympd_last_played_song_uri(const char *uri);
void mympd_last_played_song_id(int song_id);
2018-08-17 09:52:22 +00:00
void mympd_get_sticker(const char *uri, t_sticker *sticker);
2018-09-17 22:25:05 +00:00
void mympd_jukebox();
int mympd_smartpls_save(char *smartpltype, char *playlist, char *tag, char *searchstr, int maxentries, int timerange);
int mympd_smartpls_put(char *buffer, char *playlist);
int mympd_smartpls_update_all();
2018-09-24 22:27:24 +00:00
int mympd_smartpls_clear(char *playlist);
int mympd_smartpls_update(char *sticker, char *playlist, int maxentries);
int mympd_smartpls_update_newest(char *playlist, int timerange, int maxentries);
int mympd_smartpls_update_search(char *playlist, char *tag, char *searchstr);
int mympd_get_updatedb_state(char *buffer);
int mympd_put_state(char *buffer, int *current_song_id, int *next_song_id, int *last_song_id, unsigned *queue_version, unsigned *queue_length);
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, unsigned *queue_version, unsigned *queue_length);
2018-06-14 22:00:54 +00:00
int mympd_put_browse(char *buffer, char *path, unsigned int offset, char *filter);
int mympd_search(char *buffer, char *searchstr, char *filter, char *plist, unsigned int offset);
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);
int mympd_put_settings(char *buffer);
int mympd_put_db_tag(char *buffer, unsigned int offset, char *mpdtagtype, char *mpdsearchtagtype, char *searchstr, char *filter);
int mympd_put_songs_in_album(char *buffer, char *album, char *search, char *tag);
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);
int mympd_queue_crop(char *buffer);
2018-06-14 22:00:54 +00:00
void mympd_disconnect();
#endif