diff --git a/inc/lektor/net.h b/inc/lektor/net.h index f862eb6dd44c0b86fd753e45af3a2721db6dc1d2..1ae6e87d132593d2cf810d3db21d47b3e163c714 100644 --- a/inc/lektor/net.h +++ b/inc/lektor/net.h @@ -46,6 +46,10 @@ struct lkt_state { /* Send a message to the connected client. */ void lkt_state_send(struct lkt_state *srv, size_t c, struct lkt_message *msg); +/* Get and set continuation state for a client. */ +bool lkt_get_continuation(struct lkt_state *srv, size_t c); +void lkt_set_continuation(struct lkt_state *srv, size_t c, int i); + /* Get the mask to watch for events for a given client, to be used with the `idle` command. * Return a pointer to the client's mask */ enum mpd_idle_flag *lkt_client_get_mask(struct lkt_state *srv, size_t c); diff --git a/src/net/listen.c b/src/net/listen.c index d2730be6cd85ef6dfd39ad3e7fdcf1250dfba296..2c7b7396dfda330ff11f7de95d2522716aa7286f 100644 --- a/src/net/listen.c +++ b/src/net/listen.c @@ -54,13 +54,25 @@ struct lkt_client { bool request_close; bool authentificated; + int continuation; }; -static bool +static inline bool lkt_close_client(struct lkt_state *srv, size_t c) { - srv->clients[c - 1].request_close = true; - return true; + return srv->clients[c - 1].request_close = true; +} + +inline bool +lkt_get_continuation(struct lkt_state *srv, size_t c) +{ + return srv->clients[c - 1].continuation; +} + +inline void +lkt_set_continuation(struct lkt_state *srv, size_t c, int i) +{ + srv->clients[c - 1].continuation = i; } void @@ -77,6 +89,15 @@ lkt_state_send(struct lkt_state *srv, size_t c, struct lkt_message *msg) srv->fds[c].events |= POLLOUT; } +static inline void +send_continue(struct lkt_state *srv, size_t c, int i) +{ + struct lkt_message *cont = lkt_message_new(); + cont->data_len = snprintf(cont->data, LKT_MESSAGE_MAX, "continue: %d\n", i); + cont->data[LKT_MESSAGE_MAX - 1] = '\0'; + lkt_state_send(srv, c, cont); +} + static void send_ok(struct lkt_state *srv, size_t c) { @@ -137,7 +158,8 @@ handle_simple_command(struct lkt_state *srv, size_t c, struct lkt_command cmd) switch (*lkt_client_get_mask(srv, c)) { case MPD_IDLE_NONE: - /* Commands that require authentification. */ + /* Commands that require authentification. + TODO: Move authentification verification inside commands. */ if (lkt_client_auth(srv, c, false)) { if (!strcmp(cmd.name, "__adduser")) { err = !command_user_add(srv->db, cmd.args); @@ -164,6 +186,10 @@ handle_simple_command(struct lkt_state *srv, size_t c, struct lkt_command cmd) err = !lkt_close_client(srv, c); else if (!strcmp(cmd.name, "ping")) err = 0; + else if (!strcmp(cmd.name, "continue")) { + srv->clients[c - 1].continuation = atoi(cmd.args[0]); + err = 0; + } else if (!strcmp(cmd.name, "next")) err = !command_next(srv->db, &srv->win, &srv->mpd_idle_events);