static void router_rule_dump (RouterRule *rule) { RouterMatch *match; gchar *text; guint i; g_print ("rule:\n"); for (i = 0; rule->matches && rule->matches[i].name != NULL; i++) { match = &rule->matches[i]; if (match->node) { text = cockpit_json_write (match->node, NULL); g_print (" %s: %s\n", match->name, text); g_free (text); } else if (match->glob) { g_print (" %s: glob\n", match->name); } else { g_print (" %s\n", match->name); } } }
void _cockpit_assert_json_eq_msg (const char *domain, const char *file, int line, const char *func, JsonObject *object, const gchar *expect) { GError *error = NULL; JsonNode *node; JsonNode *exnode; gchar *escaped; gchar *msg; node = json_node_init_object (json_node_alloc (), object); exnode = cockpit_json_parse (expect, -1, &error); if (error) g_assertion_message_error (domain, file, line, func, "error", error, 0, 0); g_assert (exnode); if (!cockpit_json_equal (exnode, node)) { escaped = cockpit_json_write (node, NULL); msg = g_strdup_printf ("%s != %s", escaped, expect); g_assertion_message (domain, file, line, func, msg); g_free (escaped); g_free (msg); } json_node_free (node); json_node_free (exnode); }
static GBytes * _json_builder_to_bytes (CockpitDBusJson1 *self, JsonBuilder *builder) { JsonNode *root; gsize length; gchar *ret; root = json_builder_get_root (builder); ret = cockpit_json_write (root, &length); json_node_free (root); return g_bytes_new_take (ret, length); }
static void write_builder (CockpitDBusJson *self, JsonBuilder *builder) { GBytes *bytes; JsonNode *root; gsize length; gchar *ret; json_builder_end_object (builder); root = json_builder_get_root (builder); ret = cockpit_json_write (root, &length); json_node_free (root); bytes = g_bytes_new_take (ret, length); cockpit_channel_send (COCKPIT_CHANNEL (self), bytes); g_bytes_unref (bytes); }