lib/curl/Delegate: helper class for response body parsers

Eliminate duplicate code.
This commit is contained in:
Max Kellermann
2018-01-21 20:31:59 +01:00
parent 8b42fd0a28
commit 1da64fb79c
12 changed files with 375 additions and 162 deletions

View File

@@ -21,9 +21,8 @@
#define TIDAL_ERROR_PARSER_HXX
#include "check.h"
#include "lib/yajl/Handle.hxx"
#include "lib/yajl/ResponseParser.hxx"
#include <exception>
#include <string>
#include <map>
@@ -33,11 +32,9 @@ struct StringView;
/**
* Parse an error JSON response.
*/
class TidalErrorParser {
class TidalErrorParser final : public YajlResponseParser {
const unsigned status;
Yajl::Handle parser;
enum class State {
NONE,
USER_MESSAGE,
@@ -53,16 +50,9 @@ public:
TidalErrorParser(unsigned status,
const std::multimap<std::string, std::string> &headers);
/**
* Feed response body data into the JSON parser.
*/
void OnData(ConstBuffer<void> data);
/**
* Throw an exception describing the error condition. Call
* this at the end of the response body.
*/
void OnEnd();
protected:
/* virtual methods from CurlResponseParser */
void OnEnd() override;
public:
/* yajl callbacks */