diff --git a/inc/lektor/defines.h b/inc/lektor/defines.h index 600d4b503c1157c510fa4f94eb0d5cc77939c79a..c6eac5cdabfa5a5119f7f8be73bd1c53f2e2603c 100644 --- a/inc/lektor/defines.h +++ b/inc/lektor/defines.h @@ -9,7 +9,7 @@ #define LKT_DATABASE_NAME_KTITLE "song_title" #define LKT_DATABASE_NAME_KCAT "song_type" #define LKT_DATABASE_NAME_KTYPE "category" -#define LKT_DATABASE_NAME_KAUTHOR "author" +#define LKT_DATABASE_NAME_KAUTHOR "author_name" #define LKT_DATABASE_NAME_KAUTHOR_YEAR "author_year" #define LKT_DATABASE_NAME_KLANG "language" #define LKT_DATABASE_KARA_COLUMNT_ANY "any_col" diff --git a/src/commands.c b/src/commands.c index 1c5254629204d094134de368286e49adac14bd12..743d2f25d1d65674ad6f8609288404f83872512a 100644 --- a/src/commands.c +++ b/src/commands.c @@ -608,7 +608,7 @@ command_find(struct lkt_state *srv, !strcasecmp("all", mpd_tag) || !strcasecmp("a", mpd_tag)) col_name = LKT_DATABASE_KARA_COLUMNT_ANY; - else if (!strcasecmp("author", mpd_tag)) + else if (!strcasecmp("author", mpd_tag) || !(strcasecmp("auth", mpd_tag))) col_name = LKT_DATABASE_NAME_KAUTHOR; else if (!strcasecmp("source", mpd_tag)) col_name = LKT_DATABASE_NAME_KNAME; @@ -656,6 +656,7 @@ no_rgx: LKT_MESSAGE_MAX, "No kara found with regex\n"); lkt_state_send(srv, c, not_found_msg); + return false; } return true; diff --git a/src/main/lkt.c b/src/main/lkt.c index d28fb1a93bfa1d9447b2cc41cf08b1a1b780c16d..0ec6f25bf6141901f63b5f6cc027375eb58b7335 100644 --- a/src/main/lkt.c +++ b/src/main/lkt.c @@ -55,14 +55,22 @@ help(void) " shuffle: shuffle lektor's playlist and play it from the begening.\n" " queue <?arg>: prints the queue. The argument is either a range or a count from the current kara.\n" " plt: the playlist sub command.\n" + " search: the search sub command.\n" "\n" " PLAYLIST COMMANDS:\n" - " help: display this help message\n" + " help: display this help message.\n" " create <plt>: creates a playlist after the argument.\n" " destroy <plt>: delete a playlist after the argument.\n" " add <plt> <type> <query>: add something to a playlist from the database.\n" " delete: <plt> <id>: delete domething from a playlist.\n" "\n" + " SEARCH COMMANDS:\n" + " help: display this help message.\n" + " get <query>: prints the results of the query.\n" + " add <query>: add to the queue and prints the results of the query.\n" + " insert <query>: insert on top of the aueue and prints the results of the query.\n" + " plt <plt> <query>: search inside a playlist and prints the results.\n" + "\n" " QUERY:\n" " A query is passed in argument of a COMMAND and is composed of:\n" " - The first word must be the type\n" @@ -639,7 +647,6 @@ plt_delete__(struct lkt_cmd_args *args) write_socket(sock, args->argv[i], strlen(args->argv[i])); write_socket(sock, "\n", sizeof(char)); - assert(read_socket(sock, buff, 2) > 0); if (buff[0] == 'O' && buff[1] == 'K') exit(EXIT_SUCCESS); @@ -689,17 +696,96 @@ plt_create__(struct lkt_cmd_args *args) exit(EXIT_FAILURE); } +/* Search functions. */ + +noreturn void +search_with_cmd__(struct lkt_cmd_args *args, const char *cmd) +{ + if (args->argc < 2) + fail("Invalid number of arguments, need at least a valid query"); + + if (!lkt_valid_type(args->argv[0])) + fail("Invalid type for the query"); + + FILE *sock = lkt_connect(); + const size_t buff_len = 1025; + char buff[buff_len]; + int i; + + write_socket(sock, cmd, strlen(cmd)); + + for (i = 0; i < args->argc; ++i) + write_socket_format(sock, " %s", args->argv[i]); + write_socket(sock, "\n", sizeof("\n") / sizeof(char)); + + for (;;) { + memset(buff, 0, buff_len * sizeof(char)); + assert(read_socket(sock, buff, buff_len - 1) > 0); + + if (! strncmp(buff, "OK", 2)) + exit(EXIT_SUCCESS); + else if (! strncmp(buff, "ACK", 3)) + exit(EXIT_FAILURE); + + fprintf(stdout, "%s", buff); + } +} + +noreturn void +search_get__(struct lkt_cmd_args *args) +{ + search_with_cmd__(args, "search"); +} + +noreturn void +search_add__(struct lkt_cmd_args *args) +{ + search_with_cmd__(args, "searchadd"); +} + +noreturn void +search_insert__(struct lkt_cmd_args *args) +{ + (void) args; + fail("Not implemented"); +} + +noreturn void +search_plt__(struct lkt_cmd_args *args) +{ + (void) args; + fail("Not implemented"); +} + /* Parsing stuff. */ static struct lkt_cmd_opt options_plt[] = { - { .name = "help", .call = help__ }, - { .name = "add", .call = plt_add__ }, - { .name = "delete", .call = plt_delete__ }, - { .name = "destroy", .call = plt_destroy__ }, - { .name = "create", .call = plt_create__ }, + { .name = "help", .call = help__ }, + { .name = "add", .call = plt_add__ }, + { .name = "delete", .call = plt_delete__ }, + { .name = "destroy", .call = plt_destroy__ }, + { .name = "create", .call = plt_create__ }, + LKT_OPT_NULL, +}; + +static struct lkt_cmd_opt options_search[] = { + { .name = "help", .call = help__ }, + { .name = "get", .call = search_get__ }, + { .name = "add", .call = search_add__ }, + { .name = "insert", .call = search_insert__ }, + { .name = "plt", .call = search_plt__ }, LKT_OPT_NULL, }; +noreturn void +search__(struct lkt_cmd_args *args) +{ + if (args->argc == 0) + fail("Invalid argument, you must specify a sub command for the search command"); + + lkt_cmd_parse(options_search, args->argc, args->argv, help); +} + noreturn void plt__(struct lkt_cmd_args *args) { @@ -722,6 +808,7 @@ static struct lkt_cmd_opt options_[] = { { .name = "shuffle", .call = shuffle__ }, { .name = "status", .call = status__ }, { .name = "plt", .call = plt__ }, + { .name = "search", .call = search__ }, LKT_OPT_NULL, };