From: Michael Tremer Date: Sat, 19 Oct 2024 14:57:33 +0000 (+0000) Subject: linter: Check if package name contains whitespace X-Git-Tag: 0.9.30~982 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6963d4578a58b3279091e0ab9613cd6b0cac217;p=pakfire.git linter: Check if package name contains whitespace Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/include/pakfire/string.h b/src/libpakfire/include/pakfire/string.h index 6685a8b1e..b88b1fbb8 100644 --- a/src/libpakfire/include/pakfire/string.h +++ b/src/libpakfire/include/pakfire/string.h @@ -23,6 +23,7 @@ #ifdef PAKFIRE_PRIVATE +#include #include #include #include @@ -61,6 +62,20 @@ int pakfire_string_partition(const char* s, const char* delim, char** s1, char** char* pakfire_string_replace(const char* s, const char* pattern, const char* repl); char* pakfire_string_join(char** list, const char* delim); +/* + Simple operations, usually used in the linter... +*/ +static inline int pakfire_string_contains_whitespace(const char* s) { + while (s && *s) { + if (isspace(*s)) + return 1; + + s++; + } + + return 0; +} + /* Cleanup Stuff */ diff --git a/src/libpakfire/linter.c b/src/libpakfire/linter.c index 616937d01..f4c5fe7d8 100644 --- a/src/libpakfire/linter.c +++ b/src/libpakfire/linter.c @@ -26,6 +26,7 @@ #include #include #include +#include struct pakfire_linter_result { TAILQ_ENTRY(pakfire_linter_result) nodes; @@ -113,6 +114,13 @@ static int pakfire_linter_result( return 0; } +#define pakfire_linter_info(linter, format, ...) \ + pakfire_linter_result(linter, PAKFIRE_LINTER_INFO, format, ## __VA_ARGS__) +#define pakfire_linter_warning(linter, format, ...) \ + pakfire_linter_result(linter, PAKFIRE_LINTER_WARNING, format, ## __VA_ARGS__) +#define pakfire_linter_error(linter, format, ...) \ + pakfire_linter_result(linter, PAKFIRE_LINTER_ERROR, format, ## __VA_ARGS__) + int pakfire_linter_create(struct pakfire_linter** linter, struct pakfire_ctx* ctx, struct pakfire_archive* archive) { struct pakfire_linter* l = NULL; @@ -200,8 +208,17 @@ static int pakfire_linter_name(struct pakfire_linter* linter) { // Fetch the package name const char* name = pakfire_package_get_string(linter->pkg, PAKFIRE_PKG_NAME); + if (!name) + return -errno; + + // Check for whitespace + if (pakfire_string_contains_whitespace(name)) { + r = pakfire_linter_error(linter, "Package name contains whitespace"); + if (r < 0) + return r; + } + - // XXX Do something here... return 0; }