From 2b960d89e871dd3f94c96bd61e187c436411abf7 Mon Sep 17 00:00:00 2001 From: Inkwizzz Date: Wed, 15 Jan 2025 23:05:48 +0300 Subject: [PATCH 1/8] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B1=D1=83=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=B4=D1=80=D1=83=D0=B3=D1=83=D1=8E=20=D0=B2=D0=B5?= =?UTF-8?q?=D1=82=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cef3170..45c1b61 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,6 +4,7 @@ on: push: branches: - master + - test - feature/github_actions jobs: From 093e1e20db4269a6b6770c6a0bef10b3e7bc803b Mon Sep 17 00:00:00 2001 From: Inkwizzz Date: Wed, 15 Jan 2025 23:19:48 +0300 Subject: [PATCH 2/8] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B1=D1=83=D0=B5=D0=BC?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D0=BF=D0=B8=D1=81=D0=B0=D1=82=D1=8C=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B7=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B2=D1=80=D1=83=D1=87=D0=BD=D1=83=D1=8E=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B2=D0=B5=D1=82=D1=83=20=D0=B3=D0=BF=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 45c1b61..d59a2f8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,6 +7,13 @@ on: - test - feature/github_actions +permissions: + contents: write + actions: write + packages: write + id-token: write + pull-requests: write + jobs: build: runs-on: ubuntu-latest From 0035b5b842adc96e992562e7238ce259e3217cdb Mon Sep 17 00:00:00 2001 From: Inkwizzz Date: Wed, 15 Jan 2025 23:26:54 +0300 Subject: [PATCH 3/8] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d59a2f8..1f956b4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,16 +18,17 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@latest with: submodules: true - run: sudo apt-get update && sudo apt-get install libboost-test-dev -y - run: cmake . -DPATCH_VERSION=${{ github.run_number }} -DWITH_BOOST_TEST=ON - run: cmake --build . - run: cmake --build . --target package + - run: ls -l ./ - name: Create Release id: create_release - uses: actions/create-release@v1 + uses: actions/create-release@latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: @@ -37,7 +38,7 @@ jobs: prerelease: false - name: Upload Release Asset id: upload-release-asset - uses: actions/upload-release-asset@v1 + uses: actions/upload-release-asset@latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: From cf28e7d572239ca0954bc2d7123f442f999bdb9b Mon Sep 17 00:00:00 2001 From: Inkwizzz Date: Wed, 15 Jan 2025 23:28:18 +0300 Subject: [PATCH 4/8] =?UTF-8?q?=D1=83=D0=BF=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1f956b4..e80bd0b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@latest + - uses: actions/checkout@v2 with: submodules: true - run: sudo apt-get update && sudo apt-get install libboost-test-dev -y @@ -28,7 +28,7 @@ jobs: - run: ls -l ./ - name: Create Release id: create_release - uses: actions/create-release@latest + uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: @@ -38,7 +38,7 @@ jobs: prerelease: false - name: Upload Release Asset id: upload-release-asset - uses: actions/upload-release-asset@latest + uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: From 6845e23f1f6c47e3f91742c51d76edfcaa5f2b9f Mon Sep 17 00:00:00 2001 From: Inkwizzz Date: Wed, 15 Jan 2025 23:29:42 +0300 Subject: [PATCH 5/8] ? --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e80bd0b..1a38b65 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,6 +43,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./ip_filter-0.0.${{ github.run_number }}-Linux.deb - asset_name: ip_filter-0.0.${{ github.run_number }}-Linux.deb + asset_path: ./ip_filter_cli-0.0.${{ github.run_number }}-Linux.deb + asset_name: ip_filter_cli-0.0.${{ github.run_number }}-Linux.deb asset_content_type: application/vnd.debian.binary-package \ No newline at end of file From c7da3f25f98b7d2814e716addec96d38a30697f8 Mon Sep 17 00:00:00 2001 From: Inkwizzz Date: Wed, 15 Jan 2025 23:32:51 +0300 Subject: [PATCH 6/8] reverted previous --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1a38b65..e80bd0b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,6 +43,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./ip_filter_cli-0.0.${{ github.run_number }}-Linux.deb - asset_name: ip_filter_cli-0.0.${{ github.run_number }}-Linux.deb + asset_path: ./ip_filter-0.0.${{ github.run_number }}-Linux.deb + asset_name: ip_filter-0.0.${{ github.run_number }}-Linux.deb asset_content_type: application/vnd.debian.binary-package \ No newline at end of file From dd4234e45221eeea6389b361406fd03d78e2f0e0 Mon Sep 17 00:00:00 2001 From: Inkwizzz Date: Wed, 15 Jan 2025 23:38:59 +0300 Subject: [PATCH 7/8] =?UTF-8?q?=D0=9A=D0=B0=D0=B6=D0=B5=D1=82=D1=81=D1=8F,?= =?UTF-8?q?=20=D0=BD=D0=B0=D1=88=D0=B5=D0=BB=20=D0=BF=D1=80=D0=BE=D0=B1?= =?UTF-8?q?=D0=BB=D0=B5=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e80bd0b..e77de9e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,6 +43,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./ip_filter-0.0.${{ github.run_number }}-Linux.deb - asset_name: ip_filter-0.0.${{ github.run_number }}-Linux.deb + asset_path: ./ip_filter-0.1.${{ github.run_number }}-Linux.deb + asset_name: ip_filter-0.1.${{ github.run_number }}-Linux.deb asset_content_type: application/vnd.debian.binary-package \ No newline at end of file From 293b0dfb1a78a44dfb1721e2740f52542405c41c Mon Sep 17 00:00:00 2001 From: Inkwizzz Date: Wed, 22 Jan 2025 00:16:28 +0300 Subject: [PATCH 8/8] Updated via requarements --- ip_filter.cpp | 122 ++++++++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 64 deletions(-) diff --git a/ip_filter.cpp b/ip_filter.cpp index c9c4076..183f7fa 100644 --- a/ip_filter.cpp +++ b/ip_filter.cpp @@ -1,64 +1,56 @@ #include +#include #include #include #include +using ip_address = std::array; +using ip_pool_type = std::vector; -using my_vec = std::vector>; - -void OutPutIP(const std::vector& vec){ - for (auto ip_part = vec.cbegin(); ip_part != vec.cend(); ++ip_part) - { - if (ip_part != vec.cbegin()) std::cout << "."; - std::cout << *ip_part; +void OutPutIP(const ip_address& ip) { + for (auto it = ip.cbegin(); it != ip.cend(); ++it) { + if (it != ip.cbegin()) std::cout << "."; + std::cout << *it; } + std::cout << std::endl; } -void FilterAny(my_vec& vector, const std::string& any) { - for (auto& row : vector) { - if (std::find(row.begin(), row.end(), any) != row.end()) { - OutPutIP(row); - std::cout << std::endl; +void FilterAny(const ip_pool_type& ip_pool, int any) { + for (const auto& ip : ip_pool) { + if (std::find(ip.begin(), ip.end(), any) != ip.end()) { + OutPutIP(ip); } } } -void FilterOutput(my_vec& vector, std::string fst) { - for (auto& row : vector) - if (row[0] == fst) { - OutPutIP(row); - std::cout << std::endl; +void FilterOutput(const ip_pool_type& ip_pool, int fst) { + for (const auto& ip : ip_pool) { + if (ip[0] == fst) { + OutPutIP(ip); } + } } -void FilterOutput(my_vec& vector, std::string fst, std::string snd) { - for (auto& row : vector) - if (row[0] == fst && row[1] == snd) { - OutPutIP(row); - std::cout << std::endl; +void FilterOutput(const ip_pool_type& ip_pool, int fst, int snd) { + for (const auto& ip : ip_pool) { + if (ip[0] == fst && ip[1] == snd) { + OutPutIP(ip); } + } } - struct MySort { - bool operator()(const std::vector& vec1, const std::vector& vec2) const { - for (size_t i = 0; i < 4; ++i) { - int num1 = std::stoi(vec1[i]); - int num2 = std::stoi(vec2[i]); - - if (num1 != num2) - return num1 < num2; - } - return false; + bool operator()(const ip_address& ip1, const ip_address& ip2) const { + return ip1 > ip2; } }; -auto Split(const std::string &str, char d) -> std::vector { +auto SplitStr(const std::string& str, char d) -> std::vector { std::vector r; std::string::size_type start = 0; std::string::size_type stop = str.find_first_of(d); - while(stop != std::string::npos) + while (stop != std::string::npos) { r.push_back(str.substr(start, stop - start)); @@ -71,45 +63,47 @@ auto Split(const std::string &str, char d) -> std::vector { return r; } -int main() -{ - try - { - my_vec ip_pool; +ip_address Split(const std::string& str, char d) { + ip_address result{}; + std::string::size_type start = 0; + std::string::size_type stop = str.find_first_of(d); + + for (int i = 0; i < 4; ++i) { + result[i] = std::stoi(str.substr(start, stop - start)); + start = stop + 1; + stop = str.find_first_of(d, start); + } + + return result; +} + +int main() { + try { + ip_pool_type ip_pool; - for(std::string line; std::getline(std::cin, line);) - { - std::vector v = Split(line, '\t'); + for (std::string line; std::getline(std::cin, line);) { + std::vector v = SplitStr(line, '\t'); ip_pool.push_back(Split(v.at(0), '.')); } - // TODO reverse lexicographically sort DONE std::sort(ip_pool.begin(), ip_pool.end(), MySort()); - for(const auto & ip : ip_pool) - { - for(auto ip_part = ip.cbegin(); ip_part != ip.cend(); ++ip_part) - { - if (ip_part != ip.cbegin()) - { - std::cout << "."; - - } - std::cout << *ip_part; - } - std::cout << std::endl; + + for (const auto& ip : ip_pool) { + OutPutIP(ip); } - //std::cout << "Filter by 1st byte"<< std::endl; - FilterOutput(ip_pool, "1"); - //std::cout << "Filter by 1st and 2nd byte"<< std::endl; - FilterOutput(ip_pool, "46", "70"); - //std::cout << "Filter any"<< std::endl; - FilterAny(ip_pool, "46"); + std::cout << "Filter by 1st byte (1):" << std::endl; + FilterOutput(ip_pool, 1); + + std::cout << "Filter by 1st and 2nd byte (46, 70):" << std::endl; + FilterOutput(ip_pool, 46, 70); + + std::cout << "Filter any (46):" << std::endl; + FilterAny(ip_pool, 46); } - catch(const std::exception &e) - { + catch (const std::exception& e) { std::cerr << e.what() << std::endl; } return 0; -} +} \ No newline at end of file