controlapi: whitespace cleanup FileCGI; fix compiler warning

Origin commit data
------------------
Branch: ni/coolstream
Commit: c2c7f08c15
Author: vanhofen <vanhofen@gmx.de>
Date: 2016-02-18 (Thu, 18 Feb 2016)

Origin message was:
------------------
- controlapi: whitespace cleanup FileCGI; fix compiler warning

------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
vanhofen
2016-02-18 16:10:04 +01:00
parent 70a1324dff
commit 705aca9f2d
2 changed files with 42 additions and 48 deletions

View File

@@ -3136,11 +3136,11 @@ void CControlAPI::FileCGI(CyhookHandler *hh) {
std::string path = hh->ParamList["path"]; std::string path = hh->ParamList["path"];
if ((dirp = opendir(path.c_str()))) { if ((dirp = opendir(path.c_str()))) {
bool isFirstLine = true;
struct dirent *entry; struct dirent *entry;
std::vector<FileCGI_List> filelist; std::vector<FileCGI_List> filelist;
while ((entry = readdir(dirp))) { while ((entry = readdir(dirp))) {
if ( !strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..") ) continue; if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
continue;
std::string ftype; std::string ftype;
if (entry->d_type == DT_DIR) if (entry->d_type == DT_DIR)
ftype = "dir"; ftype = "dir";
@@ -3151,12 +3151,24 @@ void CControlAPI::FileCGI(CyhookHandler *hh) {
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;
filelist.push_back(FileCGI_List{std::string(entry->d_name),ftype,entry->d_type,fullname});
FileCGI_List listitem;
listitem.name = std::string(entry->d_name);
listitem.type_str = ftype;
listitem.type = entry->d_type;
listitem.fullname = fullname;
filelist.push_back(listitem);
} }
closedir(dirp); closedir(dirp);
if (hh->ParamList["sort"].empty())
sort(filelist.begin(), filelist.end(),fsort); if (hh->ParamList["sort"] != "false")
for(std::vector<FileCGI_List>::iterator f = filelist.begin(); f != filelist.end(); ++f) { sort(filelist.begin(), filelist.end(), fsort);
for(std::vector<FileCGI_List>::iterator f = filelist.begin(); f != filelist.end(); ++f)
{
bool got_next = (f != filelist.end()-1);
std::string item = ""; std::string item = "";
item += hh->outPair("name", hh->outValue(f->name.c_str()), true); 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_str", hh->outValue(f->type_str.c_str()), true);
@@ -3165,61 +3177,42 @@ void CControlAPI::FileCGI(CyhookHandler *hh) {
struct stat statbuf; struct stat statbuf;
if (stat(f->fullname.c_str(), &statbuf) != -1) { if (stat(f->fullname.c_str(), &statbuf) != -1) {
item item += hh->outPair("mode", string_printf("%xld", (long) statbuf.st_mode), true);
+= hh->outPair(
"mode",
string_printf("%xld",
(long) statbuf.st_mode), true);
/* Print out type, permissions, and number of links. */ /* Print out type, permissions, and number of links. */
//TODO: hh->printf("\t\t<permission>%10.10s</permission>\n", sperm (statbuf.st_mode)); //TODO: hh->printf("\t\t<permission>%10.10s</permission>\n", sperm (statbuf.st_mode));
item += hh->outPair("nlink", item += hh->outPair("nlink", string_printf("%d", statbuf.st_nlink), true);
string_printf("%d", statbuf.st_nlink), true);
/* Print out owner's name if it is found using getpwuid(). */ /* Print out owner's name if it is found using getpwuid(). */
struct passwd *pwd; struct passwd *pwd;
if ((pwd = getpwuid(statbuf.st_uid)) != NULL) { if ((pwd = getpwuid(statbuf.st_uid)) != NULL)
item += hh->outPair("user", pwd->pw_name, true); item += hh->outPair("user", pwd->pw_name, true);
} else
else { item += hh->outPair("user", string_printf("%d", statbuf.st_uid), true);
item += hh->outPair("user",
string_printf("%d", statbuf.st_uid), true);
}
/* Print out group name if it is found using getgrgid(). */ /* Print out group name if it is found using getgrgid(). */
struct group *grp; struct group *grp;
if ((grp = getgrgid(statbuf.st_gid)) != NULL) if ((grp = getgrgid(statbuf.st_gid)) != NULL)
item += hh->outPair("group", grp->gr_name, true); item += hh->outPair("group", grp->gr_name, true);
else { else
item += hh->outPair("group", item += hh->outPair("group", string_printf("%d", statbuf.st_gid), true);
string_printf("%d", statbuf.st_gid), true);
}
/* Print size of file. */ /* Print size of file. */
item += hh->outPair("size", item += hh->outPair("size", string_printf("%jd", (intmax_t) statbuf.st_size), true);
string_printf("%jd", (intmax_t) statbuf.st_size),
true);
struct tm *tm = localtime(&statbuf.st_mtime); struct tm *tm = localtime(&statbuf.st_mtime);
char datestring[256] = {0}; char datestring[256] = {0};
/* Get localized date string. */ /* Get localized date string. */
strftime(datestring, sizeof(datestring), strftime(datestring, sizeof(datestring), nl_langinfo(D_T_FMT), tm);
nl_langinfo(D_T_FMT), tm);
item += hh->outPair("time", hh->outValue(datestring), true); item += hh->outPair("time", hh->outValue(datestring), true);
item += hh->outPair("time_t", string_printf("%ld", (long) statbuf.st_mtime), false);
item += hh->outPair("time_t",
string_printf("%ld", (long) statbuf.st_mtime),
false);
} }
if(isFirstLine) result += hh->outArrayItem("item", item, got_next);
isFirstLine = false;
else
result += hh->outNext();
result += hh->outArrayItem("item", item, false);
} }
} }
result = hh->outArray("filelist", result); result = hh->outArray("filelist", result);
// write footer if (outType == json)
if (outType == json) {
hh->WriteLn(json_out_success(result)); hh->WriteLn(json_out_success(result));
}
else else
hh->WriteLn(result); hh->WriteLn(result);
} }

View File

@@ -33,7 +33,8 @@ private:
std::string type_str; std::string type_str;
unsigned char type; unsigned char type;
std::string fullname; std::string fullname;
bool operator () (FileCGI_List a,FileCGI_List b)
bool operator() (FileCGI_List a, FileCGI_List b)
{ {
return (a.name < b.name); return (a.name < b.name);
} }