mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-27 15:32:52 +02:00
controlapi: sort files alphabetical
Origin commit data
------------------
Branch: ni/coolstream
Commit: 21fbadaa8f
Author: TangoCash <eric@loxat.de>
Date: 2016-02-12 (Fri, 12 Feb 2016)
------------------
No further description and justification available within origin commit message!
------------------
This commit was generated by Migit
This commit is contained in:
@@ -3079,13 +3079,14 @@ void CControlAPI::ConfigCGI(CyhookHandler *hh) {
|
|||||||
*
|
*
|
||||||
* @par nhttpd-usage
|
* @par nhttpd-usage
|
||||||
* @code
|
* @code
|
||||||
* /control/file?action=list&path={path}[&format=|xml|json]
|
* /control/file?action=list&path={path}[&format=|xml|json][&sort=false]
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* @par example:
|
* @par example:
|
||||||
* @code
|
* @code
|
||||||
* /control/file?action=list&path=/
|
* /control/file?action=list&path=/
|
||||||
* /control/file?action=list&path=/&format=json
|
* /control/file?action=list&path=/&format=json
|
||||||
|
* /control/file?action=list&path=/&format=json&sort=false
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* @par output
|
* @par output
|
||||||
@@ -3137,10 +3138,9 @@ void CControlAPI::FileCGI(CyhookHandler *hh) {
|
|||||||
if ((dirp = opendir(path.c_str()))) {
|
if ((dirp = opendir(path.c_str()))) {
|
||||||
bool isFirstLine = true;
|
bool isFirstLine = true;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
|
std::vector<FileCGI_List> filelist;
|
||||||
while ((entry = readdir(dirp))) {
|
while ((entry = readdir(dirp))) {
|
||||||
std::string item = "";
|
if ( !strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..") ) continue;
|
||||||
item += hh->outPair("name",
|
|
||||||
hh->outValue(hh->outValue(entry->d_name)), true);
|
|
||||||
std::string ftype;
|
std::string ftype;
|
||||||
if (entry->d_type == DT_DIR)
|
if (entry->d_type == DT_DIR)
|
||||||
ftype = "dir";
|
ftype = "dir";
|
||||||
@@ -3148,17 +3148,23 @@ void CControlAPI::FileCGI(CyhookHandler *hh) {
|
|||||||
ftype = "lnk";
|
ftype = "lnk";
|
||||||
else if (entry->d_type == 8)
|
else if (entry->d_type == 8)
|
||||||
ftype = "file";
|
ftype = "file";
|
||||||
|
|
||||||
item += hh->outPair("type_str", ftype, true);
|
|
||||||
item += hh->outPair("type",
|
|
||||||
string_printf("%d", (int) entry->d_type), true);
|
|
||||||
if (path[path.length() - 1] != '/')
|
if (path[path.length() - 1] != '/')
|
||||||
path += "/";
|
path += "/";
|
||||||
std::string fullname = path + entry->d_name;
|
std::string fullname = path + entry->d_name;
|
||||||
item += hh->outPair("fullname", hh->outValue(fullname), true);
|
filelist.push_back(FileCGI_List{std::string(entry->d_name),ftype,entry->d_type,fullname});
|
||||||
|
}
|
||||||
|
closedir(dirp);
|
||||||
|
if (hh->ParamList["sort"].empty())
|
||||||
|
sort(filelist.begin(), filelist.end(),fsort);
|
||||||
|
for(std::vector<FileCGI_List>::iterator f = filelist.begin(); f != filelist.end(); ++f) {
|
||||||
|
std::string item = "";
|
||||||
|
item += hh->outPair("name", hh->outValue(f->name.c_str()), true);
|
||||||
|
item += hh->outPair("type_str", hh->outValue(f->type_str.c_str()), true);
|
||||||
|
item += hh->outPair("type", string_printf("%d", (int) f->type), true);
|
||||||
|
item += hh->outPair("fullname", hh->outValue(f->fullname.c_str()), true);
|
||||||
|
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
if (stat(fullname.c_str(), &statbuf) != -1) {
|
if (stat(f->fullname.c_str(), &statbuf) != -1) {
|
||||||
item
|
item
|
||||||
+= hh->outPair(
|
+= hh->outPair(
|
||||||
"mode",
|
"mode",
|
||||||
@@ -3208,7 +3214,6 @@ void CControlAPI::FileCGI(CyhookHandler *hh) {
|
|||||||
result += hh->outNext();
|
result += hh->outNext();
|
||||||
result += hh->outArrayItem("item", item, false);
|
result += hh->outArrayItem("item", item, false);
|
||||||
}
|
}
|
||||||
closedir(dirp);
|
|
||||||
}
|
}
|
||||||
result = hh->outArray("filelist", result);
|
result = hh->outArray("filelist", result);
|
||||||
// write footer
|
// write footer
|
||||||
|
@@ -27,6 +27,18 @@ private:
|
|||||||
} TyCgiCall;
|
} TyCgiCall;
|
||||||
const static TyCgiCall yCgiCallList[];
|
const static TyCgiCall yCgiCallList[];
|
||||||
|
|
||||||
|
struct FileCGI_List
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
std::string type_str;
|
||||||
|
unsigned char type;
|
||||||
|
std::string fullname;
|
||||||
|
bool operator () (FileCGI_List a,FileCGI_List b)
|
||||||
|
{
|
||||||
|
return (a.name < b.name);
|
||||||
|
}
|
||||||
|
} fsort;
|
||||||
|
|
||||||
int rc_send(int ev, unsigned int code, unsigned int value);
|
int rc_send(int ev, unsigned int code, unsigned int value);
|
||||||
|
|
||||||
// send functions for ExecuteCGI (controld api)
|
// send functions for ExecuteCGI (controld api)
|
||||||
|
Reference in New Issue
Block a user