Added optional folder name filter

This commit is contained in:
Uwe Seimet 2021-12-19 19:49:56 +01:00
parent ec31198d83
commit 29603a327a
4 changed files with 33 additions and 21 deletions

View File

@ -1488,8 +1488,8 @@ static void *MonThread(void *param)
PbResult result; PbResult result;
result.set_allocated_server_info(rascsi_response.GetServerInfo( result.set_allocated_server_info(rascsi_response.GetServerInfo(
result, devices, reserved_ids, current_log_level, GetParam(command, "filename_pattern"), result, devices, reserved_ids, current_log_level, GetParam(command, "folder_pattern"),
scan_depth)); GetParam(command, "file_pattern"), scan_depth));
SerializeMessage(fd, result); SerializeMessage(fd, result);
break; break;
} }
@ -1517,7 +1517,7 @@ static void *MonThread(void *param)
PbResult result; PbResult result;
result.set_allocated_image_files_info(rascsi_response.GetAvailableImages(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); SerializeMessage(fd, result);
break; break;
} }

View File

@ -68,7 +68,8 @@ enum PbOperation {
// Gets the server information (PbServerInfo). Calling this operation should be avoided because it // 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. // 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; SERVER_INFO = 10;
// Get rascsi version information (PbVersionInfo) // Get rascsi version information (PbVersionInfo)
@ -83,7 +84,8 @@ enum PbOperation {
// Get information on available image files in the default image folder (PbImageFilesInfo) // Get information on available image files in the default image folder (PbImageFilesInfo)
// Parameters: // 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; DEFAULT_IMAGE_FILES_INFO = 14;
// Get information on an image file (not necessarily in the default image folder) based on an absolute path. // Get information on an image file (not necessarily in the default image folder) based on an absolute path.

View File

@ -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, void RascsiResponse::GetAvailableImages(PbImageFilesInfo& image_files_info, const string& default_image_folder,
const string& folder, const string& pattern, int scan_depth) { const string& folder, const string& folder_pattern, const string& file_pattern, int scan_depth) {
string pattern_lower = pattern; string folder_pattern_lower = folder_pattern;
transform(pattern_lower.begin(), pattern_lower.end(), pattern_lower.begin(), ::tolower); 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) { if (scan_depth-- >= 0) {
DIR *d = opendir(folder.c_str()); 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 filename = folder + "/" + dir->d_name;
string name_lower = filename; string name_lower = filename;
if (!pattern.empty()) { if (!file_pattern.empty()) {
transform(name_lower.begin(), name_lower.end(), name_lower.begin(), ::tolower); 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()); LOGTRACE("Symlink '%s' in image folder '%s' is broken", dir->d_name, folder.c_str());
continue; continue;
} else if (dir->d_type == DT_DIR) { } 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; 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(); PbImageFile *image_file = new PbImageFile();
if (GetImageFile(image_file, filename)) { if (GetImageFile(image_file, filename)) {
GetImageFile(image_files_info.add_image_files(), filename.substr(default_image_folder.length() + 1)); 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(); PbImageFilesInfo *image_files_info = new PbImageFilesInfo();
string default_image_folder = rascsi_image->GetDefaultImageFolder(); string default_image_folder = rascsi_image->GetDefaultImageFolder();
image_files_info->set_default_image_folder(default_image_folder); 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); result.set_status(true);
return image_files_info; 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()); image_files_info->set_default_image_folder(rascsi_image->GetDefaultImageFolder());
server_info.set_allocated_image_files_info(image_files_info); 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, 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(); PbServerInfo *server_info = new PbServerInfo();
server_info->set_allocated_version_info(GetVersionInfo(result)); server_info->set_allocated_version_info(GetVersionInfo(result));
server_info->set_allocated_log_level_info(GetLogLevelInfo(result, current_log_level)); server_info->set_allocated_log_level_info(GetLogLevelInfo(result, current_log_level));
GetAllDeviceTypeProperties(*server_info->mutable_device_types_info()); 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_network_interfaces_info(GetNetworkInterfacesInfo(result));
server_info->set_allocated_mapping_info(GetMappingInfo(result)); server_info->set_allocated_mapping_info(GetMappingInfo(result));
GetDevices(*server_info, devices); GetDevices(*server_info, devices);

View File

@ -29,13 +29,14 @@ public:
~RascsiResponse() {}; ~RascsiResponse() {};
bool GetImageFile(PbImageFile *, const string&); 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>&); PbReservedIdsInfo *GetReservedIds(PbResult&, const set<int>&);
void GetDevices(PbServerInfo&, const vector<Device *>&); void GetDevices(PbServerInfo&, const vector<Device *>&);
void GetDevicesInfo(PbResult&, const PbCommand&, const vector<Device *>&, int); void GetDevicesInfo(PbResult&, const PbCommand&, const vector<Device *>&, int);
PbDeviceTypesInfo *GetDeviceTypesInfo(PbResult&, const PbCommand&); PbDeviceTypesInfo *GetDeviceTypesInfo(PbResult&, const PbCommand&);
PbVersionInfo *GetVersionInfo(PbResult&); 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&); PbNetworkInterfacesInfo *GetNetworkInterfacesInfo(PbResult&);
PbMappingInfo *GetMappingInfo(PbResult&); PbMappingInfo *GetMappingInfo(PbResult&);
PbLogLevelInfo *GetLogLevelInfo(PbResult&, const string&); PbLogLevelInfo *GetLogLevelInfo(PbResult&, const string&);
@ -51,6 +52,6 @@ private:
void GetDevice(const Device *, PbDevice *); void GetDevice(const Device *, PbDevice *);
void GetAllDeviceTypeProperties(PbDeviceTypesInfo&); void GetAllDeviceTypeProperties(PbDeviceTypesInfo&);
void GetDeviceTypeProperties(PbDeviceTypesInfo&, PbDeviceType); void GetDeviceTypeProperties(PbDeviceTypesInfo&, PbDeviceType);
void GetAvailableImages(PbImageFilesInfo&, const string&, const string&, const string&, int); void GetAvailableImages(PbImageFilesInfo&, const string&, const string&, const string&, const string&, int);
void GetAvailableImages(PbResult& result, PbServerInfo&, const string&, int); void GetAvailableImages(PbResult& result, PbServerInfo&, const string&, const string&, int);
}; };