]> git.ipfire.org Git - oddments/collecty.git/commitdiff
bus: Parse timestamps
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 29 Oct 2025 15:44:08 +0000 (15:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 29 Oct 2025 15:44:08 +0000 (15:44 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/graph-bus.c

index b93b33291f52bd6d249b726f82a26f9dc061095d..3d7e75ce18d74cd42df57d6c0469fd1e4475ceb9 100644 (file)
@@ -25,6 +25,7 @@
 #include "graph.h"
 #include "graph-bus.h"
 #include "string.h"
+#include "time.h"
 
 static int td_graph_node_enumerator(sd_bus* bus,
                const char* path, void* data, char*** nodes, sd_bus_error* error) {
@@ -106,6 +107,10 @@ static int td_graph_bus_render(sd_bus_message* m, void* data, sd_bus_error* erro
        size_t length = 0;
        int r;
 
+       // Intervals
+       const char* since = NULL;
+       const char* until = NULL;
+
        // Open the options array
        r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}");
        if (r < 0)
@@ -148,6 +153,34 @@ static int td_graph_bus_render(sd_bus_message* m, void* data, sd_bus_error* erro
                        r = sd_bus_message_read(m, "v", "t", &options.dimensions.w);
                        if (r < 0)
                                goto ERROR;
+
+               // Parse "since"
+               } else if (td_string_equals(key, "since")) {
+                       r = sd_bus_message_read(m, "v", "s", &since);
+                       if (r < 0)
+                               goto ERROR;
+
+                       // Parse the timestamp
+                       r = time_parse(&options.interval.t_start, since);
+                       if (r < 0) {
+                               r = sd_bus_error_setf(error,
+                                               SD_BUS_ERROR_INVALID_ARGS, "Failed to time '%s'", since);
+                               goto ERROR;
+                       }
+
+               // Parse until
+               } else if (td_string_equals(key, "until")) {
+                       r = sd_bus_message_read(m, "v", "s", &until);
+                       if (r < 0)
+                               goto ERROR;
+
+                       // Parse the timestamp
+                       r = time_parse(&options.interval.t_end, until);
+                       if (r < 0) {
+                               r = sd_bus_error_setf(error,
+                                               SD_BUS_ERROR_INVALID_ARGS, "Failed to time '%s'", until);
+                               goto ERROR;
+                       }
                }
 
                // Leave the container
@@ -161,6 +194,19 @@ static int td_graph_bus_render(sd_bus_message* m, void* data, sd_bus_error* erro
        if (r < 0)
                goto ERROR;
 
+       // Check the timestamps
+       if (options.interval.t_start && options.interval.t_end
+                       && options.interval.t_start > options.interval.t_end) {
+               r = sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
+                               "Graph start time is after the end time");
+               if (r < 0)
+                       goto ERROR;
+
+               // Abort
+               r = -ERANGE;
+               goto ERROR;
+       }
+
        // Render the graph
        r = td_graph_render(graph, object, &options, &buffer, &length);
        if (r < 0)