2018-01-21 12:17:18 +01:00
|
|
|
/*
|
2020-01-18 19:22:19 +01:00
|
|
|
* Copyright 2003-2020 The Music Player Daemon Project
|
2018-01-21 12:17:18 +01:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TIDAL_ERROR_PARSER_HXX
|
|
|
|
#define TIDAL_ERROR_PARSER_HXX
|
|
|
|
|
2018-01-21 20:31:59 +01:00
|
|
|
#include "lib/yajl/ResponseParser.hxx"
|
2018-01-21 12:17:18 +01:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
template<typename T> struct ConstBuffer;
|
|
|
|
struct StringView;
|
|
|
|
|
|
|
|
/**
|
2018-01-24 12:44:57 +01:00
|
|
|
* Parse an error JSON response and throw a #TidalError upon
|
|
|
|
* completion.
|
2018-01-21 12:17:18 +01:00
|
|
|
*/
|
2018-01-21 20:31:59 +01:00
|
|
|
class TidalErrorParser final : public YajlResponseParser {
|
2018-01-21 12:17:18 +01:00
|
|
|
const unsigned status;
|
|
|
|
|
|
|
|
enum class State {
|
|
|
|
NONE,
|
|
|
|
USER_MESSAGE,
|
2018-01-24 12:26:12 +01:00
|
|
|
SUB_STATUS,
|
2018-01-21 12:17:18 +01:00
|
|
|
} state = State::NONE;
|
|
|
|
|
2018-01-24 12:26:12 +01:00
|
|
|
unsigned sub_status = 0;
|
|
|
|
|
2018-01-21 12:17:18 +01:00
|
|
|
std::string message;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* May throw if there is a formal error in the response
|
|
|
|
* headers.
|
|
|
|
*/
|
|
|
|
TidalErrorParser(unsigned status,
|
|
|
|
const std::multimap<std::string, std::string> &headers);
|
|
|
|
|
2018-01-21 20:31:59 +01:00
|
|
|
protected:
|
|
|
|
/* virtual methods from CurlResponseParser */
|
|
|
|
void OnEnd() override;
|
2018-01-21 12:17:18 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
/* yajl callbacks */
|
2018-01-24 12:26:12 +01:00
|
|
|
bool Integer(long long value) noexcept;
|
2018-01-21 12:17:18 +01:00
|
|
|
bool String(StringView value) noexcept;
|
|
|
|
bool MapKey(StringView value) noexcept;
|
|
|
|
bool EndMap() noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|