From 68426f9c7ee0071f0bd981ce848c20323ba23cf5 Mon Sep 17 00:00:00 2001 From: Igor Belitskiy Date: Mon, 17 Apr 2023 11:06:22 +0600 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BF=D0=B0=D1=80=D1=81=D0=B5=D1=80=20=D0=BA=D0=B2?= =?UTF-8?q?=D0=BE=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/my_type.h | 14 ++++++++- source/system_cmd_quotas.cc | 61 ++++++++++++++++++++++++++++++++----- source/system_cmd_quotas.h | 4 +-- 3 files changed, 68 insertions(+), 11 deletions(-) diff --git a/source/my_type.h b/source/my_type.h index e4b0b7b..0b55a2e 100644 --- a/source/my_type.h +++ b/source/my_type.h @@ -2,6 +2,7 @@ #define MY_TYPE_H #include "project_lib.h" +#include using namespace std; @@ -45,7 +46,18 @@ struct status_quotas { bool project; bool status; }; - +struct data_all_quotas { + string username; + string status; + string block_used; + string block_soft; + string block_hard; + string block_grace; + string file_used; + string file_soft; + string file_hard; + string file_grace; +}; typedef struct users_grups USER_GRUPS; typedef map map_str_str; diff --git a/source/system_cmd_quotas.cc b/source/system_cmd_quotas.cc index e7cf0c3..e7de561 100644 --- a/source/system_cmd_quotas.cc +++ b/source/system_cmd_quotas.cc @@ -1,4 +1,5 @@ #include "system_cmd_quotas.h" +#include "my_type.h" namespace Quotas_sys { Quotas_sys::Quotas_sys() { @@ -158,31 +159,75 @@ bool Quotas_sys::off_quota_system(string partition, string quota_hw, string quot } -void Quotas_sys::pars_data(string cmd) { +vector Quotas_sys::pars_data(string cmd) { string start_pars = "------\n"; string response = obj_process_call.call_all_sections(cmd); size_t index_start = response.find(start_pars); string line_pars = ""; + struct data_all_quotas struct_data; + vector vec_struct_data; int index = 0; int old_index = index; - if (index_start!=string::npos) { + if (index_start != string::npos) { response = response.substr(index_start+start_pars.length(), response.length()); vector vec_index_sep = Utils::find_all(response, "\n"); - cout << response.substr(0, vec_index_sep[0]) << endl; for (size_t i = 0; i < vec_index_sep.size(); i++) { old_index = index; index = vec_index_sep[i]; if (index-1 == old_index) { break; } - line_pars = line_pars.substr(old_index, index); - part_quotas_line(line_pars); + line_pars = response.substr(old_index, index); + struct_data = part_quotas_line(line_pars); + vec_struct_data.push_back(struct_data); } } } -struct status_quotas part_quotas_line(string line) { - vector vec_index_sep = Utils::find_all(response, "\t"); - cout << vec_index_sep.size() << endl; + +struct data_all_quotas Quotas_sys::part_quotas_line(string line) { + struct data_all_quotas struct_data; + vector vec_index_sep = Utils::find_all(line, " "); + int old_index = 0; + string buff = ""; + int index_data = 0; + for (int& index: vec_index_sep) { + if ((index - old_index) >= 2) { + buff = line.substr(old_index, index - old_index); + if (index_data == 0) { + struct_data.username = buff; + } + else if (index_data == 1) { + struct_data.status = buff; + } + else if (index_data == 2) { + struct_data.block_used = buff; + } + else if (index_data == 3) { + struct_data.block_soft = buff; + } + else if (index_data == 4) { + struct_data.block_hard = buff; + } + else if (index_data == 5) { + struct_data.block_grace = buff; + } + else if (index_data == 6) { + struct_data.file_used = buff; + } + else if (index_data == 7) { + struct_data.file_soft = buff; + } + else if (index_data == 8) { + struct_data.file_hard = buff; + } + else if (index == 9) { + struct_data.file_grace = buff; + } + index_data += 1; + } + old_index = index; + } + return struct_data; } } \ No newline at end of file diff --git a/source/system_cmd_quotas.h b/source/system_cmd_quotas.h index f0df3aa..7ff0809 100644 --- a/source/system_cmd_quotas.h +++ b/source/system_cmd_quotas.h @@ -24,9 +24,9 @@ class Quotas_sys { struct status_quotas check_on_quotas_system_2_hw(string params); bool on_quota_hw(string partition, string cmd_hw, string cmd_sw); bool on_quota_sw(string partition, int mode); - void pars_data(string cmd); + vector pars_data(string cmd); protected: - struct status_quotas part_quotas_line(string line); + struct data_all_quotas part_quotas_line(string line); }; } #endif \ No newline at end of file