From 401bd5302f51522a3af2d0ceaedfd2ce7de9b33b Mon Sep 17 00:00:00 2001 From: jcorporation Date: Tue, 12 Jun 2018 02:09:24 +0100 Subject: [PATCH] Rewrite to newest mongoose version --- src/mpd_client.c | 15 ++++++++------- src/mpd_client.h | 2 +- src/mympd.c | 5 ++++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/mpd_client.c b/src/mpd_client.c index ff44d8c..13a5112 100644 --- a/src/mpd_client.c +++ b/src/mpd_client.c @@ -59,7 +59,7 @@ static inline enum mpd_cmd_ids get_cmd_id(const char *cmd) 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); 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_charbuf2 = 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) return 0; @@ -485,8 +486,8 @@ out_set_replaygain: int mpd_close_handler(struct mg_connection *c) { /* Cleanup session data */ -// if(c->connection_param) -// free(c->connection_param); + if(c->user_data) + free(c->user_data); return 0; } @@ -505,10 +506,10 @@ static int mpd_notify_callback(struct mg_connection *c, const char *param) { return 0; } - if(!c->connection_param) - c->connection_param = calloc(1, sizeof(struct t_mpd_client_session)); + if(!c->user_data) + 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) { n = snprintf(mpd.buf, MAX_SIZE, "{\"type\":\"disconnected\"}"); diff --git a/src/mpd_client.h b/src/mpd_client.h index 770dbbf..4ae484a 100644 --- a/src/mpd_client.h +++ b/src/mpd_client.h @@ -131,7 +131,7 @@ struct t_mpd_client_session { }; 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_put_state(char *buffer, int *current_song_id, int *next_song_id, unsigned *queue_version); int mpd_put_outputs(char *buffer, int putnames); diff --git a/src/mympd.c b/src/mympd.c index 935fdf4..5e5038a 100644 --- a/src/mympd.c +++ b/src/mympd.c @@ -46,11 +46,14 @@ static void signal_handler(int sig_num) { static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { switch(ev) { case MG_EV_CLOSE: { - mpd_close_handler(nc); + if (is_websocket(nc)) { + mpd_close_handler(nc); + } break; } case MG_EV_WEBSOCKET_FRAME: { struct websocket_message *wm = (struct websocket_message *) ev_data; + wm->data[wm->size]='\0'; struct mg_str d = {(char *) wm->data, wm->size}; callback_mpd(nc, d); break;