diff options
author | Max Kellermann <max@duempel.org> | 2015-08-06 22:10:25 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-08-12 08:41:05 +0200 |
commit | 7652a2986b0d0ad55b2776685130f1c68d7108c7 (patch) | |
tree | b4d45e60e97757454f1ff8e4dc793a1e7d852c36 /src/protocol | |
parent | b1480167be487d09ff46bb86ad02041fb28acff1 (diff) | |
download | mpd-7652a2986b0d0ad55b2776685130f1c68d7108c7.tar.gz mpd-7652a2986b0d0ad55b2776685130f1c68d7108c7.tar.xz mpd-7652a2986b0d0ad55b2776685130f1c68d7108c7.zip |
client/Response: new Client wrapper class for writing responses
Diffstat (limited to 'src/protocol')
-rw-r--r-- | src/protocol/ArgParser.cxx | 65 | ||||
-rw-r--r-- | src/protocol/ArgParser.hxx | 22 |
2 files changed, 40 insertions, 47 deletions
diff --git a/src/protocol/ArgParser.cxx b/src/protocol/ArgParser.cxx index 580d70a20..31756f53e 100644 --- a/src/protocol/ArgParser.cxx +++ b/src/protocol/ArgParser.cxx @@ -19,27 +19,26 @@ #include "config.h" #include "ArgParser.hxx" -#include "Result.hxx" #include "Chrono.hxx" +#include "client/Response.hxx" #include <stdlib.h> bool -check_uint32(Client &client, uint32_t *dst, const char *s) +ParseCommandArg32(Response &r, uint32_t &value_r, const char *s) { char *test; - *dst = strtoul(s, &test, 10); + value_r = strtoul(s, &test, 10); if (test == s || *test != '\0') { - command_error(client, ACK_ERROR_ARG, - "Integer expected: %s", s); + r.FormatError(ACK_ERROR_ARG, "Integer expected: %s", s); return false; } return true; } bool -ParseCommandArg(Client &client, int &value_r, const char *s, +ParseCommandArg(Response &r, int &value_r, const char *s, int min_value, int max_value) { char *test; @@ -47,14 +46,12 @@ ParseCommandArg(Client &client, int &value_r, const char *s, value = strtol(s, &test, 10); if (test == s || *test != '\0') { - command_error(client, ACK_ERROR_ARG, - "Integer expected: %s", s); + r.FormatError(ACK_ERROR_ARG, "Integer expected: %s", s); return false; } if (value < min_value || value > max_value) { - command_error(client, ACK_ERROR_ARG, - "Number too large: %s", s); + r.FormatError(ACK_ERROR_ARG, "Number too large: %s", s); return false; } @@ -63,22 +60,22 @@ ParseCommandArg(Client &client, int &value_r, const char *s, } bool -ParseCommandArg(Client &client, int &value_r, const char *s) +ParseCommandArg(Response &r, int &value_r, const char *s) { - return ParseCommandArg(client, value_r, s, + return ParseCommandArg(r, value_r, s, std::numeric_limits<int>::min(), std::numeric_limits<int>::max()); } bool -ParseCommandArg(Client &client, RangeArg &value_r, const char *s) +ParseCommandArg(Response &r, RangeArg &value_r, const char *s) { char *test, *test2; long value; value = strtol(s, &test, 10); if (test == s || (*test != '\0' && *test != ':')) { - command_error(client, ACK_ERROR_ARG, + r.FormatError(ACK_ERROR_ARG, "Integer or range expected: %s", s); return false; } @@ -92,14 +89,12 @@ ParseCommandArg(Client &client, RangeArg &value_r, const char *s) } if (value < 0) { - command_error(client, ACK_ERROR_ARG, - "Number is negative: %s", s); + r.FormatError(ACK_ERROR_ARG, "Number is negative: %s", s); return false; } if (unsigned(value) > std::numeric_limits<unsigned>::max()) { - command_error(client, ACK_ERROR_ARG, - "Number too large: %s", s); + r.FormatError(ACK_ERROR_ARG, "Number too large: %s", s); return false; } @@ -108,7 +103,7 @@ ParseCommandArg(Client &client, RangeArg &value_r, const char *s) if (*test == ':') { value = strtol(++test, &test2, 10); if (*test2 != '\0') { - command_error(client, ACK_ERROR_ARG, + r.FormatError(ACK_ERROR_ARG, "Integer or range expected: %s", s); return false; } @@ -117,13 +112,13 @@ ParseCommandArg(Client &client, RangeArg &value_r, const char *s) value = std::numeric_limits<int>::max(); if (value < 0) { - command_error(client, ACK_ERROR_ARG, + r.FormatError(ACK_ERROR_ARG, "Number is negative: %s", s); return false; } if (unsigned(value) > std::numeric_limits<unsigned>::max()) { - command_error(client, ACK_ERROR_ARG, + r.FormatError(ACK_ERROR_ARG, "Number too large: %s", s); return false; } @@ -137,7 +132,7 @@ ParseCommandArg(Client &client, RangeArg &value_r, const char *s) } bool -ParseCommandArg(Client &client, unsigned &value_r, const char *s, +ParseCommandArg(Response &r, unsigned &value_r, const char *s, unsigned max_value) { unsigned long value; @@ -145,13 +140,12 @@ ParseCommandArg(Client &client, unsigned &value_r, const char *s, value = strtoul(s, &endptr, 10); if (endptr == s || *endptr != 0) { - command_error(client, ACK_ERROR_ARG, - "Integer expected: %s", s); + r.FormatError(ACK_ERROR_ARG, "Integer expected: %s", s); return false; } if (value > max_value) { - command_error(client, ACK_ERROR_ARG, + r.FormatError(ACK_ERROR_ARG, "Number too large: %s", s); return false; } @@ -161,21 +155,21 @@ ParseCommandArg(Client &client, unsigned &value_r, const char *s, } bool -ParseCommandArg(Client &client, unsigned &value_r, const char *s) +ParseCommandArg(Response &r, unsigned &value_r, const char *s) { - return ParseCommandArg(client, value_r, s, + return ParseCommandArg(r, value_r, s, std::numeric_limits<unsigned>::max()); } bool -ParseCommandArg(Client &client, bool &value_r, const char *s) +ParseCommandArg(Response &r, bool &value_r, const char *s) { long value; char *endptr; value = strtol(s, &endptr, 10); if (endptr == s || *endptr != 0 || (value != 0 && value != 1)) { - command_error(client, ACK_ERROR_ARG, + r.FormatError(ACK_ERROR_ARG, "Boolean (0/1) expected: %s", s); return false; } @@ -185,15 +179,14 @@ ParseCommandArg(Client &client, bool &value_r, const char *s) } bool -ParseCommandArg(Client &client, float &value_r, const char *s) +ParseCommandArg(Response &r, float &value_r, const char *s) { float value; char *endptr; value = strtof(s, &endptr); if (endptr == s || *endptr != 0) { - command_error(client, ACK_ERROR_ARG, - "Float expected: %s", s); + r.FormatError(ACK_ERROR_ARG, "Float expected: %s", s); return false; } @@ -202,10 +195,10 @@ ParseCommandArg(Client &client, float &value_r, const char *s) } bool -ParseCommandArg(Client &client, SongTime &value_r, const char *s) +ParseCommandArg(Response &r, SongTime &value_r, const char *s) { float value; - bool success = ParseCommandArg(client, value, s) && value >= 0; + bool success = ParseCommandArg(r, value, s) && value >= 0; if (success) value_r = SongTime::FromS(value); @@ -213,10 +206,10 @@ ParseCommandArg(Client &client, SongTime &value_r, const char *s) } bool -ParseCommandArg(Client &client, SignedSongTime &value_r, const char *s) +ParseCommandArg(Response &r, SignedSongTime &value_r, const char *s) { float value; - bool success = ParseCommandArg(client, value, s); + bool success = ParseCommandArg(r, value, s); if (success) value_r = SignedSongTime::FromS(value); diff --git a/src/protocol/ArgParser.hxx b/src/protocol/ArgParser.hxx index b05d7224e..f60dbdf50 100644 --- a/src/protocol/ArgParser.hxx +++ b/src/protocol/ArgParser.hxx @@ -26,19 +26,19 @@ #include <stdint.h> -class Client; +class Response; class SongTime; class SignedSongTime; bool -check_uint32(Client &client, uint32_t *dst, const char *s); +ParseCommandArg32(Response &r, uint32_t &value_r, const char *s); bool -ParseCommandArg(Client &client, int &value_r, const char *s, +ParseCommandArg(Response &r, int &value_r, const char *s, int min_value, int max_value); bool -ParseCommandArg(Client &client, int &value_r, const char *s); +ParseCommandArg(Response &r, int &value_r, const char *s); struct RangeArg { unsigned start, end; @@ -54,25 +54,25 @@ struct RangeArg { }; bool -ParseCommandArg(Client &client, RangeArg &value_r, const char *s); +ParseCommandArg(Response &r, RangeArg &value_r, const char *s); bool -ParseCommandArg(Client &client, unsigned &value_r, const char *s, +ParseCommandArg(Response &r, unsigned &value_r, const char *s, unsigned max_value); bool -ParseCommandArg(Client &client, unsigned &value_r, const char *s); +ParseCommandArg(Response &r, unsigned &value_r, const char *s); bool -ParseCommandArg(Client &client, bool &value_r, const char *s); +ParseCommandArg(Response &r, bool &value_r, const char *s); bool -ParseCommandArg(Client &client, float &value_r, const char *s); +ParseCommandArg(Response &r, float &value_r, const char *s); bool -ParseCommandArg(Client &client, SongTime &value_r, const char *s); +ParseCommandArg(Response &r, SongTime &value_r, const char *s); bool -ParseCommandArg(Client &client, SignedSongTime &value_r, const char *s); +ParseCommandArg(Response &r, SignedSongTime &value_r, const char *s); #endif |