1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-12-27 19:30:27 +00:00

Rewrite to newest mongoose version

This commit is contained in:
jcorporation 2018-06-12 02:09:24 +01:00
parent 25fa58aa8c
commit 401bd5302f
3 changed files with 13 additions and 9 deletions

View File

@ -59,7 +59,7 @@ static inline enum mpd_cmd_ids get_cmd_id(const char *cmd)
return -1; return -1;
} }
int callback_mpd(struct mg_connection *c,const struct mg_str msg) void callback_mpd(struct mg_connection *c,const struct mg_str msg)
{ {
enum mpd_cmd_ids cmd_id = get_cmd_id(msg.p); enum mpd_cmd_ids cmd_id = get_cmd_id(msg.p);
size_t n = 0; size_t n = 0;
@ -69,8 +69,9 @@ int callback_mpd(struct mg_connection *c,const struct mg_str msg)
char *p_charbuf = NULL, *token; char *p_charbuf = NULL, *token;
char *p_charbuf2 = NULL; char *p_charbuf2 = NULL;
char *searchstr = NULL; char *searchstr = NULL;
char request[500];
fprintf(stdout,"Got request: %s:%d\n",msg.p,cmd_id); fprintf(stdout,"Got request: %s\n",msg.p);
if(cmd_id == -1) if(cmd_id == -1)
return 0; return 0;
@ -485,8 +486,8 @@ out_set_replaygain:
int mpd_close_handler(struct mg_connection *c) int mpd_close_handler(struct mg_connection *c)
{ {
/* Cleanup session data */ /* Cleanup session data */
// if(c->connection_param) if(c->user_data)
// free(c->connection_param); free(c->user_data);
return 0; return 0;
} }
@ -505,10 +506,10 @@ static int mpd_notify_callback(struct mg_connection *c, const char *param) {
return 0; return 0;
} }
if(!c->connection_param) if(!c->user_data)
c->connection_param = calloc(1, sizeof(struct t_mpd_client_session)); c->user_data = calloc(1, sizeof(struct t_mpd_client_session));
struct t_mpd_client_session *s = (struct t_mpd_client_session *)c->connection_param; struct t_mpd_client_session *s = (struct t_mpd_client_session *)c->user_data;
if(mpd.conn_state != MPD_CONNECTED) { if(mpd.conn_state != MPD_CONNECTED) {
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\":\"disconnected\"}"); n = snprintf(mpd.buf, MAX_SIZE, "{\"type\":\"disconnected\"}");

View File

@ -131,7 +131,7 @@ struct t_mpd_client_session {
}; };
void mpd_poll(struct mg_mgr *s); void mpd_poll(struct mg_mgr *s);
int callback_mpd(struct mg_connection *c,const struct mg_str msg); void callback_mpd(struct mg_connection *c, const struct mg_str msg);
int mpd_close_handler(struct mg_connection *c); int mpd_close_handler(struct mg_connection *c);
int mpd_put_state(char *buffer, int *current_song_id, int *next_song_id, unsigned *queue_version); int mpd_put_state(char *buffer, int *current_song_id, int *next_song_id, unsigned *queue_version);
int mpd_put_outputs(char *buffer, int putnames); int mpd_put_outputs(char *buffer, int putnames);

View File

@ -46,11 +46,14 @@ static void signal_handler(int sig_num) {
static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
switch(ev) { switch(ev) {
case MG_EV_CLOSE: { case MG_EV_CLOSE: {
mpd_close_handler(nc); if (is_websocket(nc)) {
mpd_close_handler(nc);
}
break; break;
} }
case MG_EV_WEBSOCKET_FRAME: { case MG_EV_WEBSOCKET_FRAME: {
struct websocket_message *wm = (struct websocket_message *) ev_data; struct websocket_message *wm = (struct websocket_message *) ev_data;
wm->data[wm->size]='\0';
struct mg_str d = {(char *) wm->data, wm->size}; struct mg_str d = {(char *) wm->data, wm->size};
callback_mpd(nc, d); callback_mpd(nc, d);
break; break;