]> git.ipfire.org Git - collecty.git/commitdiff
modules: Create a dummy function for modules to submit data
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 27 Sep 2025 14:47:59 +0000 (14:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 27 Sep 2025 14:47:59 +0000 (14:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/module.c
src/daemon/module.h

index f5d0e715f3e29cd505d0437cecf7352a9aebbd32..bba4f8b5636937b972dd5975d03ae21eddd6ad51 100644 (file)
@@ -19,6 +19,7 @@
 #############################################################################*/
 
 #include <errno.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -209,3 +210,32 @@ collecty_module* collecty_module_unref(collecty_module* self) {
 const char* collecty_module_name(collecty_module* self) {
        return self->methods->name;
 }
+
+/*
+       Called when a module has some data to submit
+*/
+int collecty_module_submit(collecty_module* self,
+               const char* object, const char* format, ...) {
+       char* value = NULL;
+       va_list args;
+       int r;
+
+       // Format the arguments
+       va_start(args, format);
+       r = vasprintf(&value, format, args);
+       va_end(args);
+
+       // Handle errors
+       if (r < 0)
+               return -errno;
+
+       DEBUG(self->ctx, "%s(%s) submitted: %s\n",
+               collecty_module_name(self), (object) ? object : "", value);
+
+       // TODO
+
+       if (value)
+               free(value);
+
+       return 0;
+}
index fc5db7c4b8115d4b170b2c438e1c1b498c017993..d856e813592930b349d2dadc8a75fe173e4a7353 100644 (file)
@@ -44,4 +44,7 @@ collecty_module* collecty_module_unref(collecty_module* self);
 
 const char* collecty_module_name(collecty_module* self);
 
+int collecty_module_submit(collecty_module* self, const char* object,
+       const char* format, ...) __attribute__((format(printf, 3, 4)));
+
 #endif /* COLLECTY_MODULE_H */