mirror of
https://github.com/akuker/RASCSI.git
synced 2024-11-22 16:33:17 +00:00
Added optional folder name filter
This commit is contained in:
parent
ec31198d83
commit
29603a327a
@ -1488,8 +1488,8 @@ static void *MonThread(void *param)
|
||||
|
||||
PbResult result;
|
||||
result.set_allocated_server_info(rascsi_response.GetServerInfo(
|
||||
result, devices, reserved_ids, current_log_level, GetParam(command, "filename_pattern"),
|
||||
scan_depth));
|
||||
result, devices, reserved_ids, current_log_level, GetParam(command, "folder_pattern"),
|
||||
GetParam(command, "file_pattern"), scan_depth));
|
||||
SerializeMessage(fd, result);
|
||||
break;
|
||||
}
|
||||
@ -1517,7 +1517,7 @@ static void *MonThread(void *param)
|
||||
|
||||
PbResult result;
|
||||
result.set_allocated_image_files_info(rascsi_response.GetAvailableImages(result,
|
||||
GetParam(command, "filename_pattern"), scan_depth));
|
||||
GetParam(command, "folder_pattern"), GetParam(command, "file_pattern"), scan_depth));
|
||||
SerializeMessage(fd, result);
|
||||
break;
|
||||
}
|
||||
|
@ -68,7 +68,8 @@ enum PbOperation {
|
||||
|
||||
// Gets the server information (PbServerInfo). Calling this operation should be avoided because it
|
||||
// may return a lot of data. More specific other operations should be used instead.
|
||||
// "filename_pattern": Optional filter, only filenames containing the case-insensitive pattern are returned
|
||||
// "folder_pattern": Optional filter, only folder names containing the case-insensitive pattern are returned
|
||||
// "file_pattern": Optional filter, only filenames containing the case-insensitive pattern are returned
|
||||
SERVER_INFO = 10;
|
||||
|
||||
// Get rascsi version information (PbVersionInfo)
|
||||
@ -83,7 +84,8 @@ enum PbOperation {
|
||||
|
||||
// Get information on available image files in the default image folder (PbImageFilesInfo)
|
||||
// Parameters:
|
||||
// "filename_pattern": Optional filter, only filenames containing the case-insensitive pattern are returned
|
||||
// "folder_pattern": Optional filter, only folder names containing the case-insensitive pattern are returned
|
||||
// "file_pattern": Optional filter, only filenames containing the case-insensitive pattern are returned
|
||||
DEFAULT_IMAGE_FILES_INFO = 14;
|
||||
|
||||
// Get information on an image file (not necessarily in the default image folder) based on an absolute path.
|
||||
|
@ -141,9 +141,12 @@ bool RascsiResponse::GetImageFile(PbImageFile *image_file, const string& filenam
|
||||
}
|
||||
|
||||
void RascsiResponse::GetAvailableImages(PbImageFilesInfo& image_files_info, const string& default_image_folder,
|
||||
const string& folder, const string& pattern, int scan_depth) {
|
||||
string pattern_lower = pattern;
|
||||
transform(pattern_lower.begin(), pattern_lower.end(), pattern_lower.begin(), ::tolower);
|
||||
const string& folder, const string& folder_pattern, const string& file_pattern, int scan_depth) {
|
||||
string folder_pattern_lower = folder_pattern;
|
||||
transform(folder_pattern_lower.begin(), folder_pattern_lower.end(), folder_pattern_lower.begin(), ::tolower);
|
||||
|
||||
string file_pattern_lower = file_pattern;
|
||||
transform(file_pattern_lower.begin(), file_pattern_lower.end(), file_pattern_lower.begin(), ::tolower);
|
||||
|
||||
if (scan_depth-- >= 0) {
|
||||
DIR *d = opendir(folder.c_str());
|
||||
@ -153,7 +156,7 @@ void RascsiResponse::GetAvailableImages(PbImageFilesInfo& image_files_info, cons
|
||||
string filename = folder + "/" + dir->d_name;
|
||||
|
||||
string name_lower = filename;
|
||||
if (!pattern.empty()) {
|
||||
if (!file_pattern.empty()) {
|
||||
transform(name_lower.begin(), name_lower.end(), name_lower.begin(), ::tolower);
|
||||
}
|
||||
|
||||
@ -169,11 +172,14 @@ void RascsiResponse::GetAvailableImages(PbImageFilesInfo& image_files_info, cons
|
||||
LOGTRACE("Symlink '%s' in image folder '%s' is broken", dir->d_name, folder.c_str());
|
||||
continue;
|
||||
} else if (dir->d_type == DT_DIR) {
|
||||
GetAvailableImages(image_files_info, default_image_folder, filename, pattern, scan_depth);
|
||||
if (folder_pattern_lower.empty() || name_lower.find(folder_pattern_lower) != string::npos) {
|
||||
GetAvailableImages(image_files_info, default_image_folder, filename, folder_pattern,
|
||||
file_pattern, scan_depth);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pattern.empty() || name_lower.find(pattern_lower) != string::npos) {
|
||||
if (file_pattern_lower.empty() || name_lower.find(file_pattern_lower) != string::npos) {
|
||||
PbImageFile *image_file = new PbImageFile();
|
||||
if (GetImageFile(image_file, filename)) {
|
||||
GetImageFile(image_files_info.add_image_files(), filename.substr(default_image_folder.length() + 1));
|
||||
@ -188,23 +194,26 @@ void RascsiResponse::GetAvailableImages(PbImageFilesInfo& image_files_info, cons
|
||||
}
|
||||
}
|
||||
|
||||
PbImageFilesInfo *RascsiResponse::GetAvailableImages(PbResult& result, const string& pattern, int scan_depth)
|
||||
PbImageFilesInfo *RascsiResponse::GetAvailableImages(PbResult& result, const string& folder_pattern,
|
||||
const string& file_pattern, int scan_depth)
|
||||
{
|
||||
PbImageFilesInfo *image_files_info = new PbImageFilesInfo();
|
||||
|
||||
string default_image_folder = rascsi_image->GetDefaultImageFolder();
|
||||
image_files_info->set_default_image_folder(default_image_folder);
|
||||
|
||||
GetAvailableImages(*image_files_info, default_image_folder, default_image_folder, pattern, scan_depth);
|
||||
GetAvailableImages(*image_files_info, default_image_folder, default_image_folder, folder_pattern, file_pattern,
|
||||
scan_depth);
|
||||
|
||||
result.set_status(true);
|
||||
|
||||
return image_files_info;
|
||||
}
|
||||
|
||||
void RascsiResponse::GetAvailableImages(PbResult& result, PbServerInfo& server_info, const string& pattern, int scan_depth)
|
||||
void RascsiResponse::GetAvailableImages(PbResult& result, PbServerInfo& server_info, const string& folder_pattern,
|
||||
const string& file_pattern, int scan_depth)
|
||||
{
|
||||
PbImageFilesInfo *image_files_info = GetAvailableImages(result, pattern, scan_depth);
|
||||
PbImageFilesInfo *image_files_info = GetAvailableImages(result, folder_pattern, file_pattern, scan_depth);
|
||||
image_files_info->set_default_image_folder(rascsi_image->GetDefaultImageFolder());
|
||||
server_info.set_allocated_image_files_info(image_files_info);
|
||||
|
||||
@ -283,14 +292,14 @@ PbDeviceTypesInfo *RascsiResponse::GetDeviceTypesInfo(PbResult& result, const Pb
|
||||
}
|
||||
|
||||
PbServerInfo *RascsiResponse::GetServerInfo(PbResult& result, const vector<Device *>& devices, const set<int>& reserved_ids,
|
||||
const string& current_log_level, const string& filename_pattern, int scan_depth)
|
||||
const string& current_log_level, const string& folder_pattern, const string& file_pattern, int scan_depth)
|
||||
{
|
||||
PbServerInfo *server_info = new PbServerInfo();
|
||||
|
||||
server_info->set_allocated_version_info(GetVersionInfo(result));
|
||||
server_info->set_allocated_log_level_info(GetLogLevelInfo(result, current_log_level));
|
||||
GetAllDeviceTypeProperties(*server_info->mutable_device_types_info());
|
||||
GetAvailableImages(result, *server_info, filename_pattern, scan_depth);
|
||||
GetAvailableImages(result, *server_info, folder_pattern, file_pattern, scan_depth);
|
||||
server_info->set_allocated_network_interfaces_info(GetNetworkInterfacesInfo(result));
|
||||
server_info->set_allocated_mapping_info(GetMappingInfo(result));
|
||||
GetDevices(*server_info, devices);
|
||||
|
@ -29,13 +29,14 @@ public:
|
||||
~RascsiResponse() {};
|
||||
|
||||
bool GetImageFile(PbImageFile *, const string&);
|
||||
PbImageFilesInfo *GetAvailableImages(PbResult&, const string&, int);
|
||||
PbImageFilesInfo *GetAvailableImages(PbResult&, const string&, const string&, int);
|
||||
PbReservedIdsInfo *GetReservedIds(PbResult&, const set<int>&);
|
||||
void GetDevices(PbServerInfo&, const vector<Device *>&);
|
||||
void GetDevicesInfo(PbResult&, const PbCommand&, const vector<Device *>&, int);
|
||||
PbDeviceTypesInfo *GetDeviceTypesInfo(PbResult&, const PbCommand&);
|
||||
PbVersionInfo *GetVersionInfo(PbResult&);
|
||||
PbServerInfo *GetServerInfo(PbResult&, const vector<Device *>&, const set<int>&, const string&, const string&, int);
|
||||
PbServerInfo *GetServerInfo(PbResult&, const vector<Device *>&, const set<int>&, const string&, const string&,
|
||||
const string&, int);
|
||||
PbNetworkInterfacesInfo *GetNetworkInterfacesInfo(PbResult&);
|
||||
PbMappingInfo *GetMappingInfo(PbResult&);
|
||||
PbLogLevelInfo *GetLogLevelInfo(PbResult&, const string&);
|
||||
@ -51,6 +52,6 @@ private:
|
||||
void GetDevice(const Device *, PbDevice *);
|
||||
void GetAllDeviceTypeProperties(PbDeviceTypesInfo&);
|
||||
void GetDeviceTypeProperties(PbDeviceTypesInfo&, PbDeviceType);
|
||||
void GetAvailableImages(PbImageFilesInfo&, const string&, const string&, const string&, int);
|
||||
void GetAvailableImages(PbResult& result, PbServerInfo&, const string&, int);
|
||||
void GetAvailableImages(PbImageFilesInfo&, const string&, const string&, const string&, const string&, int);
|
||||
void GetAvailableImages(PbResult& result, PbServerInfo&, const string&, const string&, int);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user