// Copyright (C) 2025 Simon Quigley // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . #ifndef SOURCES_PARSER_H #define SOURCES_PARSER_H #include #include #include #include #include #include #include // Structure to hold the required fields struct PackageInfo { std::string Package; // Package name std::vector Provides; // Virtual packages provided std::string BuildDepends; // Build dependencies (for source packages) std::optional Source; // Source package name (for binary packages) std::vector Binary; // Nested structures for parsing dependencies struct ArchRestriction { bool enabled; std::string arch; }; struct BuildRestriction { bool enabled; std::string condition; }; struct ParsedRelation { std::string name; // Dependency package name std::optional archqual; // Architecture qualifier std::optional> version; // Version relation and version std::optional> arch; // Architecture restrictions std::optional>> restrictions; // Build restrictions }; // Parsed BuildDepends and Binary relations std::optional>> BuildDependsParsed; }; // Namespace to encapsulate the parser functionalities namespace SourcesParser { // Function to download, decompress, and parse the Sources.gz data std::optional> fetch_and_parse_sources(const std::string& url); // Function to download, decompress, and parse the Packages.gz data std::optional> fetch_and_parse_packages(const std::string& url); // Function to parse dependency relations std::vector> parse_relations(const std::string& raw); // Function to build dependency graph std::set> build_dependency_graph( const std::vector& sources, const std::vector& binaries); // Function to serialize dependency graph to JSON QString serialize_dependency_graph_to_json(const std::set>& graph); } // namespace SourcesParser #endif // SOURCES_PARSER_H