]> git.ipfire.org Git - pakfire.git/commitdiff
linter: Check if package name contains whitespace
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 19 Oct 2024 14:57:33 +0000 (14:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 19 Oct 2024 14:57:33 +0000 (14:57 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/string.h
src/libpakfire/linter.c

index 6685a8b1e5a30c5d4d22c0a0a9a4c002a0f57ed8..b88b1fbb8a152c8396895545a163c75cda3e6a57 100644 (file)
@@ -23,6 +23,7 @@
 
 #ifdef PAKFIRE_PRIVATE
 
+#include <ctype.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <time.h>
@@ -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
 */
index 616937d016f7a099fc12fe9e2c2df58c9ae1f0f7..f4c5fe7d8a2c5b97f4e7ed36b012556f7bbd135c 100644 (file)
@@ -26,6 +26,7 @@
 #include <pakfire/linter.h>
 #include <pakfire/logging.h>
 #include <pakfire/package.h>
+#include <pakfire/string.h>
 
 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;
 }