Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 5669af5c rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Adding functions to alter continuation state of a client.

parent 7eccb2b7
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!56Search
...@@ -46,6 +46,10 @@ struct lkt_state { ...@@ -46,6 +46,10 @@ struct lkt_state {
/* Send a message to the connected client. */ /* Send a message to the connected client. */
void lkt_state_send(struct lkt_state *srv, size_t c, struct lkt_message *msg); 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. /* 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 */ * Return a pointer to the client's mask */
enum mpd_idle_flag *lkt_client_get_mask(struct lkt_state *srv, size_t c); enum mpd_idle_flag *lkt_client_get_mask(struct lkt_state *srv, size_t c);
......
...@@ -54,13 +54,25 @@ struct lkt_client { ...@@ -54,13 +54,25 @@ struct lkt_client {
bool request_close; bool request_close;
bool authentificated; bool authentificated;
int continuation;
}; };
static bool static inline bool
lkt_close_client(struct lkt_state *srv, size_t c) lkt_close_client(struct lkt_state *srv, size_t c)
{ {
srv->clients[c - 1].request_close = true; return srv->clients[c - 1].request_close = true;
return 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 void
...@@ -77,6 +89,15 @@ lkt_state_send(struct lkt_state *srv, size_t c, struct lkt_message *msg) ...@@ -77,6 +89,15 @@ lkt_state_send(struct lkt_state *srv, size_t c, struct lkt_message *msg)
srv->fds[c].events |= POLLOUT; 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 static void
send_ok(struct lkt_state *srv, size_t c) 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) ...@@ -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)) { switch (*lkt_client_get_mask(srv, c)) {
case MPD_IDLE_NONE: 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 (lkt_client_auth(srv, c, false)) {
if (!strcmp(cmd.name, "__adduser")) { if (!strcmp(cmd.name, "__adduser")) {
err = !command_user_add(srv->db, cmd.args); 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) ...@@ -164,6 +186,10 @@ handle_simple_command(struct lkt_state *srv, size_t c, struct lkt_command cmd)
err = !lkt_close_client(srv, c); err = !lkt_close_client(srv, c);
else if (!strcmp(cmd.name, "ping")) else if (!strcmp(cmd.name, "ping"))
err = 0; 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")) else if (!strcmp(cmd.name, "next"))
err = !command_next(srv->db, &srv->win, &srv->mpd_idle_events); err = !command_next(srv->db, &srv->win, &srv->mpd_idle_events);
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter