aboutsummaryrefslogtreecommitdiffstats
path: root/src/ClientProcess.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ClientProcess.cxx (renamed from src/client_process.c)43
1 files changed, 18 insertions, 25 deletions
diff --git a/src/client_process.c b/src/ClientProcess.cxx
index 57a8a7824..69b23e868 100644
--- a/src/client_process.c
+++ b/src/ClientProcess.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,7 +18,9 @@
*/
#include "config.h"
-#include "client_internal.h"
+#include "ClientInternal.hxx"
+#include "protocol/Result.hxx"
+#include "AllCommands.hxx"
#include <string.h>
@@ -27,13 +29,14 @@
#define CLIENT_LIST_MODE_END "command_list_end"
static enum command_return
-client_process_command_list(struct client *client, bool list_ok, GSList *list)
+client_process_command_list(Client *client, bool list_ok,
+ std::list<std::string> &&list)
{
enum command_return ret = COMMAND_RETURN_OK;
unsigned num = 0;
- for (GSList *cur = list; cur != NULL; cur = g_slist_next(cur)) {
- char *cmd = cur->data;
+ for (auto &&i : list) {
+ char *cmd = &*i.begin();
g_debug("command_process_list: process command \"%s\"",
cmd);
@@ -49,7 +52,7 @@ client_process_command_list(struct client *client, bool list_ok, GSList *list)
}
enum command_return
-client_process_line(struct client *client, char *line)
+client_process_line(Client *client, char *line)
{
enum command_return ret;
@@ -74,19 +77,16 @@ client_process_line(struct client *client, char *line)
return COMMAND_RETURN_CLOSE;
}
- if (client->cmd_list_OK >= 0) {
+ if (client->cmd_list.IsActive()) {
if (strcmp(line, CLIENT_LIST_MODE_END) == 0) {
g_debug("[%u] process command list",
client->num);
- /* for scalability reasons, we have prepended
- each new command; now we have to reverse it
- to restore the correct order */
- client->cmd_list = g_slist_reverse(client->cmd_list);
+ auto &&cmd_list = client->cmd_list.Commit();
ret = client_process_command_list(client,
- client->cmd_list_OK,
- client->cmd_list);
+ client->cmd_list.IsOKMode(),
+ std::move(cmd_list));
g_debug("[%u] process command "
"list returned %i", client->num, ret);
@@ -98,31 +98,24 @@ client_process_line(struct client *client, char *line)
command_success(client);
client_write_output(client);
- free_cmd_list(client->cmd_list);
- client->cmd_list = NULL;
- client->cmd_list_OK = -1;
+ client->cmd_list.Reset();
} else {
- size_t len = strlen(line) + 1;
- client->cmd_list_size += len;
- if (client->cmd_list_size >
- client_max_command_list_size) {
- g_warning("[%u] command list size (%lu) "
+ if (!client->cmd_list.Add(line)) {
+ g_warning("[%u] command list size "
"is larger than the max (%lu)",
client->num,
- (unsigned long)client->cmd_list_size,
(unsigned long)client_max_command_list_size);
return COMMAND_RETURN_CLOSE;
}
- new_cmd_list_ptr(client, line);
ret = COMMAND_RETURN_OK;
}
} else {
if (strcmp(line, CLIENT_LIST_MODE_BEGIN) == 0) {
- client->cmd_list_OK = 0;
+ client->cmd_list.Begin(false);
ret = COMMAND_RETURN_OK;
} else if (strcmp(line, CLIENT_LIST_OK_MODE_BEGIN) == 0) {
- client->cmd_list_OK = 1;
+ client->cmd_list.Begin(true);
ret = COMMAND_RETURN_OK;
} else {
g_debug("[%u] process command \"%s\"",