glib GVariant 2
#include <stdio.h> #include <glib.h> #include <stdlib.h> #include <string.h> int main (void) { g_autoptr(GVariant) sessions = NULL; sessions = g_variant_new_parsed ("[('2', uint32 1000, 'nidhoegger', 'seat0', objectpath '/org/freedesktop/login1/session/_32'), ('6', 1001, 'test', 'seat0', '/org/freedesktop/login1/session/_36'), ('c2', 111, 'lightdm', 'seat0', '/org/freedesktop/login1/session/c2')]"); for (gsize i = 0; i < g_variant_n_children (sessions); i++) { g_autoptr(GVariant) child = g_variant_get_child_value (sessions, i); g_message ("Child %" G_GSIZE_FORMAT ": %s", i, g_variant_get_type_string (child)); guint32 uid; const gchar *id, *user, *seat, *session_path; g_variant_get (child, "(&su&s&s&o)", &id, &uid, &user, &seat, &session_path); g_message ("%s, %u, %s, %s, %s", id, uid, user, seat, session_path); } return 0; }