diff options
Diffstat (limited to 'backend/utils.cpp')
| -rw-r--r-- | backend/utils.cpp | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/backend/utils.cpp b/backend/utils.cpp index 19d0b39..871fad8 100644 --- a/backend/utils.cpp +++ b/backend/utils.cpp @@ -11,6 +11,9 @@ module; #include <gio/gio.h> #include <curl/curl.h> #include <sqlite3.h> +#include <string> +#include <vector> +#include <optional> export module katja.utils; @@ -36,12 +39,33 @@ struct JobData CURL *curl; virtual void package(Info info, const char *package_id, const char *summary) = 0; - virtual void files(char **) = 0; + virtual void files(const std::vector<std::string>&) = 0; virtual void details(char *package_id, const char *group, const char *description, const char *homepage, int uncompressed) = 0; virtual void set_percentage(double) = 0; }; +struct DummyJobData final : JobData +{ + + void package(Info info, const char *package_id, const char *summary) override + { + } + + void files(const std::vector<std::string>&) override + { + } + + void details(char *package_id, + const char *group, const char *description, const char *homepage, int uncompressed) override + { + } + + void set_percentage(double) override + { + } +}; + /** * katja::get_file: * @curl: curl easy handle. @@ -106,37 +130,30 @@ CURLcode get_file(CURL **curl, const char *source_url, const char *dest) * katja::split_package_name: * Got the name of a package, without version-arch-release data. **/ -char **split_package_name(const char *pkg_filename) +std::optional<std::vector<std::string>> split_package_name(const std::string& pkg_filename) { char *pkg_full_name; - char **pkg_tokens; - g_return_val_if_fail(pkg_filename != nullptr, nullptr); - - int len = strlen(pkg_filename); + int len = pkg_filename.size(); if (len < 4) { - return nullptr; + return std::nullopt; } + std::vector<std::string> pkg_tokens(5); if (pkg_filename[len - 4] == '.') { - pkg_tokens = static_cast<char **>(g_malloc_n (6, sizeof (char *))); - /* Full name without extension */ len -= 4; - pkg_full_name = g_strndup(pkg_filename, len); + pkg_full_name = g_strndup(pkg_filename.data(), len); pkg_tokens[3] = g_strdup(pkg_full_name); /* The last 3 characters should be the file extension */ - pkg_tokens[4] = g_strdup(pkg_filename + len + 1); - pkg_tokens[5] = nullptr; + pkg_tokens[4] = g_strdup(pkg_filename.data() + len + 1); } else { - pkg_tokens = static_cast<char **>(g_malloc_n (4, sizeof (char *))); - pkg_full_name = g_strdup(pkg_filename); - pkg_tokens[3] = nullptr; + pkg_full_name = g_strdup(pkg_filename.c_str()); } /* Reverse all of the bytes in the package filename to get the name, version and the architecture */ |
