- controlapi: simplify result output

This commit is contained in:
svenhoefer
2016-02-21 00:16:42 +01:00
parent b48c1d6551
commit 1c73ca39e7

View File

@@ -1127,22 +1127,12 @@ void CControlAPI::GetBouquetCGI(CyhookHandler *hh) {
} }
} }
result = hh->outArray("channels", result); result = hh->outArray("channels", result);
// write footer
if (outType == json) { hh->SendResult(result);
hh->WriteLn(json_out_success(result));
}
else {
hh->WriteLn(result);
}
} }
} }
else { else
if (hh->ParamList["format"] == "json") { hh->SendError("no parameter");
hh->WriteLn(json_out_error("no parameter"));
}
else
hh->WriteLn("error");
}
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -1258,13 +1248,8 @@ void CControlAPI::GetBouquetsCGI(CyhookHandler *hh) {
} }
} }
result = hh->outArray("bouquets", result); result = hh->outArray("bouquets", result);
// write footer
if (outType == json) { hh->SendResult(result);
hh->WriteLn(json_out_success(result));
}
else {
hh->WriteLn(result);
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// details EPG Information for channelid // details EPG Information for channelid
@@ -1359,7 +1344,7 @@ void CControlAPI::epgDetailList(CyhookHandler *hh) {
} }
// ------ generate output ------ // ------ generate output ------
TOutType outType = hh->outStart(true /*old mode*/); hh->outStart(true /*old mode*/);
std::string result = ""; std::string result = "";
NeutrinoAPI->eList.clear(); NeutrinoAPI->eList.clear();
@@ -1400,13 +1385,8 @@ void CControlAPI::epgDetailList(CyhookHandler *hh) {
result = channelEPGformated(hh, 0, channel_id, max, stoptime); result = channelEPGformated(hh, 0, channel_id, max, stoptime);
result = hh->outCollection("epglist", result); result = hh->outCollection("epglist", result);
// write footer
if (outType == json) { hh->SendResult(result);
hh->WriteLn(json_out_success(result));
}
else {
hh->WriteLn(result);
}
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
inline static bool sortByDateTime (const CChannelEvent& a, const CChannelEvent& b) inline static bool sortByDateTime (const CChannelEvent& a, const CChannelEvent& b)
@@ -1459,7 +1439,7 @@ void CControlAPI::SendFoundEvents(CyhookHandler *hh, bool xml_format)
if (xml_format) // to stay backward compatible :/ if (xml_format) // to stay backward compatible :/
hh->ParamList["format"] = "xml"; hh->ParamList["format"] = "xml";
TOutType outType = hh->outStart(true /*old mode*/); hh->outStart(true /*old mode*/);
/* TODO: maybe add following options as in tuxbox neutrino /* TODO: maybe add following options as in tuxbox neutrino
hh->ParamList["epgitem"] hh->ParamList["epgitem"]
@@ -1593,16 +1573,13 @@ void CControlAPI::SendFoundEvents(CyhookHandler *hh, bool xml_format)
#endif #endif
} }
hh->WriteLn("----------------------------------------------------------"); hh->WriteLn("----------------------------------------------------------");
return;
} }
} }
} }
result = hh->outArray("epgsearch", result); result = hh->outArray("epgsearch", result);
if (outType == json) {
hh->WriteLn(json_out_success(result)); hh->SendResult(result);
}
else if (outType == xml) {
hh->WriteLn(result);
}
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -2998,7 +2975,7 @@ void CControlAPI::ConfigCGI(CyhookHandler *hh) {
std::string result = ""; std::string result = "";
std::string configFileName = hh->ParamList["config"]; std::string configFileName = hh->ParamList["config"];
TOutType outType = hh->outStart(); hh->outStart();
if (hh->ParamList["action"] == "submit") if (hh->ParamList["action"] == "submit")
load = false; load = false;
@@ -3048,15 +3025,10 @@ void CControlAPI::ConfigCGI(CyhookHandler *hh) {
error = string_printf("no config defined for %s", (hh->ParamList["config"]).c_str()); error = string_printf("no config defined for %s", (hh->ParamList["config"]).c_str());
} }
// write footer hh->WriteLn(hh->outCollection("config", result));
if (error.empty()) {
if (outType == json) { if (error.empty())
hh->WriteLn(json_out_success(result)); hh->SendResult(result);
}
else {
hh->WriteLn(hh->outCollection("config", result));
}
}
else else
hh->SendError(error); hh->SendError(error);
@@ -3123,7 +3095,7 @@ void CControlAPI::FileCGI(CyhookHandler *hh) {
if (hh->ParamList["action"] == "list") { // directory list: action=list&path=<path> if (hh->ParamList["action"] == "list") { // directory list: action=list&path=<path>
DIR *dirp; DIR *dirp;
TOutType outType = hh->outStart(); hh->outStart();
std::string path = hh->ParamList["path"]; std::string path = hh->ParamList["path"];
if ((dirp = opendir(path.c_str()))) { if ((dirp = opendir(path.c_str()))) {
@@ -3202,10 +3174,8 @@ void CControlAPI::FileCGI(CyhookHandler *hh) {
} }
} }
result = hh->outArray("filelist", result); result = hh->outArray("filelist", result);
if (outType == json)
hh->WriteLn(json_out_success(result)); hh->SendResult(result);
else
hh->WriteLn(result);
} }
// create new folder // create new folder
else if (hh->ParamList["action"] == "new_folder") { else if (hh->ParamList["action"] == "new_folder") {
@@ -3261,7 +3231,7 @@ void CControlAPI::StatfsCGI(CyhookHandler *hh) {
if (hh->ParamList["path"].empty()) if (hh->ParamList["path"].empty())
hh->ParamList["path"] = "/"; hh->ParamList["path"] = "/";
TOutType outType = hh->outStart(); hh->outStart();
std::string path = hh->ParamList["path"]; std::string path = hh->ParamList["path"];
struct statfs s; struct statfs s;
@@ -3283,10 +3253,7 @@ void CControlAPI::StatfsCGI(CyhookHandler *hh) {
result = hh->outArrayItem("path", item, false); result = hh->outArrayItem("path", item, false);
result = hh->outArray("statfs", result); result = hh->outArray("statfs", result);
if (outType == json) hh->SendResult(result);
hh->WriteLn(json_out_success(result));
else
hh->WriteLn(result);
} }
else else
hh->SendError("statfs failed"); hh->SendError("statfs failed");
@@ -3323,7 +3290,7 @@ void CControlAPI::getDirCGI(CyhookHandler *hh) {
std::string item = ""; std::string item = "";
bool isFirstLine = true; bool isFirstLine = true;
TOutType outType = hh->outStart(true /*old mode*/); hh->outStart(true /*old mode*/);
//Shows all 7 directories stored in the moviebrowser.conf //Shows all 7 directories stored in the moviebrowser.conf
if (hh->ParamList["dir"] == "moviedir" || hh->ParamList["dir"] == "allmoviedirs" ) { if (hh->ParamList["dir"] == "moviedir" || hh->ParamList["dir"] == "allmoviedirs" ) {
@@ -3373,13 +3340,8 @@ void CControlAPI::getDirCGI(CyhookHandler *hh) {
result = hh->outArray("dirs", result); result = hh->outArray("dirs", result);
// write footer
if (outType == json) { hh->SendResult(result);
hh->WriteLn(json_out_success(result));
}
else {
hh->WriteLn(result);
}
} }
//Helpfunction to get subdirs of a dir //Helpfunction to get subdirs of a dir