From c7c4c23e5faea2182b8f9d18d12a31608e428f28 Mon Sep 17 00:00:00 2001 From: Dan Mick Date: Tue, 23 Jul 2013 17:23:50 -0700 Subject: [PATCH] Formatter, admin_socket: make default formatter be json-pretty If not given, default to json-pretty; if given but not equal to one of the formatter choices, return NULL as before. Remove defaulting code in admin_socket.cc in favor of this. Signed-off-by: Dan Mick --- src/common/Formatter.cc | 14 +++++++++----- src/common/Formatter.h | 2 +- src/common/admin_socket.cc | 11 +---------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/common/Formatter.cc b/src/common/Formatter.cc index 357b287fe3222..7362684c070eb 100644 --- a/src/common/Formatter.cc +++ b/src/common/Formatter.cc @@ -62,15 +62,19 @@ Formatter::~Formatter() } Formatter * -new_formatter(const std::string &type) +new_formatter(const std::string type) { - if (type == "json") + std::string mytype = type; + if (mytype == "") + mytype = "json-pretty"; + + if (mytype == "json") return new JSONFormatter(false); - else if (type == "json-pretty") + else if (mytype == "json-pretty") return new JSONFormatter(true); - else if (type == "xml") + else if (mytype == "xml") return new XMLFormatter(false); - else if (type == "xml-pretty") + else if (mytype == "xml-pretty") return new XMLFormatter(true); else return (Formatter *)NULL; diff --git a/src/common/Formatter.h b/src/common/Formatter.h index 8775c0cf9df5c..c62a8303ce113 100644 --- a/src/common/Formatter.h +++ b/src/common/Formatter.h @@ -60,7 +60,7 @@ class Formatter { } }; -Formatter *new_formatter(const std::string &type); +Formatter *new_formatter(const std::string type); class JSONFormatter : public Formatter { public: diff --git a/src/common/admin_socket.cc b/src/common/admin_socket.cc index 5ebb3e040db8d..4afd685b72acd 100644 --- a/src/common/admin_socket.cc +++ b/src/common/admin_socket.cc @@ -322,13 +322,6 @@ bool AdminSocket::do_accept() cmd_getval(m_cct, cmdmap, "format", format); cmd_getval(m_cct, cmdmap, "prefix", c); - // we don't do plain here - if (format != "json" && - format != "json-pretty" && - format != "xml" && - format != "xml-pretty") - format = "json"; - string firstword; if (c.find(" ") == string::npos) firstword = c; @@ -450,9 +443,7 @@ class HelpHook : public AdminSocketHook { public: HelpHook(AdminSocket *as) : m_as(as) {} bool call(string command, string args, string format, bufferlist& out) { - // override format here because help should always be pretty and - // predictable - Formatter *f = new_formatter("json-pretty"); + Formatter *f = new_formatter(format); f->open_object_section("help"); for (map::iterator p = m_as->m_help.begin(); p != m_as->m_help.end(); -- 2.39.5