diff --git a/src/database/stickers.c b/src/database/stickers.c index 4b8661b800f249bdf5fc9fd3cb7c80552c1a7b23..afeb6209b62dd438d7a9cc57e8e1cae23e7fc5b4 100644 --- a/src/database/stickers.c +++ b/src/database/stickers.c @@ -245,7 +245,7 @@ database_sticker_delete_specify(sqlite3 *db, const char *type, int uri, const ch } snprintf(SQL, LKT_MAX_SQLITE_STATEMENT - 1, "DELETE FROM 'stickers.%s' " - "WHERE 'stickers.%s' = ? ", type, type); + "WHERE 'stickers.%s' = ? ", type, type); SQL[LKT_MAX_SQLITE_STATEMENT - 1] = 0; /* If there is a name specified. */ diff --git a/src/main/lkt.c b/src/main/lkt.c index 9d812d84788d7783b62a2deaad1ca99a890f63ea..52ba9ababbf7bbedacc54bd9548a0d037efb44d7 100644 --- a/src/main/lkt.c +++ b/src/main/lkt.c @@ -21,6 +21,7 @@ #include <assert.h> #include <stdbool.h> #include <stdarg.h> +#include <limits.h> #define LKT_KEY_VALUE_SEP ": \n\t\0" #define STR_MATCH(str1, str2) (! strcasecmp(str1, str2)) @@ -47,6 +48,7 @@ help(void) " status: get the status of lektor.\n" " current: get the currently playing song.\n" " add <query>: add a kara to the playlist with a query.\n" + " delete <id>: delete the id or a range of ids from the queue.\n" " clear: clear the queue of lektor.\n" " prev: play previous kara in the queue.\n" " next: play the next kara in the queue.\n" @@ -477,6 +479,49 @@ shuffle__(struct lkt_cmd_args *args) lkt_send_and_exit(shuffle_str__, strlen(shuffle_str__)); } +noreturn void +delete__(struct lkt_cmd_args *args) +{ + if (args->argc != 1) + fail("Invalid argument, need onlt one argument"); + + static const char *cmd_range__ = "delete %s\nclose\n"; + static const char *cmd_id__ = "deleteid %s\nclose\n"; + int dumy1 = 0, dumy2 = 0;; + FILE *sock = lkt_connect(); + char buff[3]; + + /* Is this a range? matches only `int:` and `int:int` */ + sscanf(args->argv[0], "%d:%d", &dumy1, &dumy2); + if (dumy1 != 0 || dumy2 != 0) { + write_socket_format(sock, cmd_range__, args->argv[0]); + goto check; + } + + /* Ranges, matches `:int`. */ + sscanf(args->argv[0], ":%d", &dumy1); + if (dumy1 != 0) { + write_socket_format(sock, cmd_range__, args->argv[0]); + goto check; + } + + /* Or only an id? */ + sscanf(args->argv[0], "%d", &dumy1); + if (dumy1 != 0) { + write_socket_format(sock, cmd_id__, args->argv[0]); + goto check; + } + + fail("Invalid argument"); + +check: + assert(read_socket(sock, buff, 2) > 0); + if (buff[0] == 'O' && buff[1] == 'K') + exit(EXIT_SUCCESS); + else + exit(EXIT_FAILURE); +} + noreturn void add__(struct lkt_cmd_args *args) { @@ -488,7 +533,7 @@ add__(struct lkt_cmd_args *args) fail("Invalid argument, the add command should takes at least two arguments"); if (!lkt_valid_type(args->argv[0])) - fail("Invalid argument, the type given to the add command is invalid\n"); + fail("Invalid argument, the type given to the add command is invalid"); FILE *sock = lkt_connect(); @@ -683,6 +728,7 @@ static struct lkt_cmd_opt options_[] = { { .name = "clear", .call = clear__ }, { .name = "current", .call = current__ }, { .name = "play", .call = play__ }, + { .name = "delete", .call = delete__ }, { .name = "next", .call = next__ }, { .name = "previous", .call = prev__ }, { .name = "queue", .call = list__ }, diff --git a/src/net/listen.c b/src/net/listen.c index d42e68ffd5973791b9665e9c2bcf73282570daa4..b2705dfad7df5e5f9adf02125f798617334e3139 100644 --- a/src/net/listen.c +++ b/src/net/listen.c @@ -208,10 +208,10 @@ handle_simple_command(struct lkt_state *srv, size_t c, struct lkt_command cmd) err = !command_add(srv->db, &srv->win, cmd.args, &srv->mpd_idle_events); else if (!strcmp(cmd.name, "addid")) err = !command_addid(srv->db, &srv->win, cmd.args, &srv->mpd_idle_events); - else if (!strcmp(cmd.name, "delete")) - err = ! (cmd.args[0] != NULL && - command_del(srv->db, &srv->win, cmd.args[0], &srv->mpd_idle_events)); else if (!strcmp(cmd.name, "deleteid")) + err = ! (cmd.args[0] != NULL && + command_delid(srv->db, &srv->win, cmd.args[0], &srv->mpd_idle_events)); + else if (!strcmp(cmd.name, "delete")) err = ! (cmd.args[0] != NULL && command_del(srv->db, &srv->win, cmd.args[0], &srv->mpd_idle_events));