mirror of
https://github.com/SuperBFG7/ympd
synced 2025-05-14 05:04:10 +00:00
Revert "Fix handling of multiple client sessions (browsers)"
This reverts commit ac7ad51a0e4c49f43a2756f2368936d869f1f2f5.
This commit is contained in:
parent
ac7ad51a0e
commit
7a725e648d
@ -52,7 +52,6 @@ static inline enum mpd_cmd_ids get_cmd_id(char *cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int callback_mpd(struct mg_connection *c) {
|
int callback_mpd(struct mg_connection *c) {
|
||||||
struct t_mpd_client_session *s;
|
|
||||||
enum mpd_cmd_ids cmd_id = get_cmd_id(c->content);
|
enum mpd_cmd_ids cmd_id = get_cmd_id(c->content);
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
unsigned int uint_buf, uint_buf_2;
|
unsigned int uint_buf, uint_buf_2;
|
||||||
@ -62,7 +61,7 @@ int callback_mpd(struct mg_connection *c) {
|
|||||||
if (!c->connection_param)
|
if (!c->connection_param)
|
||||||
c->connection_param = calloc(1, sizeof(struct t_mpd_client_session));
|
c->connection_param = calloc(1, sizeof(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->connection_param;
|
||||||
|
|
||||||
if (!s->authorized && (cmd_id != MPD_API_AUTHORIZE)) {
|
if (!s->authorized && (cmd_id != MPD_API_AUTHORIZE)) {
|
||||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\":\"error\",\"data\":\"not authorized\"}");
|
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\":\"error\",\"data\":\"not authorized\"}");
|
||||||
@ -363,11 +362,9 @@ int callback_mpd(struct mg_connection *c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int mpd_close_handler(struct mg_connection *c) {
|
int mpd_close_handler(struct mg_connection *c) {
|
||||||
struct t_mpd_client_session *s;
|
|
||||||
|
|
||||||
/* Cleanup session data */
|
/* Cleanup session data */
|
||||||
if (c->connection_param) {
|
if (c->connection_param) {
|
||||||
s = (struct t_mpd_client_session *)c->connection_param;
|
struct t_mpd_client_session *s = (struct t_mpd_client_session *)c->connection_param;
|
||||||
if (s->auth_token)
|
if (s->auth_token)
|
||||||
free(s->auth_token);
|
free(s->auth_token);
|
||||||
free(c->connection_param);
|
free(c->connection_param);
|
||||||
@ -377,7 +374,6 @@ int mpd_close_handler(struct mg_connection *c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int mpd_notify_callback(struct mg_connection *c, enum mg_event ev) {
|
static int mpd_notify_callback(struct mg_connection *c, enum mg_event ev) {
|
||||||
struct t_mpd_client_session *s;
|
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
if (!c->is_websocket)
|
if (!c->is_websocket)
|
||||||
@ -386,7 +382,7 @@ static int mpd_notify_callback(struct mg_connection *c, enum mg_event ev) {
|
|||||||
if (!c->connection_param)
|
if (!c->connection_param)
|
||||||
return MG_TRUE;
|
return MG_TRUE;
|
||||||
|
|
||||||
s = (struct t_mpd_client_session *)c->connection_param;
|
struct t_mpd_client_session *s = (struct t_mpd_client_session *)c->connection_param;
|
||||||
|
|
||||||
if (!s->authorized)
|
if (!s->authorized)
|
||||||
return MG_TRUE;
|
return MG_TRUE;
|
||||||
@ -404,17 +400,7 @@ static int mpd_notify_callback(struct mg_connection *c, enum mg_event ev) {
|
|||||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\":\"disconnected\"}");
|
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\":\"disconnected\"}");
|
||||||
mg_websocket_write(c, 1, mpd.buf, n);
|
mg_websocket_write(c, 1, mpd.buf, n);
|
||||||
} else {
|
} else {
|
||||||
if (ev == MG_POLL) {
|
|
||||||
mpd.buf_size = mpd_put_state(mpd.buf, &mpd.song_id, &mpd.queue_version);
|
|
||||||
mg_websocket_write(c, 1, mpd.buf, mpd.buf_size);
|
mg_websocket_write(c, 1, mpd.buf, mpd.buf_size);
|
||||||
mpd.buf_size = mpd_put_outputs(mpd.buf, 0);
|
|
||||||
mg_websocket_write(c, 1, mpd.buf, mpd.buf_size);
|
|
||||||
mpd.buf_size = mpd_put_channels(mpd.buf);
|
|
||||||
mg_websocket_write(c, 1, mpd.buf, mpd.buf_size);
|
|
||||||
} else {
|
|
||||||
fprintf(stdout, "notify_callback: %i, %s\n", mpd.buf_size, mpd.buf);
|
|
||||||
mg_websocket_write(c, 1, mpd.buf, mpd.buf_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s->song_id != mpd.song_id) {
|
if (s->song_id != mpd.song_id) {
|
||||||
n = mpd_put_current_song(mpd.buf);
|
n = mpd_put_current_song(mpd.buf);
|
||||||
@ -487,20 +473,21 @@ void mpd_poll(struct mg_server *s) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MPD_CONNECTED:
|
case MPD_CONNECTED:
|
||||||
// mpd.buf_size = mpd_put_state(mpd.buf, &mpd.song_id, &mpd.queue_version);
|
mpd.buf_size = mpd_put_state(mpd.buf, &mpd.song_id, &mpd.queue_version);
|
||||||
for (struct mg_connection *c = mg_next(s, NULL); c != NULL; c = mg_next(s, c)) {
|
for (struct mg_connection *c = mg_next(s, NULL); c != NULL; c = mg_next(s, c)) {
|
||||||
c->callback_param = NULL;
|
c->callback_param = NULL;
|
||||||
mpd_notify_callback(c, MG_POLL);
|
mpd_notify_callback(c, MG_POLL);
|
||||||
}
|
}
|
||||||
/* mpd.buf_size = mpd_put_outputs(mpd.buf, 0);
|
mpd.buf_size = mpd_put_outputs(mpd.buf, 0);
|
||||||
for (struct mg_connection *c = mg_next(s, NULL); c != NULL; c = mg_next(s,
|
for (struct mg_connection *c = mg_next(s, NULL); c != NULL; c = mg_next(s, c)) {
|
||||||
c)) { c->callback_param = NULL; mpd_notify_callback(c, MG_POLL);
|
c->callback_param = NULL;
|
||||||
|
mpd_notify_callback(c, MG_POLL);
|
||||||
}
|
}
|
||||||
mpd.buf_size = mpd_put_channels(mpd.buf);
|
mpd.buf_size = mpd_put_channels(mpd.buf);
|
||||||
for (struct mg_connection *c = mg_next(s, NULL); c != NULL; c = mg_next(s,
|
for (struct mg_connection *c = mg_next(s, NULL); c != NULL; c = mg_next(s, c)) {
|
||||||
c)) { c->callback_param = NULL; mpd_notify_callback(c, MG_POLL);
|
c->callback_param = NULL;
|
||||||
|
mpd_notify_callback(c, MG_POLL);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user