mpd_client.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* ympd
  2. (c) 2013-2014 Andrew Karpow <andy@ndyk.de>
  3. This project's homepage is: http://www.ympd.org
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; version 2 of the License.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with this program; if not, write to the Free Software Foundation, Inc.,
  13. Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  14. */
  15. #ifndef __MPD_CLIENT_H__
  16. #define __MPD_CLIENT_H__
  17. #include "mongoose.h"
  18. #define RETURN_ERROR_AND_RECOVER(X) do { \
  19. fprintf(stderr, "MPD X: %s\n", mpd_connection_get_error_message(mpd.conn)); \
  20. cur += snprintf(cur, end - cur, "{\"type\":\"error\",\"data\":\"%s\"}", \
  21. mpd_connection_get_error_message(mpd.conn)); \
  22. if (!mpd_connection_clear_error(mpd.conn)) \
  23. mpd.conn_state = MPD_FAILURE; \
  24. return cur - buffer; \
  25. } while(0)
  26. #define MAX_SIZE 1024 * 100
  27. #define MAX_ELEMENTS_PER_PAGE 512
  28. #define GEN_ENUM(X) X,
  29. #define GEN_STR(X) #X,
  30. #define MPD_CMDS(X) \
  31. X(MPD_API_GET_QUEUE) \
  32. X(MPD_API_GET_BROWSE) \
  33. X(MPD_API_GET_MPDHOST) \
  34. X(MPD_API_GET_DIRBLEAPITOKEN) \
  35. X(MPD_API_ADD_TRACK) \
  36. X(MPD_API_ADD_PLAY_TRACK) \
  37. X(MPD_API_ADD_PLAYLIST) \
  38. X(MPD_API_PLAY_TRACK) \
  39. X(MPD_API_SAVE_QUEUE) \
  40. X(MPD_API_RM_TRACK) \
  41. X(MPD_API_RM_RANGE) \
  42. X(MPD_API_RM_ALL) \
  43. X(MPD_API_MOVE_TRACK) \
  44. X(MPD_API_SEARCH) \
  45. X(MPD_API_SEND_MESSAGE) \
  46. X(MPD_API_SET_VOLUME) \
  47. X(MPD_API_SET_PAUSE) \
  48. X(MPD_API_SET_PLAY) \
  49. X(MPD_API_SET_STOP) \
  50. X(MPD_API_SET_SEEK) \
  51. X(MPD_API_SET_NEXT) \
  52. X(MPD_API_SET_PREV) \
  53. X(MPD_API_SET_MPDHOST) \
  54. X(MPD_API_SET_MPDPASS) \
  55. X(MPD_API_UPDATE_DB) \
  56. X(MPD_API_GET_OUTPUTS) \
  57. X(MPD_API_TOGGLE_OUTPUT) \
  58. X(MPD_API_TOGGLE_RANDOM) \
  59. X(MPD_API_TOGGLE_CONSUME) \
  60. X(MPD_API_TOGGLE_SINGLE) \
  61. X(MPD_API_TOGGLE_CROSSFADE) \
  62. X(MPD_API_TOGGLE_REPEAT)
  63. enum mpd_cmd_ids {
  64. MPD_CMDS(GEN_ENUM)
  65. };
  66. enum mpd_conn_states {
  67. MPD_DISCONNECTED,
  68. MPD_FAILURE,
  69. MPD_CONNECTED,
  70. MPD_RECONNECT,
  71. MPD_DISCONNECT
  72. };
  73. struct t_mpd {
  74. int port;
  75. char host[128];
  76. char *password;
  77. struct mpd_connection *conn;
  78. enum mpd_conn_states conn_state;
  79. /* Reponse Buffer */
  80. char buf[MAX_SIZE];
  81. size_t buf_size;
  82. int song_id;
  83. unsigned queue_version;
  84. } mpd;
  85. char dirble_api_token[28];
  86. struct t_mpd_client_session {
  87. int song_id;
  88. unsigned queue_version;
  89. };
  90. void mpd_poll(struct mg_server *s);
  91. int callback_mpd(struct mg_connection *c);
  92. int mpd_close_handler(struct mg_connection *c);
  93. int mpd_put_state(char *buffer, int *current_song_id, unsigned *queue_version);
  94. int mpd_put_outputs(char *buffer, int putnames);
  95. int mpd_put_current_song(char *buffer);
  96. int mpd_put_queue(char *buffer, unsigned int offset);
  97. int mpd_put_browse(char *buffer, char *path, unsigned int offset);
  98. int mpd_search(char *buffer, char *searchstr);
  99. void mpd_disconnect();
  100. #endif