From 54371add1349e72684506868f72ee4919fd69b0a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 7 Sep 2008 13:51:59 +0200 Subject: command: added command_success() and command_error() These two functions take a client struct instead of the file descriptor. We will now begin passing the client struct around instead of a raw file descriptor (which needed a linear lookup in the client list to be useful). --- src/client.c | 4 ++-- src/command.c | 28 ++++++++++++++++++++++++++++ src/command.h | 8 +++++--- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/client.c b/src/client.c index fd0695cc3..9bb0b224c 100644 --- a/src/client.c +++ b/src/client.c @@ -348,7 +348,7 @@ static int client_process_line(struct client *client) } if (ret == 0) - commandSuccess(client->fd); + command_success(client); client_write_output(client); free_cmd_list(client->cmd_list); @@ -394,7 +394,7 @@ static int client_process_line(struct client *client) } if (ret == 0) - commandSuccess(client->fd); + command_success(client); client_write_output(client); } diff --git a/src/command.c b/src/command.c index 9b579e37d..2b81aaf92 100644 --- a/src/command.c +++ b/src/command.c @@ -186,6 +186,34 @@ static void command_error_va(int fd, int error, const char *fmt, va_list args) } } +void command_success(struct client *client) +{ + client_puts(client, "OK\n"); +} + +static void command_error_v(struct client *client, int error, + const char *fmt, va_list args) +{ + assert(client != NULL); + assert(current_command != NULL); + + client_printf(client, "ACK [%i@%i] {%s} ", + (int)error, command_listNum, current_command); + client_vprintf(client, fmt, args); + client_puts(client, "\n"); + + current_command = NULL; +} + +mpd_fprintf_ void command_error(struct client *client, int error, + const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + command_error_v(client, error, fmt, args); + va_end(args); +} + static int mpd_fprintf__ check_uint32(int fd, mpd_uint32 *dst, const char *s, const char *fmt, ...) { diff --git a/src/command.h b/src/command.h index 1018102cd..594ca2724 100644 --- a/src/command.h +++ b/src/command.h @@ -22,7 +22,6 @@ #include "gcc.h" #include "os_compat.h" #include "sllist.h" -#include "myfprintf.h" #define COMMAND_RETURN_KILL 10 #define COMMAND_RETURN_CLOSE 20 @@ -40,8 +39,11 @@ void initCommands(void); void finishCommands(void); -#define commandSuccess(fd) fdprintf(fd, "OK\n") - mpd_fprintf_ void commandError(int fd, int error, const char *fmt, ...); +void command_success(struct client *client); + +mpd_fprintf_ void command_error(struct client *client, int error, + const char *fmt, ...); + #endif -- cgit v1.2.3