diff --git a/src/main/lkt.c b/src/main/lkt.c index 29390aa146aaf2043c02012e17e00f4e72f6e2e4..20895dc829b8d4e24d9f5af6a2e628a0c849ce16 100644 --- a/src/main/lkt.c +++ b/src/main/lkt.c @@ -182,6 +182,7 @@ just_send_one_arg(stickers_create__, "sticker __create") just_send_one_arg(stickers_destroy__, "sticker __destroy") just_send_one_arg(plt_destroy__, "rm") just_send_one_arg(plt_create__, "playlistadd") +just_send_one_arg(queue_dump__, "__dump") #undef just_send_one_arg #define just_send(func, msg) /* Just send a simple string functions */ \ @@ -841,10 +842,45 @@ redo: } } +noreturn void +search_plt__(struct lkt_cmd_args *args) +{ + fail_if(args->argc < 3, "Invalid number of arguments"); + fail_if(!lkt_valid_type(args->argv[1]), "Invalid type for query"); + char buff[LKT_MESSAGE_MAX]; + int continuation = 0, i; + FILE *sock = NULL; +redo: + sock = lkt_connect(); + + write_socket(sock, "%d listplaylist %s %s://", continuation, + args->argv[0], args->argv[1]); + for (i = 1; i < args->argc - 1; ++i) + write_socket(sock, "%s ", args->argv[i]); + write_socket(sock, "%s\n", args->argv[i]); + + for (;;) { + memset(buff, 0, LKT_MESSAGE_MAX * sizeof(char)); + read_socket(sock, buff, LKT_MESSAGE_MAX - 1); + + if (STR_NMATCH(buff, "continue:", strlen("continue:"))) { + continuation = atoi(lkt_skip_key(buff)); + fclose(sock); + goto redo; + } + + if (STR_NMATCH(buff, "OK", 2)) + exit(EXIT_SUCCESS); + else if (STR_NMATCH(buff, "ACK", 3)) + exit(EXIT_FAILURE); + + fprintf(stdout, "%s", buff); + } +} + #define search_with_cmd(func, cmd) /* I don't want to write always the same things */ \ noreturn void func (struct lkt_cmd_args *args) { search_with_cmd__(args, #cmd); } search_with_cmd(search_get__, search) -search_with_cmd(search_plt__, listplaylist) search_with_cmd(search_count__, count) search_with_cmd(search_queue__, playlistfind) #undef search_with_cmd @@ -861,6 +897,7 @@ static struct lkt_cmd_opt options_queue[] = { { .name = "clear", .call = queue_clear__ }, { .name = "crop", .call = queue_crop__ }, { .name = "replace", .call = queue_replace__ }, + { .name = "dump", .call = queue_dump__ }, LKT_OPT_DEFAULT(queue_list__), };