From 8375f9ffb68ba73ec121718db19b05a5a89ad2b2 Mon Sep 17 00:00:00 2001 From: svenhoefer Date: Sat, 20 Feb 2016 14:28:59 +0100 Subject: [PATCH] - controlapi: add statfs output for a given path --- src/nhttpd/doc/nhttpd_controlapi.html | 13 +++++ src/nhttpd/tuxboxapi/controlapi.cpp | 82 +++++++++++++++++++++++++++ src/nhttpd/tuxboxapi/controlapi.h | 1 + 3 files changed, 96 insertions(+) diff --git a/src/nhttpd/doc/nhttpd_controlapi.html b/src/nhttpd/doc/nhttpd_controlapi.html index 864fa401f..cb8208cc5 100644 --- a/src/nhttpd/doc/nhttpd_controlapi.html +++ b/src/nhttpd/doc/nhttpd_controlapi.html @@ -251,6 +251,11 @@ http://box_ip/control/config + + Dateisystemstatistiken + + http://box_ip/control/statfs + Streaming URL anfordern @@ -2130,6 +2135,14 @@ Beispiel:
...
  + +
Dateisystemstatistiken
+
Handler: http://box_ip/control/statfs
+
+Parameter: keine oder path=<path>; format=<plain|xml|json>

+
+ +
Streaming URL anfordern
Handler: http://box_ip/control/build_live_url
diff --git a/src/nhttpd/tuxboxapi/controlapi.cpp b/src/nhttpd/tuxboxapi/controlapi.cpp index d3f292007..655023b1c 100644 --- a/src/nhttpd/tuxboxapi/controlapi.cpp +++ b/src/nhttpd/tuxboxapi/controlapi.cpp @@ -15,6 +15,7 @@ // system #include #include +#include // for statfs #include #include #include @@ -221,6 +222,7 @@ const CControlAPI::TyCgiCall CControlAPI::yCgiCallList[]= {"config", &CControlAPI::ConfigCGI, "text/plain"}, // filehandling {"file", &CControlAPI::FileCGI, "+xml"}, + {"statfs", &CControlAPI::StatfsCGI, "+xml"}, {"getdir", &CControlAPI::getDirCGI, "+xml"} @@ -3224,6 +3226,86 @@ void CControlAPI::FileCGI(CyhookHandler *hh) { } } +//----------------------------------------------------------------------------- +/** Get a list of statfs output for a given path + * + * @param hh CyhookHandler + * + * @par nhttpd-usage + * @code + * /control/statfs[?path={path}][&format=plain|xml|json] + * @endcode + * + * @par example: + * @code + * /control/statfs + * /control/statfs?path=/media/sda1/movies&format=json + * @endcode + * + * @par output + * @code + * {"success": "true", "data": + * { + * "statfs": [{ + * "path": "/media/sda1/movies", + * "f_type": "0x4d44", + * "f_bsize": "4096", + * "f_blocks": "488444", + * "f_bfree": "365874", + * "f_bavail": "365874", + * "f_files": "0", + * "f_ffree": "0", + * "f_fsid": "0x801, 0", + * "f_namelen": "1530", + * "f_frsize": "24" + * }] + * }} + * @endcode + */ +//----------------------------------------------------------------------------- +void CControlAPI::StatfsCGI(CyhookHandler *hh) { + std::string result = ""; + + if (hh->ParamList["path"].empty()) + hh->ParamList["path"] = "/"; + + TOutType outType = hh->outStart(); + + std::string path = hh->ParamList["path"]; + struct statfs s; + if (::statfs(path.c_str(), &s) == 0) + { + std::string item = ""; + item += hh->outPair("path", path.c_str(), true); + item += hh->outPair("f_type", string_printf("%#lx", (unsigned long) s.f_type), true); + item += hh->outPair("f_bsize", string_printf("%lu", (unsigned long) s.f_bsize), true); + item += hh->outPair("f_blocks", string_printf("%lu", (unsigned long) s.f_blocks), true); + item += hh->outPair("f_bfree", string_printf("%lu", (unsigned long) s.f_bfree), true); + item += hh->outPair("f_bavail", string_printf("%lu", (unsigned long) s.f_bavail), true); + item += hh->outPair("f_files", string_printf("%lu", (unsigned long) s.f_files), true); + item += hh->outPair("f_ffree", string_printf("%lu", (unsigned long) s.f_ffree), true); + item += hh->outPair("f_fsid", string_printf("%#x, %#x", (unsigned) s.f_fsid.__val[0], (unsigned) s.f_fsid.__val[1]), true); + item += hh->outPair("f_namelen", string_printf("%lu", (unsigned long) s.f_namelen), true); + item += hh->outPair("f_frsize", string_printf("%lu", (unsigned long) s.f_frsize), false); + + result = hh->outArrayItem("path", item, false); + result = hh->outArray("statfs", result); + + if (outType == json) + hh->WriteLn(json_out_success(result)); + else + hh->WriteLn(result); + } + else + { + if (outType == json) + hh->WriteLn(json_out_error("statfs failed")); + else + hh->SendError(); + } + +} + //----------------------------------------------------------------------------- /** Get neutrino directories * diff --git a/src/nhttpd/tuxboxapi/controlapi.h b/src/nhttpd/tuxboxapi/controlapi.h index a8a9c9d4e..1ba5dab7c 100644 --- a/src/nhttpd/tuxboxapi/controlapi.h +++ b/src/nhttpd/tuxboxapi/controlapi.h @@ -127,6 +127,7 @@ private: void logoCGI(CyhookHandler *hh); void ConfigCGI(CyhookHandler *hh); void FileCGI(CyhookHandler *hh); + void StatfsCGI(CyhookHandler *hh); void SignalInfoCGI(CyhookHandler *hh); void getDirCGI(CyhookHandler *hh); std::string getSubdirectories(CyhookHandler *hh, std::string path, std::string result);