static gboolean parse_emojione_element (JsonNode *node, EmojiData *data) { JsonObject *object; GList *members, *m; if (json_node_get_node_type (node) != JSON_NODE_OBJECT) { return FALSE; } reset_emoji_element (data); object = json_node_get_object (node); m = members = json_object_get_members (object); while (m) { const gchar *member = (const gchar *) m->data; if (!parse_emojione_emoji_data (json_object_get_member (object, member), member, data)) { g_list_free (members); return FALSE; } m = m->next; } g_list_free (members); update_emoji_dict (data); return TRUE; }
static void router_rule_compile (RouterRule *rule, JsonObject *object) { RouterMatch *match; GList *names, *l; JsonNode *node; gint i; g_assert (rule->matches == NULL); names = json_object_get_members (object); rule->matches = g_new0 (RouterMatch, g_list_length (names) + 1); for (l = names, i = 0; l != NULL; l = g_list_next (l), i++) { match = &rule->matches[i]; match->name = g_strdup (l->data); node = json_object_get_member (object, l->data); /* A glob style string pattern */ if (JSON_NODE_HOLDS_VALUE (node) && json_node_get_value_type (node) == G_TYPE_STRING) match->glob = g_pattern_spec_new (json_node_get_string (node)); /* A null matches anything */ if (!JSON_NODE_HOLDS_NULL (node)) match->node = json_node_copy (node); } /* The last match has a null name */ g_list_free (names); }
static void gml_gtk_widget_create_rect (ClutterActor *parent, JsonObject *obj) { GList *l = NULL; GList *p = NULL; ClutterColor color = { 0x00, 0x00, 0x00, 0xff }; ClutterActor *rect = clutter_rectangle_new (); l = json_object_get_members (obj); for (p = l; p; p = p->next) { if (!strcmp (p->data, "width")) { clutter_actor_set_width (rect, (float)json_object_get_int_member (obj, p->data)); } else if (!strcmp (p->data, "height")) { clutter_actor_set_height (rect, (float)json_object_get_int_member (obj, p->data)); } else if (!strcmp (p->data, "x")) { clutter_actor_set_x (rect, (float)json_object_get_int_member (obj, p->data)); } else if (!strcmp (p->data, "y")) { clutter_actor_set_y (rect, (float)json_object_get_int_member (obj, p->data)); } else if (!strcmp (p->data, "color")) { clutter_color_from_string (&(color), json_object_get_string_member (obj, p->data)); clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect), &color); } else if (!strcmp (p->data, "border.width")) { clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rect), json_object_get_int_member (obj, p->data)); } else if (!strcmp (p->data, "border.color")) { clutter_color_from_string (&(color), json_object_get_string_member (obj, p->data)); clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rect), &color); } } clutter_container_add_actor (CLUTTER_CONTAINER (parent), rect); }
static gboolean ipcam_event_input_msg_handler_update_param(IpcamEventInputMsgHandler *handler, const gchar *name, JsonObject *value_obj) { IpcamIConfig *iconfig; g_object_get(G_OBJECT(handler), "app", &iconfig, NULL); GList *members, *item; Schedules *sche = g_new(Schedules, 1); GVariant *value = NULL; gboolean ret = FALSE; members = json_object_get_members(value_obj); for (item = g_list_first(members); item; item = g_list_next(item)) { const gchar *sub_name = item->data; if (g_str_equal(sub_name, "enable")) { value = g_variant_new_boolean(json_object_get_boolean_member(value_obj, sub_name)); } else if (g_str_equal(sub_name, "schedules")) { gint i = 0; JsonObject *sub_obj = json_object_get_object_member(value_obj, sub_name); for (i = ENUM_MON; i < ENUM_WEEKDAY_LAST; i++) { if (json_object_has_member(sub_obj, weekday_name[i])) { sche->schedule[i] = (gchar *)json_object_get_string_member(sub_obj, weekday_name[i]); } else { sche->schedule[i] = g_malloc0(1); } } if (IS_64BIT_MACHINE) { value = g_variant_new_uint64(GPOINTER_TO_SIZE(sche)); } else { value = g_variant_new_uint32(GPOINTER_TO_SIZE(sche)); } } else { g_warn_if_reached(); } if (value) { ret = ipcam_iconfig_update(iconfig, IPCAM_EVENT_INPUT_TYPE, name, sub_name, value); g_variant_unref(value); value = NULL; } } g_free(sche); g_list_free(members); return ret; }
static guint install_properties(JsonOpClass *json_op_class) { GObjectClass *object_class = G_OBJECT_CLASS (json_op_class); JsonObject *root = json_op_class->json_root; guint prop = 1; // Exported ports if (json_object_has_member(root, "inports")) { JsonObject *inports = json_object_get_object_member(root, "inports"); GList *inport_names = json_object_get_members(inports); GList *l; for (l = inport_names; l != NULL; l = l->next) { const gchar *name = l->data; JsonObject *conn = json_object_get_object_member(inports, name); const gchar *proc = json_object_get_string_member(conn, "process"); const gchar *port = json_object_get_string_member(conn, "port"); JsonObject *processes = json_object_get_object_member(root, "processes"); JsonObject *p = json_object_get_object_member(processes, proc); const gchar *component = json_object_get_string_member(p, "component"); { GParamSpec *target_spec = NULL; gchar *opname = component2geglop(component); // HACK: should avoid instantiating node to determine prop GeglNode *n = gegl_node_new(); g_assert(n); gegl_node_set(n, "operation", opname, NULL); target_spec = gegl_node_find_property(n, port); if (target_spec) { GParamSpec *spec = copy_param_spec(target_spec, name); PropertyTarget *t = property_target_new(g_strdup(proc), g_strdup(port)); g_hash_table_insert(json_op_class->properties, GINT_TO_POINTER(prop), t); g_object_class_install_property (object_class, prop, spec); prop++; } g_object_unref(n); g_free(opname); } } g_list_free(inport_names); } /* if (json_object_has_member(root, "outports")) { JsonObject *outports = json_object_get_object_member(root, "outports"); GList *outport_names = json_object_get_members(outports); for (int i=0; i<g_list_length(outport_names); i++) { const gchar *name = g_list_nth_data(outport_names, i); JsonObject *conn = json_object_get_object_member(outports, name); const gchar *proc = json_object_get_string_member(conn, "process"); const gchar *port = json_object_get_string_member(conn, "port"); graph_add_port(self, GraphOutPort, name, proc, port); } } */ return prop-1; }
/*! * Recursive function that handles converging \c JsonNode's to \c * GNode's. * * \param root \c Root JsonNode to convert. * \param node \c GNode. * \param parsing_array \c true if handling an array, else \c false. */ static void clr_oci_json_parse_aux(JsonNode* root, GNode* node, bool parsing_array) { guint i; g_assert (root); g_assert (node); if (JSON_NODE_TYPE(root) == JSON_NODE_OBJECT) { JsonObject *object = json_node_get_object(root); if (object) { guint j; guint size; GList* keys, *key = NULL; GList* values, *value = NULL; size = json_object_get_size(object); keys = json_object_get_members(object); values = json_object_get_values(object); node = g_node_append(node, g_node_new(NULL)); for (j = 0, key = keys, value = values; j < size; j++) { if (key) { node = g_node_append(node->parent, g_node_new(g_strdup(key->data))); } if (value) { clr_oci_json_parse_aux(value->data, node, false); } key = g_list_next(key); value = g_list_next(value); } if (keys) { g_list_free(keys); } if (values) { g_list_free(values); } } } else if (JSON_NODE_TYPE(root) == JSON_NODE_ARRAY) { JsonArray* array = json_node_get_array(root); guint array_size = json_array_get_length (array); JsonNode *array_element; for (i = 0; i < array_size; i++) { array_element = json_array_get_element(array, i); clr_oci_json_parse_aux(array_element, node, true); } } else if (JSON_NODE_TYPE(root) == JSON_NODE_VALUE) { node = g_node_append(node, g_node_new(clr_oci_json_string(root))); if (parsing_array) { node = g_node_append(node, g_node_new(NULL)); } } }
static void skk_map_file_load_map (SkkMapFile* self, GeeMap* map, JsonObject* object) { JsonObject* _tmp0_; GList* _tmp1_ = NULL; GList* keys; GList* _tmp2_; g_return_if_fail (self != NULL); g_return_if_fail (map != NULL); g_return_if_fail (object != NULL); _tmp0_ = object; _tmp1_ = json_object_get_members (_tmp0_); keys = _tmp1_; _tmp2_ = keys; { GList* key_collection = NULL; GList* key_it = NULL; key_collection = _tmp2_; for (key_it = key_collection; key_it != NULL; key_it = key_it->next) { const gchar* key = NULL; key = (const gchar*) key_it->data; { JsonObject* _tmp3_; const gchar* _tmp4_; JsonNode* _tmp5_ = NULL; JsonNode* _tmp6_; JsonNode* value; JsonNode* _tmp7_; JsonNodeType _tmp8_ = 0; _tmp3_ = object; _tmp4_ = key; _tmp5_ = json_object_get_member (_tmp3_, _tmp4_); _tmp6_ = __vala_JsonNode_copy0 (_tmp5_); value = _tmp6_; _tmp7_ = value; _tmp8_ = json_node_get_node_type (_tmp7_); if (_tmp8_ == JSON_NODE_NULL) { GeeMap* _tmp9_; const gchar* _tmp10_; _tmp9_ = map; _tmp10_ = key; gee_map_unset (_tmp9_, _tmp10_, NULL); } else { GeeMap* _tmp11_; const gchar* _tmp12_; JsonNode* _tmp13_; _tmp11_ = map; _tmp12_ = key; _tmp13_ = value; gee_map_set (_tmp11_, _tmp12_, _tmp13_); } __vala_JsonNode_free0 (value); } } } _g_list_free0 (keys); }
void gml_gtk_widget_set_file (GmlGtkWidget *gml, gchar *f) { JsonParser *parser = NULL; JsonNode *node = NULL; JsonObject *obj = NULL; JsonArray *arr = NULL; GError *error = NULL; GList *l = NULL; GList *p = NULL; parser = json_parser_new (); json_parser_load_from_file (parser, f, &error); if (error) { g_print ("Unable to parse `%s': %s\n", f, error->message); g_error_free (error); g_object_unref (parser); return; } node = json_parser_get_root (parser); obj = json_node_get_object (node); l = json_object_get_members (obj); for (p = l; p; p = p->next) { if (!strcmp (p->data, "width")) { gml->width = json_object_get_int_member (obj, p->data); } else if (!strcmp (p->data, "height")) { gml->height = json_object_get_int_member (obj, p->data); } else if (!strcmp (p->data, "color")) { clutter_color_from_string (&(gml->stage_color), json_object_get_string_member (obj, p->data)); } else if (!strcmp (p->data, "elements")) { GList *al = NULL; GList *ap = NULL; JsonObject *arro = NULL; // parsing elements arr = json_object_get_array_member (obj, p->data); al = json_array_get_elements (arr); for (ap = al; ap; ap = ap->next) { arro = json_node_get_object (ap->data); gml_gtk_widget_create_element (gml->stage, arro); } } } g_list_free (l); g_object_unref (parser); gtk_widget_set_size_request (gml->clutter_widget, gml->width, gml->height); clutter_stage_set_color (CLUTTER_STAGE (gml->stage), &(gml->stage_color)); }
static gboolean gs_plugin_odrs_load_ratings (GsPlugin *plugin, const gchar *fn, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); GList *l; JsonNode *json_root; JsonObject *json_item; g_autoptr(GList) apps = NULL; g_autoptr(JsonParser) json_parser = NULL; /* remove all existing */ g_hash_table_remove_all (priv->ratings); /* parse the data and find the success */ json_parser = json_parser_new (); if (!json_parser_load_from_file (json_parser, fn, error)) { gs_utils_error_convert_json_glib (error); return FALSE; } json_root = json_parser_get_root (json_parser); if (json_root == NULL) { g_set_error_literal (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_INVALID_FORMAT, "no ratings root"); return FALSE; } if (json_node_get_node_type (json_root) != JSON_NODE_OBJECT) { g_set_error_literal (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_INVALID_FORMAT, "no ratings array"); return FALSE; } /* parse each app */ json_item = json_node_get_object (json_root); apps = json_object_get_members (json_item); for (l = apps; l != NULL; l = l->next) { const gchar *app_id = (const gchar *) l->data; JsonObject *json_app = json_object_get_object_member (json_item, app_id); g_autoptr(GArray) ratings = NULL;; ratings = gs_plugin_odrs_load_ratings_for_app (json_app); if (ratings->len == 6) { g_hash_table_insert (priv->ratings, g_strdup (app_id), g_array_ref (ratings)); } } return TRUE; }
static gboolean process_open_dynamic_peer (CockpitRouter *self, const gchar *channel, JsonObject *options, GBytes *data, gpointer user_data) { CockpitPeer *peer = NULL; DynamicKey key = { NULL, NULL }; DynamicPeer *dp = user_data; JsonObject *config = NULL; GList *l, *names = NULL; if (dp->spawn) add_dynamic_args_to_array (&key.argv, dp->spawn, options); if (dp->env) add_dynamic_args_to_array (&key.environ, dp->env, options); peer = g_hash_table_lookup (dp->peers, &key); if (!peer) { config = json_object_new (); names = json_object_get_members (dp->config); for (l = names; l != NULL; l = g_list_next (l)) { if (!g_str_equal (l->data, "spawn") && !g_str_equal (l->data, "environ")) json_object_set_member (config, l->data, json_object_dup_member (dp->config, l->data)); } if (key.argv) json_object_set_array_member (config, "spawn", strv_to_json_array (key.argv)); if (key.environ) json_object_set_array_member (config, "environ", strv_to_json_array (key.environ)); peer = cockpit_peer_new (self->transport, config); g_hash_table_insert (dp->peers, g_memdup (&key, sizeof (DynamicKey)), peer); } else { g_strfreev (key.argv); g_strfreev (key.environ); } if (config) json_object_unref (config); g_list_free (names); return cockpit_peer_handle (peer, channel, options, data); }
static gboolean emojione_parse_json_file (const gchar *filename, GHashTable *dict) { JsonParser *parser = json_parser_new (); JsonNode *node; JsonObject *object; GList *members, *m; GError *error = NULL; EmojiData data = { 0, }; g_return_val_if_fail (filename != NULL, FALSE); g_return_val_if_fail (dict != NULL, FALSE); if (!json_parser_load_from_file (parser, filename, &error)) { g_error ("%s", error->message); g_error_free (error); goto fail_to_json_file; } node = json_parser_get_root (parser); if (json_node_get_node_type (node) != JSON_NODE_OBJECT) { g_warning ("Json file does not have Json object %s", filename); goto fail_to_json_file; } object = json_node_get_object (node); members = json_object_get_members (object); data.dict = dict; m = members; while (m) { const gchar *member = (const gchar *) m->data; if (!parse_emojione_element (json_object_get_member (object, member), &data)) { g_warning ("Failed to parse member '%s' in %s", member, filename); } m = m->next; } g_list_free (members); reset_emoji_element (&data); g_object_unref (parser); return TRUE; fail_to_json_file: g_object_unref (parser); return FALSE; }
gboolean fb_process_friend_lists(FacebookAccount *fba, JsonObject *buddy_list) { JsonObject *fl_obj; GList *friend_list_ids, *cur; purple_debug_info("facebook", "processing friend list data\n"); if (!json_object_has_member(buddy_list, "flData")) { purple_debug_info("facebook", "no friend list data\n"); return FALSE; } fl_obj = json_node_get_object(json_object_get_member( buddy_list, "flData")); friend_list_ids = json_object_get_members(fl_obj); for (cur = friend_list_ids; cur != NULL; cur = cur->next) { gchar *id; const gchar *name; JsonObject *data; id = (gchar *) cur->data; data = json_node_get_object(json_object_get_member( fl_obj, id)); name = json_node_get_string(json_object_get_member( data, "n")); if (name) { // Either -1 isnt a valid JSON string or JSON-glib does // this wrong. I'm too tired to tell the difference. if (g_str_equal(id, "_1")) { id = "-1"; } purple_debug_info("facebook", "got friend list %s with id %s\n", name, id); g_hash_table_insert(fba->friend_lists, g_strdup(id), g_strdup(name)); g_hash_table_insert(fba->friend_lists_reverse, g_utf8_strdown(name, -1), g_strdup(id)); } } g_list_free(friend_list_ids); return TRUE; }
static gboolean flist_process_profile(FListAccount *fla, JsonObject *root) { FListProfiles *flp = _flist_profiles(fla); JsonObject *info; GList *categories, *cur; GHashTable *profile; const gchar *error; error = json_object_get_string_member(root, "error"); if(error && strlen(error) > 0) { purple_debug_info(FLIST_DEBUG, "We requested a profile from the Web API, but it returned an error. Error Message: %s\n", error); return FALSE; //user probably opted out of API access } profile = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); info = json_object_get_object_member(root, "info"); categories = json_object_get_members(info); cur = categories; while(cur) { JsonObject *field_group; JsonArray *field_array; guint i, len; field_group = json_object_get_object_member(info, cur->data); field_array = json_object_get_array_member(field_group, "items"); len = json_array_get_length(field_array); for(i = 0; i < len; i++) { JsonObject *field_object = json_array_get_object_element(field_array, i); const gchar *field_name = json_object_get_string_member(field_object, "name"); gchar *unescaped = flist_html_unescape_utf8(json_object_get_string_member(field_object, "value")); gchar *field_value = purple_markup_escape_text(unescaped, strlen(unescaped)); g_hash_table_insert(profile, (gpointer) field_name, (gpointer) field_value); g_free(unescaped); } cur = cur->next; } g_list_free(categories); flist_show_profile(fla->pc, flp->character, profile, FALSE, flp->profile_info); g_hash_table_destroy(profile); return TRUE; }
void ipcam_itrain_update_szyc_setting(IpcamITrain *itrain, JsonNode *body) { JsonObject *items_obj = json_object_get_object_member(json_node_get_object(body), "items"); GList *members, *item; members = json_object_get_members(items_obj); for (item = g_list_first(members); item; item = g_list_next(item)) { const gchar *name = (const gchar *)item->data; gchar *key; if (asprintf(&key, "szyc:%s", (const gchar *)item->data) > 0) { const gchar *value = json_object_get_string_member(items_obj, name); ipcam_itrain_set_string_property(itrain, key, value); g_free(key); } } g_list_free(members); }
//Constructor. GobjectImplKeys::GobjectImplKeys(JsonNode* node):mKeys() { //Only object type json nodes have keys. if (json_node_get_node_type(node) == JSON_NODE_OBJECT) { JsonObject *asObject=json_node_get_object(node); if (asObject) { //get all propertis the object has. GList *members=json_object_get_members(asObject); if (members) { //Add each key to our vector. for (GList *member=members;member;member=member->next) { mKeys.push_back(std::string((char *) member->data)); } //Do some cleanup. g_list_free(members); } } } }
GHashTable * json_ghashtable_deserialize (JsonNode *node, GError **error) { GHashTable *table = NULL; GList *k; GList *keys; JsonNode *node_value; JsonObject *object; gchar *value; if (!node || !JSON_NODE_HOLDS_OBJECT (node)) { g_set_error_literal (error, JSON_READER_ERROR, JSON_READER_ERROR_NO_OBJECT, "Expected JSON object"); return table; } object = json_node_get_object (node); keys = json_object_get_members (object); table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); for (k = keys; k ; k = g_list_next (k)) { node_value = json_object_get_member (object, k->data); if (!JSON_NODE_HOLDS_VALUE (node_value) || (value = json_node_dup_string (node_value)) == NULL) { g_set_error_literal (error, JSON_READER_ERROR, JSON_READER_ERROR_INVALID_TYPE, "Expected JSON string"); g_hash_table_unref (table); table = NULL; break; } else { g_hash_table_insert (table, g_strdup (k->data), value); } } g_list_free (keys); json_object_unref (object); return table; }
static gboolean ipcam_event_cover_msg_handler_put_action_impl(IpcamMessageHandler *handler, JsonNode *request, JsonNode **response) { JsonBuilder *builder = json_builder_new(); JsonObject *req_obj; GList *members, *item; req_obj = json_object_get_object_member(json_node_get_object(request), "items"); members = json_object_get_members(req_obj); json_builder_begin_object(builder); json_builder_set_member_name(builder, "items"); json_builder_begin_object(builder); for (item = g_list_first(members); item; item = g_list_next(item)) { const gchar *name = item->data; if (g_str_equal(name, "region1") || g_str_equal(name, "region2")) { JsonObject *value_obj = json_object_get_object_member(req_obj, name); ipcam_event_cover_msg_handler_update_param(IPCAM_EVENT_COVER_MSG_HANDLER(handler), name, value_obj); json_builder_set_member_name(builder, name); json_builder_begin_object(builder); ipcam_event_cover_msg_handler_read_param(IPCAM_EVENT_COVER_MSG_HANDLER(handler), builder, name); json_builder_end_object(builder); } } json_builder_end_object(builder); json_builder_end_object(builder); g_list_free(members); *response = json_builder_get_root(builder); g_object_unref(builder); return TRUE; }
static void skk_map_file_load (SkkMapFile* self, const gchar* rule, const gchar* type, const gchar* name, GeeSet* included, GError** error) { const gchar* _tmp0_; SkkRuleMetadata* _tmp1_ = NULL; SkkRuleMetadata* metadata; SkkRuleMetadata* _tmp2_; SkkRuleMetadata* _tmp5_; const gchar* _tmp6_; const gchar* _tmp7_; const gchar* _tmp8_; gchar* _tmp9_; gchar* _tmp10_; gchar* _tmp11_ = NULL; gchar* _tmp12_; gchar* filename; const gchar* _tmp13_; gboolean _tmp14_ = FALSE; JsonParser* _tmp17_; JsonParser* parser; JsonParser* _tmp30_; JsonNode* _tmp31_ = NULL; JsonNode* _tmp32_; JsonNode* root; JsonNode* _tmp33_; JsonNodeType _tmp34_ = 0; JsonNode* _tmp36_; JsonObject* _tmp37_ = NULL; JsonObject* _tmp38_; JsonObject* object; JsonNode* member = NULL; JsonObject* _tmp39_; gboolean _tmp40_ = FALSE; JsonObject* _tmp83_; gboolean _tmp84_ = FALSE; GError * _inner_error_ = NULL; g_return_if_fail (self != NULL); g_return_if_fail (rule != NULL); g_return_if_fail (type != NULL); g_return_if_fail (name != NULL); g_return_if_fail (included != NULL); _tmp0_ = rule; _tmp1_ = skk_rule_find_rule (_tmp0_); metadata = _tmp1_; _tmp2_ = metadata; if (_tmp2_ == NULL) { const gchar* _tmp3_; GError* _tmp4_; _tmp3_ = rule; _tmp4_ = g_error_new (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "can't find rule %s", _tmp3_); _inner_error_ = _tmp4_; if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) { g_propagate_error (error, _inner_error_); _skk_rule_metadata_free0 (metadata); return; } else { _skk_rule_metadata_free0 (metadata); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } } _tmp5_ = metadata; _tmp6_ = (*_tmp5_).base_dir; _tmp7_ = type; _tmp8_ = name; _tmp9_ = g_strconcat (_tmp8_, ".json", NULL); _tmp10_ = _tmp9_; _tmp11_ = g_build_filename (_tmp6_, _tmp7_, _tmp10_, NULL); _tmp12_ = _tmp11_; _g_free0 (_tmp10_); filename = _tmp12_; _tmp13_ = filename; _tmp14_ = g_file_test (_tmp13_, G_FILE_TEST_EXISTS); if (!_tmp14_) { const gchar* _tmp15_; GError* _tmp16_; _tmp15_ = filename; _tmp16_ = g_error_new (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "no such file %s", _tmp15_); _inner_error_ = _tmp16_; if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) { g_propagate_error (error, _inner_error_); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); return; } else { _g_free0 (filename); _skk_rule_metadata_free0 (metadata); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } } _tmp17_ = json_parser_new (); parser = _tmp17_; { JsonParser* _tmp18_; const gchar* _tmp19_; gboolean _tmp20_ = FALSE; gboolean _tmp21_; _tmp18_ = parser; _tmp19_ = filename; _tmp20_ = json_parser_load_from_file (_tmp18_, _tmp19_, &_inner_error_); _tmp21_ = _tmp20_; if (_inner_error_ != NULL) { goto __catch28_g_error; } if (!_tmp21_) { GError* _tmp22_; _tmp22_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, ""); _inner_error_ = _tmp22_; goto __catch28_g_error; } } goto __finally28; __catch28_g_error: { GError* e = NULL; const gchar* _tmp23_; GError* _tmp24_; const gchar* _tmp25_; gchar* _tmp26_ = NULL; gchar* _tmp27_; GError* _tmp28_; GError* _tmp29_; e = _inner_error_; _inner_error_ = NULL; _tmp23_ = filename; _tmp24_ = e; _tmp25_ = _tmp24_->message; _tmp26_ = g_strdup_printf ("can't load %s: %s", _tmp23_, _tmp25_); _tmp27_ = _tmp26_; _tmp28_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, _tmp27_); _tmp29_ = _tmp28_; _g_free0 (_tmp27_); _inner_error_ = _tmp29_; _g_error_free0 (e); goto __finally28; } __finally28: if (_inner_error_ != NULL) { if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) { g_propagate_error (error, _inner_error_); _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); return; } else { _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } } _tmp30_ = parser; _tmp31_ = json_parser_get_root (_tmp30_); _tmp32_ = __vala_JsonNode_copy0 (_tmp31_); root = _tmp32_; _tmp33_ = root; _tmp34_ = json_node_get_node_type (_tmp33_); if (_tmp34_ != JSON_NODE_OBJECT) { GError* _tmp35_; _tmp35_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "root element must be an object"); _inner_error_ = _tmp35_; if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) { g_propagate_error (error, _inner_error_); __vala_JsonNode_free0 (root); _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); return; } else { __vala_JsonNode_free0 (root); _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } } _tmp36_ = root; _tmp37_ = json_node_get_object (_tmp36_); _tmp38_ = __vala_JsonObject_copy0 (_tmp37_); object = _tmp38_; _tmp39_ = object; _tmp40_ = json_object_has_member (_tmp39_, "include"); if (_tmp40_) { JsonObject* _tmp41_; JsonNode* _tmp42_ = NULL; JsonNode* _tmp43_; JsonNode* _tmp44_; JsonNodeType _tmp45_ = 0; JsonNode* _tmp47_; JsonArray* _tmp48_ = NULL; JsonArray* _tmp49_; JsonArray* include; JsonArray* _tmp50_; GList* _tmp51_ = NULL; GList* elements; GList* _tmp52_; _tmp41_ = object; _tmp42_ = json_object_get_member (_tmp41_, "include"); _tmp43_ = __vala_JsonNode_copy0 (_tmp42_); __vala_JsonNode_free0 (member); member = _tmp43_; _tmp44_ = member; _tmp45_ = json_node_get_node_type (_tmp44_); if (_tmp45_ != JSON_NODE_ARRAY) { GError* _tmp46_; _tmp46_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "\"include\" element must be an array"); _inner_error_ = _tmp46_; if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) { g_propagate_error (error, _inner_error_); __vala_JsonNode_free0 (member); __vala_JsonObject_free0 (object); __vala_JsonNode_free0 (root); _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); return; } else { __vala_JsonNode_free0 (member); __vala_JsonObject_free0 (object); __vala_JsonNode_free0 (root); _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } } _tmp47_ = member; _tmp48_ = json_node_get_array (_tmp47_); _tmp49_ = __vala_JsonArray_copy0 (_tmp48_); include = _tmp49_; _tmp50_ = include; _tmp51_ = json_array_get_elements (_tmp50_); elements = _tmp51_; _tmp52_ = elements; { GList* element_collection = NULL; GList* element_it = NULL; element_collection = _tmp52_; for (element_it = element_collection; element_it != NULL; element_it = element_it->next) { JsonNode* element = NULL; element = (JsonNode*) element_it->data; { JsonNode* _tmp53_; const gchar* _tmp54_ = NULL; gchar* _tmp55_; gchar* parent; GeeSet* _tmp56_; const gchar* _tmp57_; gboolean _tmp58_ = FALSE; const gchar* _tmp61_; gint _tmp62_ = 0; gint index; gint _tmp63_; GeeSet* _tmp81_; const gchar* _tmp82_; _tmp53_ = element; _tmp54_ = json_node_get_string (_tmp53_); _tmp55_ = g_strdup (_tmp54_); parent = _tmp55_; _tmp56_ = included; _tmp57_ = parent; _tmp58_ = gee_collection_contains ((GeeCollection*) _tmp56_, _tmp57_); if (_tmp58_) { const gchar* _tmp59_; GError* _tmp60_; _tmp59_ = parent; _tmp60_ = g_error_new (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "found circular include of %s", _tmp59_); _inner_error_ = _tmp60_; if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) { g_propagate_error (error, _inner_error_); _g_free0 (parent); _g_list_free0 (elements); __vala_JsonArray_free0 (include); __vala_JsonNode_free0 (member); __vala_JsonObject_free0 (object); __vala_JsonNode_free0 (root); _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); return; } else { _g_free0 (parent); _g_list_free0 (elements); __vala_JsonArray_free0 (include); __vala_JsonNode_free0 (member); __vala_JsonObject_free0 (object); __vala_JsonNode_free0 (root); _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } } _tmp61_ = parent; _tmp62_ = string_index_of (_tmp61_, "/", 0); index = _tmp62_; _tmp63_ = index; if (_tmp63_ < 0) { const gchar* _tmp64_; const gchar* _tmp65_; const gchar* _tmp66_; GeeSet* _tmp67_; _tmp64_ = rule; _tmp65_ = type; _tmp66_ = parent; _tmp67_ = included; skk_map_file_load (self, _tmp64_, _tmp65_, _tmp66_, _tmp67_, &_inner_error_); if (_inner_error_ != NULL) { if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) { g_propagate_error (error, _inner_error_); _g_free0 (parent); _g_list_free0 (elements); __vala_JsonArray_free0 (include); __vala_JsonNode_free0 (member); __vala_JsonObject_free0 (object); __vala_JsonNode_free0 (root); _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); return; } else { _g_free0 (parent); _g_list_free0 (elements); __vala_JsonArray_free0 (include); __vala_JsonNode_free0 (member); __vala_JsonObject_free0 (object); __vala_JsonNode_free0 (root); _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } } } else { const gchar* _tmp68_; gint _tmp69_; gchar* _tmp70_ = NULL; gchar* _tmp71_; const gchar* _tmp72_; const gchar* _tmp73_; gint _tmp74_; const gchar* _tmp75_; gint _tmp76_; gint _tmp77_; gchar* _tmp78_ = NULL; gchar* _tmp79_; GeeSet* _tmp80_; _tmp68_ = parent; _tmp69_ = index; _tmp70_ = string_slice (_tmp68_, (glong) 0, (glong) _tmp69_); _tmp71_ = _tmp70_; _tmp72_ = type; _tmp73_ = parent; _tmp74_ = index; _tmp75_ = parent; _tmp76_ = strlen (_tmp75_); _tmp77_ = _tmp76_; _tmp78_ = string_slice (_tmp73_, (glong) (_tmp74_ + 1), (glong) _tmp77_); _tmp79_ = _tmp78_; _tmp80_ = included; skk_map_file_load (self, _tmp71_, _tmp72_, _tmp79_, _tmp80_, &_inner_error_); _g_free0 (_tmp79_); _g_free0 (_tmp71_); if (_inner_error_ != NULL) { if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) { g_propagate_error (error, _inner_error_); _g_free0 (parent); _g_list_free0 (elements); __vala_JsonArray_free0 (include); __vala_JsonNode_free0 (member); __vala_JsonObject_free0 (object); __vala_JsonNode_free0 (root); _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); return; } else { _g_free0 (parent); _g_list_free0 (elements); __vala_JsonArray_free0 (include); __vala_JsonNode_free0 (member); __vala_JsonObject_free0 (object); __vala_JsonNode_free0 (root); _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } } } _tmp81_ = included; _tmp82_ = parent; gee_collection_add ((GeeCollection*) _tmp81_, _tmp82_); _g_free0 (parent); } } } _g_list_free0 (elements); __vala_JsonArray_free0 (include); } _tmp83_ = object; _tmp84_ = json_object_has_member (_tmp83_, "define"); if (_tmp84_) { JsonObject* _tmp85_; JsonNode* _tmp86_ = NULL; JsonNode* _tmp87_; JsonNode* _tmp88_; JsonNodeType _tmp89_ = 0; JsonNode* _tmp91_; JsonObject* _tmp92_ = NULL; JsonObject* _tmp93_; JsonObject* define; JsonObject* _tmp94_; GList* _tmp95_ = NULL; GList* keys; GList* _tmp96_; _tmp85_ = object; _tmp86_ = json_object_get_member (_tmp85_, "define"); _tmp87_ = __vala_JsonNode_copy0 (_tmp86_); __vala_JsonNode_free0 (member); member = _tmp87_; _tmp88_ = member; _tmp89_ = json_node_get_node_type (_tmp88_); if (_tmp89_ != JSON_NODE_OBJECT) { GError* _tmp90_; _tmp90_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "\"define\" element must be an object"); _inner_error_ = _tmp90_; if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) { g_propagate_error (error, _inner_error_); __vala_JsonNode_free0 (member); __vala_JsonObject_free0 (object); __vala_JsonNode_free0 (root); _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); return; } else { __vala_JsonNode_free0 (member); __vala_JsonObject_free0 (object); __vala_JsonNode_free0 (root); _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } } _tmp91_ = member; _tmp92_ = json_node_get_object (_tmp91_); _tmp93_ = __vala_JsonObject_copy0 (_tmp92_); define = _tmp93_; _tmp94_ = define; _tmp95_ = json_object_get_members (_tmp94_); keys = _tmp95_; _tmp96_ = keys; { GList* key_collection = NULL; GList* key_it = NULL; key_collection = _tmp96_; for (key_it = key_collection; key_it != NULL; key_it = key_it->next) { const gchar* key = NULL; key = (const gchar*) key_it->data; { GeeMap* _tmp97_; const gchar* _tmp98_; gboolean _tmp99_ = FALSE; JsonObject* _tmp104_; const gchar* _tmp105_; JsonNode* _tmp106_ = NULL; JsonNode* _tmp107_; JsonNode* _tmp108_; JsonNodeType _tmp109_ = 0; GeeMap* _tmp111_; const gchar* _tmp112_; gpointer _tmp113_ = NULL; GeeMap* _tmp114_; JsonNode* _tmp115_; JsonObject* _tmp116_ = NULL; _tmp97_ = self->priv->maps; _tmp98_ = key; _tmp99_ = gee_map_has_key (_tmp97_, _tmp98_); if (!_tmp99_) { GeeHashMap* _tmp100_; GeeHashMap* map; GeeMap* _tmp101_; const gchar* _tmp102_; GeeHashMap* _tmp103_; _tmp100_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, json_node_get_type (), (GBoxedCopyFunc) _vala_JsonNode_copy, _vala_JsonNode_free, NULL, NULL, NULL); map = _tmp100_; _tmp101_ = self->priv->maps; _tmp102_ = key; _tmp103_ = map; gee_map_set (_tmp101_, _tmp102_, (GeeMap*) _tmp103_); _g_object_unref0 (map); } _tmp104_ = define; _tmp105_ = key; _tmp106_ = json_object_get_member (_tmp104_, _tmp105_); _tmp107_ = __vala_JsonNode_copy0 (_tmp106_); __vala_JsonNode_free0 (member); member = _tmp107_; _tmp108_ = member; _tmp109_ = json_node_get_node_type (_tmp108_); if (_tmp109_ != JSON_NODE_OBJECT) { GError* _tmp110_; _tmp110_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "map element must be an object"); _inner_error_ = _tmp110_; if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) { g_propagate_error (error, _inner_error_); _g_list_free0 (keys); __vala_JsonObject_free0 (define); __vala_JsonNode_free0 (member); __vala_JsonObject_free0 (object); __vala_JsonNode_free0 (root); _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); return; } else { _g_list_free0 (keys); __vala_JsonObject_free0 (define); __vala_JsonNode_free0 (member); __vala_JsonObject_free0 (object); __vala_JsonNode_free0 (root); _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } } _tmp111_ = self->priv->maps; _tmp112_ = key; _tmp113_ = gee_map_get (_tmp111_, _tmp112_); _tmp114_ = (GeeMap*) _tmp113_; _tmp115_ = member; _tmp116_ = json_node_get_object (_tmp115_); skk_map_file_load_map (self, _tmp114_, _tmp116_); _g_object_unref0 (_tmp114_); } } } _g_list_free0 (keys); __vala_JsonObject_free0 (define); } __vala_JsonNode_free0 (member); __vala_JsonObject_free0 (object); __vala_JsonNode_free0 (root); _g_object_unref0 (parser); _g_free0 (filename); _skk_rule_metadata_free0 (metadata); }
static GObject * json_gobject_new (GType gtype, JsonObject *object) { JsonSerializableIface *iface = NULL; JsonSerializable *serializable = NULL; gboolean find_property; gboolean deserialize_property; gboolean set_property; GList *members, *members_left, *l; guint n_members; GObjectClass *klass; GObject *retval; GArray *construct_params; gint i; klass = g_type_class_ref (gtype); n_members = json_object_get_size (object); members = json_object_get_members (object); members_left = NULL; /* first pass: construct-only properties; here we cannot use Serializable * because we don't have an instance yet; we use the default implementation * of json_deserialize_pspec() to deserialize known types * * FIXME - find a way to allow deserialization for these properties */ construct_params = g_array_sized_new (FALSE, FALSE, sizeof (GParameter), n_members); for (l = members; l != NULL; l = l->next) { const gchar *member_name = l->data; GParamSpec *pspec; GParameter param = { NULL, }; JsonNode *val; gboolean res = FALSE; pspec = g_object_class_find_property (klass, member_name); if (!pspec) goto next_member; /* we only apply construct-only properties here */ if ((pspec->flags & G_PARAM_CONSTRUCT_ONLY) == 0) goto next_member; if (!(pspec->flags & G_PARAM_WRITABLE)) goto next_member; g_value_init (¶m.value, G_PARAM_SPEC_VALUE_TYPE (pspec)); val = json_object_get_member (object, member_name); res = json_deserialize_pspec (¶m.value, pspec, val); if (!res) { g_warning ("Failed to deserialize \"%s\" property of type \"%s\" for an object of type \"%s\"", pspec->name, G_VALUE_TYPE_NAME (¶m.value), g_type_name (gtype)); g_value_unset (¶m.value); } else { param.name = g_strdup (pspec->name); g_array_append_val (construct_params, param); continue; } next_member: members_left = g_list_prepend (members_left, l->data); } retval = g_object_newv (gtype, construct_params->len, (GParameter *) construct_params->data); /* free the contents of the GArray */ for (i = 0; i < construct_params->len; i++) { GParameter *param = &g_array_index (construct_params, GParameter, i); g_free ((gchar *) param->name); g_value_unset (¶m->value); } g_array_free (construct_params, TRUE); g_list_free (members); /* we use g_list_prepend() above, but we want to maintain * the ordering of json_object_get_members() here */ members = g_list_reverse (members_left); /* do the Serializable type check once */ if (g_type_is_a (gtype, JSON_TYPE_SERIALIZABLE)) { serializable = JSON_SERIALIZABLE (retval); iface = JSON_SERIALIZABLE_GET_IFACE (serializable); find_property = (iface->find_property != NULL); deserialize_property = (iface->deserialize_property != NULL); set_property = (iface->set_property != NULL); } else { find_property = FALSE; deserialize_property = FALSE; set_property = FALSE; } g_object_freeze_notify (retval); for (l = members; l != NULL; l = l->next) { const gchar *member_name = l->data; GParamSpec *pspec; JsonNode *val; GValue value = { 0, }; gboolean res = FALSE; if (find_property) pspec = json_serializable_find_property (serializable, member_name); else pspec = g_object_class_find_property (klass, member_name); if (pspec == NULL) continue; /* we should have dealt with these above */ if (pspec->flags & G_PARAM_CONSTRUCT_ONLY) continue; if (!(pspec->flags & G_PARAM_WRITABLE)) continue; g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec)); val = json_object_get_member (object, member_name); if (deserialize_property) { JSON_NOTE (GOBJECT, "Using JsonSerializable for property '%s'", pspec->name); res = json_serializable_deserialize_property (serializable, pspec->name, &value, pspec, val); } if (!res) { JSON_NOTE (GOBJECT, "Using json_deserialize_pspec for property '%s'", pspec->name); res = json_deserialize_pspec (&value, pspec, val); } if (res) { JSON_NOTE (GOBJECT, "Calling set_property('%s', '%s')", pspec->name, g_type_name (G_VALUE_TYPE (&value))); if (set_property) json_serializable_set_property (serializable, pspec, &value); else g_object_set_property (retval, pspec->name, &value); } else g_warning ("Failed to deserialize \"%s\" property of type \"%s\" for an object of type \"%s\"", pspec->name, g_type_name (G_VALUE_TYPE (&value)), g_type_name (gtype)); g_value_unset (&value); } g_list_free (members); g_object_thaw_notify (retval); g_type_class_unref (klass); return retval; }
static gboolean builder_options_deserialize_property (JsonSerializable *serializable, const gchar *property_name, GValue *value, GParamSpec *pspec, JsonNode *property_node) { if (strcmp (property_name, "arch") == 0) { if (JSON_NODE_TYPE (property_node) == JSON_NODE_NULL) { g_value_set_boxed (value, NULL); return TRUE; } else if (JSON_NODE_TYPE (property_node) == JSON_NODE_OBJECT) { JsonObject *object = json_node_get_object (property_node); g_autoptr(GHashTable) hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); g_autoptr(GList) members = NULL; GList *l; members = json_object_get_members (object); for (l = members; l != NULL; l = l->next) { const char *member_name = l->data; JsonNode *val; GObject *option; val = json_object_get_member (object, member_name); option = json_gobject_deserialize (BUILDER_TYPE_OPTIONS, val); if (option == NULL) return FALSE; g_hash_table_insert (hash, g_strdup (member_name), option); } g_value_set_boxed (value, hash); return TRUE; } return FALSE; } else if (strcmp (property_name, "env") == 0) { if (JSON_NODE_TYPE (property_node) == JSON_NODE_NULL) { g_value_set_boxed (value, NULL); return TRUE; } else if (JSON_NODE_TYPE (property_node) == JSON_NODE_OBJECT) { JsonObject *object = json_node_get_object (property_node); g_autoptr(GPtrArray) env = g_ptr_array_new_with_free_func (g_free); g_autoptr(GList) members = NULL; GList *l; members = json_object_get_members (object); for (l = members; l != NULL; l = l->next) { const char *member_name = l->data; JsonNode *val; const char *val_str; val = json_object_get_member (object, member_name); val_str = json_node_get_string (val); if (val_str == NULL) return FALSE; g_ptr_array_add (env, g_strdup_printf ("%s=%s", member_name, val_str)); } g_ptr_array_add (env, NULL); g_value_set_boxed (value, g_ptr_array_free (g_steal_pointer (&env), FALSE)); return TRUE; } return FALSE; } else return json_serializable_default_deserialize_property (serializable, property_name, value, pspec, property_node); }
static void on_socket_connect (GObject *object, GAsyncResult *result, gpointer user_data) { CockpitWebSocketStream *self = COCKPIT_WEB_SOCKET_STREAM (user_data); CockpitChannel *channel = COCKPIT_CHANNEL (self); const gchar *problem = "protocol-error"; gchar **protocols = NULL; GList *l, *names = NULL; GError *error = NULL; JsonObject *options; JsonObject *headers; const gchar *value; JsonNode *node; GIOStream *io; io = cockpit_connect_stream_finish (result, &error); if (error) { problem = cockpit_stream_problem (error, self->origin, "couldn't connect", cockpit_channel_close_options (channel)); cockpit_channel_close (channel, problem); goto out; } options = cockpit_channel_get_options (channel); if (!cockpit_json_get_strv (options, "protocols", NULL, &protocols)) { cockpit_channel_fail (channel, "protocol-error", "%s: invalid \"protocol\" value in WebSocket stream request", self->origin); goto out; } if (G_IS_TLS_CONNECTION (io)) { self->sig_accept_cert = g_signal_connect (G_TLS_CONNECTION (io), "accept-certificate", G_CALLBACK (on_rejected_certificate), self); } else { self->sig_accept_cert = 0; } self->client = web_socket_client_new_for_stream (self->url, self->origin, (const gchar **)protocols, io); node = json_object_get_member (options, "headers"); if (node) { if (!JSON_NODE_HOLDS_OBJECT (node)) { cockpit_channel_fail (channel, "protocol-error", "%s: invalid \"headers\" field in WebSocket stream request", self->origin); goto out; } headers = json_node_get_object (node); names = json_object_get_members (headers); for (l = names; l != NULL; l = g_list_next (l)) { node = json_object_get_member (headers, l->data); if (!node || !JSON_NODE_HOLDS_VALUE (node) || json_node_get_value_type (node) != G_TYPE_STRING) { cockpit_channel_fail (channel, "protocol-error", "%s: invalid header value in WebSocket stream request: %s", self->origin, (gchar *)l->data); goto out; } value = json_node_get_string (node); g_debug ("%s: sending header: %s %s", self->origin, (gchar *)l->data, value); web_socket_client_include_header (WEB_SOCKET_CLIENT (self->client), l->data, value); } } self->sig_open = g_signal_connect (self->client, "open", G_CALLBACK (on_web_socket_open), self); self->sig_message = g_signal_connect (self->client, "message", G_CALLBACK (on_web_socket_message), self); self->sig_closing = g_signal_connect (self->client, "closing", G_CALLBACK (on_web_socket_closing), self); self->sig_close = g_signal_connect (self->client, "close", G_CALLBACK (on_web_socket_close), self); self->sig_error = g_signal_connect (self->client, "error", G_CALLBACK (on_web_socket_error), self); problem = NULL; out: g_clear_error (&error); g_strfreev (protocols); if (io) g_object_unref (io); g_list_free (names); }
static void send_http_request (CockpitHttpStream *self) { CockpitChannel *channel = COCKPIT_CHANNEL (self); JsonObject *options; gboolean had_host; gboolean had_encoding; const gchar *method; const gchar *path; GString *string = NULL; JsonNode *node; JsonObject *headers; const gchar *header; const gchar *value; GList *request = NULL; GList *names = NULL; GBytes *bytes; GList *l; gsize total; options = cockpit_channel_get_options (channel); /* * The checks we do here for token validity are just enough to be able * to format an HTTP response, without leaking across lines etc. */ if (!cockpit_json_get_string (options, "path", NULL, &path)) { cockpit_channel_fail (channel, "protocol-error", "%s: bad \"path\" field in HTTP stream request", self->name); goto out; } else if (path == NULL) { cockpit_channel_fail (channel, "protocol-error", "%s: missing \"path\" field in HTTP stream request", self->name); goto out; } else if (!cockpit_web_response_is_simple_token (path)) { cockpit_channel_fail (channel, "protocol-error", "%s: invalid \"path\" field in HTTP stream request", self->name); goto out; } if (!cockpit_json_get_string (options, "method", NULL, &method)) { cockpit_channel_fail (channel, "protocol-error", "%s: bad \"method\" field in HTTP stream request", self->name); goto out; } else if (method == NULL) { cockpit_channel_fail (channel, "protocol-error", "%s: missing \"method\" field in HTTP stream request", self->name); goto out; } else if (!cockpit_web_response_is_simple_token (method)) { cockpit_channel_fail (channel, "protocol-error", "%s: invalid \"method\" field in HTTP stream request", self->name); goto out; } g_debug ("%s: sending %s request", self->name, method); string = g_string_sized_new (128); g_string_printf (string, "%s %s HTTP/1.1\r\n", method, path); had_encoding = had_host = FALSE; node = json_object_get_member (options, "headers"); if (node) { if (!JSON_NODE_HOLDS_OBJECT (node)) { cockpit_channel_fail (channel, "protocol-error", "%s: invalid \"headers\" field in HTTP stream request", self->name); goto out; } headers = json_node_get_object (node); names = json_object_get_members (headers); for (l = names; l != NULL; l = g_list_next (l)) { header = l->data; if (!cockpit_web_response_is_simple_token (header)) { cockpit_channel_fail (channel, "protocol-error", "%s: invalid header in HTTP stream request: %s", self->name, header); goto out; } node = json_object_get_member (headers, header); if (!node || !JSON_NODE_HOLDS_VALUE (node) || json_node_get_value_type (node) != G_TYPE_STRING) { cockpit_channel_fail (channel, "protocol-error", "%s: invalid header value in HTTP stream request: %s", self->name, header); goto out; } value = json_node_get_string (node); if (disallowed_header (header, value, self->binary)) { cockpit_channel_fail (channel, "protocol-error", "%s: disallowed header in HTTP stream request: %s", self->name, header); goto out; } if (!cockpit_web_response_is_header_value (value)) { cockpit_channel_fail (channel, "protocol-error", "%s: invalid header value in HTTP stream request: %s", self->name, header); goto out; } g_string_append_printf (string, "%s: %s\r\n", (gchar *)l->data, value); g_debug ("%s: sending header: %s %s", self->name, (gchar *)l->data, value); if (g_ascii_strcasecmp (l->data, "Host") == 0) had_host = TRUE; if (g_ascii_strcasecmp (l->data, "Accept-Encoding") == 0) had_encoding = TRUE; } } if (!had_host) { g_string_append (string, "Host: "); g_string_append_uri_escaped (string, self->client->connectable->name, "[]!%$&()*+,-.:;=\\_~", FALSE); g_string_append (string, "\r\n"); } if (!had_encoding) g_string_append (string, "Accept-Encoding: identity\r\n"); if (!self->binary) g_string_append (string, "Accept-Charset: UTF-8\r\n"); request = g_list_reverse (self->request); self->request = NULL; /* Calculate how much data we have to send */ total = 0; for (l = request; l != NULL; l = g_list_next (l)) total += g_bytes_get_size (l->data); if (request || g_ascii_strcasecmp (method, "POST") == 0) g_string_append_printf (string, "Content-Length: %" G_GSIZE_FORMAT "\r\n", total); g_string_append (string, "\r\n"); bytes = g_string_free_to_bytes (string); string = NULL; cockpit_stream_write (self->stream, bytes); g_bytes_unref (bytes); /* Now send all the data */ for (l = request; l != NULL; l = g_list_next (l)) cockpit_stream_write (self->stream, l->data); out: g_list_free (names); g_list_free_full (request, (GDestroyNotify)g_bytes_unref); if (string) g_string_free (string, TRUE); }
/** * json_reader_read_element: * @reader: a #JsonReader * @index_: the index of the element * * Advances the cursor of @reader to the element @index_ of the array * or the object at the current position. * * You can use the json_reader_get_value* family of functions to retrieve * the value of the element; for instance: * * |[ * json_reader_read_element (reader, 0); * int_value = json_reader_get_int_value (reader); * ]| * * After reading the value, json_reader_end_element() should be called to * reposition the cursor inside the #JsonReader, e.g.: * * |[ * json_reader_read_element (reader, 1); * str_value = json_reader_get_string_value (reader); * json_reader_end_element (reader); * * json_reader_read_element (reader, 2); * str_value = json_reader_get_string_value (reader); * json_reader_end_element (reader); * ]| * * If @reader is not currently on an array or an object, or if the @index_ is * bigger than the size of the array or the object, the #JsonReader will be * put in an error state until json_reader_end_element() is called. * * Return value: %TRUE on success, and %FALSE otherwise * * Since: 0.12 */ gboolean json_reader_read_element (JsonReader *reader, guint index_) { JsonReaderPrivate *priv; g_return_val_if_fail (JSON_READER (reader), FALSE); json_reader_return_val_if_error_set (reader, FALSE); priv = reader->priv; if (priv->current_node == NULL) priv->current_node = priv->root; if (!(JSON_NODE_HOLDS_ARRAY (priv->current_node) || JSON_NODE_HOLDS_OBJECT (priv->current_node))) return json_reader_set_error (reader, JSON_READER_ERROR_NO_ARRAY, "The current node is of type '%s', but " "an array or an object was expected.", json_node_type_name (priv->current_node)); switch (json_node_get_node_type (priv->current_node)) { case JSON_NODE_ARRAY: { JsonArray *array = json_node_get_array (priv->current_node); if (index_ >= json_array_get_length (array)) return json_reader_set_error (reader, JSON_READER_ERROR_INVALID_INDEX, "The index '%d' is greater than the size " "of the array at the current position.", index_); priv->previous_node = priv->current_node; priv->current_node = json_array_get_element (array, index_); } break; case JSON_NODE_OBJECT: { JsonObject *object = json_node_get_object (priv->current_node); GList *members; const gchar *name; if (index_ >= json_object_get_size (object)) return json_reader_set_error (reader, JSON_READER_ERROR_INVALID_INDEX, "The index '%d' is greater than the size " "of the object at the current position.", index_); priv->previous_node = priv->current_node; g_free (priv->current_member); members = json_object_get_members (object); name = g_list_nth_data (members, index_); priv->current_node = json_object_get_member (object, name); priv->current_member = g_strdup (name); g_list_free (members); } break; default: g_assert_not_reached (); return FALSE; } return TRUE; }
static void flist_global_profile_cb(FListWebRequestData *req_data, gpointer user_data, JsonObject *root, const gchar *error_message) { FListAccount *fla = user_data; FListProfiles *flp = _flist_profiles(fla); JsonObject *info; GList *categories, *cur; flp->global_profile_request = NULL; if(!root) { purple_debug_warning(FLIST_DEBUG, "Failed to obtain the global list of profile fields. Error Message: %s\n", error_message); return; } info = json_object_get_object_member(root, "info"); if(!info) { purple_debug_warning(FLIST_DEBUG, "We received the global list of profile fields, but it was empty.\n"); return; } purple_debug_info(FLIST_DEBUG, "Processing global profile fields...\n"); flp->category_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, flist_profile_field_category_free); categories = json_object_get_members(info); cur = categories; while(cur) { const gchar *group_name; JsonObject *field_group; JsonArray *field_array; FListProfileFieldCategory *category; guint i, len; field_group = json_object_get_object_member(info, cur->data); group_name = json_object_get_string_member(field_group, "group"); field_array = json_object_get_array_member(field_group, "items"); category = g_new0(FListProfileFieldCategory, 1); category->name = g_strdup(group_name); len = json_array_get_length(field_array); for(i = 0; i < len; i++) { JsonObject *field_object = json_array_get_object_element(field_array, i); FListProfileField *field = g_new0(FListProfileField, 1); field->category = category; field->fieldid = g_strdup_printf("%d", (gint) json_object_get_int_member(field_object, "id")); field->name = g_strdup(json_object_get_string_member(field_object, "name")); category->fields = g_slist_prepend(category->fields, field); if(fla->debug_mode) { purple_debug_info(FLIST_DEBUG, "Global profile field processed. (ID: %s) (Category: %s) (Name: %s)\n", field->fieldid, field->category->name, field->name); } } category->fields = g_slist_sort(category->fields, (GCompareFunc) flist_profile_field_cmp); flp->category_list = g_slist_append(flp->category_list, category); g_hash_table_insert(flp->category_table, g_strdup(category->name), category); cur = g_list_next(cur); } g_list_free(categories); purple_debug_info(FLIST_DEBUG, "Global profile fields processed. (Categories: %d)\n", g_hash_table_size(flp->category_table)); }
/* See "man 5 passwd" We just make sure the name and uid/gid match, and that none are missing. don't care about GECOS/dir/shell. */ static gboolean rpmostree_check_passwd_groups (gboolean passwd, OstreeRepo *repo, GFile *yumroot, GFile *treefile_dirpath, JsonObject *treedata, const char *previous_commit, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; const char *direct = NULL; const char *chk_type = "previous"; const char *commit_filepath = passwd ? "usr/lib/passwd" : "usr/lib/group"; const char *json_conf_name = passwd ? "check-passwd" : "check-groups"; const char *json_conf_ign = passwd ? "ignore-removed-users" : "ignore-removed-groups"; g_autoptr(GFile) old_path = NULL; g_autoptr(GFile) new_path = g_file_resolve_relative_path (yumroot, commit_filepath); g_autoptr(GPtrArray) ignore_removed_ents = NULL; gboolean ignore_all_removed = FALSE; g_autofree char *old_contents = NULL; g_autofree char *new_contents = NULL; g_autoptr(GPtrArray) old_ents = NULL; g_autoptr(GPtrArray) new_ents = NULL; unsigned int oiter = 0; unsigned int niter = 0; if (json_object_has_member (treedata, json_conf_name)) { JsonObject *chk = json_object_get_object_member (treedata,json_conf_name); if (!chk) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s is not an object", json_conf_name); goto out; } chk_type = _rpmostree_jsonutil_object_require_string_member (chk, "type", error); if (!chk_type) goto out; if (g_str_equal (chk_type, "none")) { ret = TRUE; goto out; } else if (g_str_equal (chk_type, "file")) { direct = _rpmostree_jsonutil_object_require_string_member (chk, "filename", error); if (!direct) goto out; } else if (g_str_equal (chk_type, "data")) { JsonNode *ents_node = json_object_get_member (chk, "entries"); JsonObject *ents_obj = NULL; GList *ents; GList *iter; if (!ents_node) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No entries member for data in %s", json_conf_name); goto out; } ents_obj = json_node_get_object (ents_node); if (passwd) old_ents = g_ptr_array_new_with_free_func (conv_passwd_ent_free); else old_ents = g_ptr_array_new_with_free_func (conv_group_ent_free); ents = json_object_get_members (ents_obj); for (iter = ents; iter; iter = iter->next) if (passwd) { const char *name = iter->data; JsonNode *val = json_object_get_member (ents_obj, name); JsonNodeType child_type = json_node_get_node_type (val); gint64 uid = 0; gint64 gid = 0; struct conv_passwd_ent *convent = g_new (struct conv_passwd_ent, 1); if (child_type != JSON_NODE_ARRAY) { if (!_rpmostree_jsonutil_object_require_int_member (ents_obj, name, &uid, error)) goto out; gid = uid; } else { JsonArray *child_array = json_node_get_array (val); guint len = json_array_get_length (child_array); if (!len || (len > 2)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Array %s is only for uid and gid. Has length %u", name, len); goto out; } if (!_rpmostree_jsonutil_array_require_int_element (child_array, 0, &uid, error)) goto out; if (len == 1) gid = uid; else if (!_rpmostree_jsonutil_array_require_int_element (child_array, 1, &gid, error)) goto out; } convent->name = g_strdup (name); convent->uid = uid; convent->gid = gid; g_ptr_array_add (old_ents, convent); } else { const char *name = iter->data; gint64 gid = 0; struct conv_group_ent *convent = g_new (struct conv_group_ent, 1); if (!_rpmostree_jsonutil_object_require_int_member (ents_obj, name, &gid, error)) goto out; convent->name = g_strdup (name); convent->gid = gid; g_ptr_array_add (old_ents, convent); } }
static gboolean process_includes (RpmOstreeTreeComposeContext *self, GFile *treefile_path, guint depth, JsonObject *root, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; const char *include_path; const guint maxdepth = 50; if (depth > maxdepth) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Exceeded maximum include depth of %u", maxdepth); goto out; } { g_autoptr(GFile) parent = g_file_get_parent (treefile_path); gboolean existed = FALSE; if (self->treefile_context_dirs->len > 0) { GFile *prev = self->treefile_context_dirs->pdata[self->treefile_context_dirs->len-1]; if (g_file_equal (parent, prev)) existed = TRUE; } if (!existed) { g_ptr_array_add (self->treefile_context_dirs, parent); parent = NULL; /* Transfer ownership */ } } if (!_rpmostree_jsonutil_object_get_optional_string_member (root, "include", &include_path, error)) goto out; if (include_path) { g_autoptr(GFile) treefile_dirpath = g_file_get_parent (treefile_path); g_autoptr(GFile) parent_path = g_file_resolve_relative_path (treefile_dirpath, include_path); glnx_unref_object JsonParser *parent_parser = json_parser_new (); JsonNode *parent_rootval; JsonObject *parent_root; GList *members; GList *iter; if (!json_parser_load_from_file (parent_parser, gs_file_get_path_cached (parent_path), error)) goto out; parent_rootval = json_parser_get_root (parent_parser); if (!JSON_NODE_HOLDS_OBJECT (parent_rootval)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Treefile root is not an object"); goto out; } parent_root = json_node_get_object (parent_rootval); if (!process_includes (self, parent_path, depth + 1, parent_root, cancellable, error)) goto out; members = json_object_get_members (parent_root); for (iter = members; iter; iter = iter->next) { const char *name = iter->data; JsonNode *parent_val = json_object_get_member (parent_root, name); JsonNode *val = json_object_get_member (root, name); g_assert (parent_val); if (!val) json_object_set_member (root, name, json_node_copy (parent_val)); else { JsonNodeType parent_type = json_node_get_node_type (parent_val); JsonNodeType child_type = json_node_get_node_type (val); if (parent_type != child_type) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Conflicting element type of '%s'", name); goto out; } if (child_type == JSON_NODE_ARRAY) { JsonArray *parent_array = json_node_get_array (parent_val); JsonArray *child_array = json_node_get_array (val); JsonArray *new_child = json_array_new (); guint i, len; len = json_array_get_length (parent_array); for (i = 0; i < len; i++) json_array_add_element (new_child, json_node_copy (json_array_get_element (parent_array, i))); len = json_array_get_length (child_array); for (i = 0; i < len; i++) json_array_add_element (new_child, json_node_copy (json_array_get_element (child_array, i))); json_object_set_array_member (root, name, new_child); } } } json_object_remove_member (root, "include"); } ret = TRUE; out: return ret; }
static void attach (GeglOperation *operation) { JsonOp *self = (JsonOp *)operation; GeglNode *gegl = operation->node; JsonArray *connections; GList *l; // Processes JsonObject *root = self->json_root; JsonObject *processes = json_object_get_object_member(root, "processes"); GList *process_names = json_object_get_members(processes); for (l = process_names; l != NULL; l = l->next) { const gchar *name = l->data; JsonObject *proc = json_object_get_object_member(processes, name); const gchar *component = json_object_get_string_member(proc, "component"); gchar *opname = component2geglop(component); GeglNode *node = gegl_node_new_child (gegl, "operation", opname, NULL); gegl_operation_meta_watch_node (operation, node); g_assert(node); g_hash_table_insert(self->nodes, (gpointer)g_strdup(name), (gpointer)node); g_free(opname); } g_list_free(process_names); // Connections connections = json_object_get_array_member(root, "connections"); g_assert(connections); for (int i=0; i<json_array_get_length(connections); i++) { JsonObject *conn = json_array_get_object_element(connections, i); JsonObject *tgt = json_object_get_object_member(conn, "tgt"); const gchar *tgt_proc = json_object_get_string_member(tgt, "process"); const gchar *tgt_port = json_object_get_string_member(tgt, "port"); GeglNode *tgt_node = g_hash_table_lookup(self->nodes, tgt_proc); JsonNode *srcnode; g_assert(tgt_node); srcnode = json_object_get_member(conn, "src"); if (srcnode) { // Connection JsonObject *src = json_object_get_object_member(conn, "src"); const gchar *src_proc = json_object_get_string_member(src, "process"); const gchar *src_port = json_object_get_string_member(src, "port"); GeglNode *src_node = g_hash_table_lookup(self->nodes, src_proc); g_assert(src_node); gegl_node_connect_to (src_node, src_port, tgt_node, tgt_port); } else { // IIP JsonNode *datanode = json_object_get_member(conn, "data"); GValue value = G_VALUE_INIT; GParamSpec *paramspec; g_assert(JSON_NODE_HOLDS_VALUE(datanode)); json_node_get_value(datanode, &value); paramspec = gegl_node_find_property(tgt_node, tgt_port); set_prop(tgt_node, tgt_port, paramspec, &value); g_value_unset(&value); } } // Exported ports if (json_object_has_member(root, "inports")) { JsonObject *inports = json_object_get_object_member(root, "inports"); GList *inport_names = json_object_get_members(inports); for (l = inport_names; l != NULL; l = l->next) { const gchar *name = l->data; JsonObject *conn = json_object_get_object_member(inports, name); const gchar *proc = json_object_get_string_member(conn, "process"); const gchar *port = json_object_get_string_member(conn, "port"); GeglNode *node = g_hash_table_lookup(self->nodes, proc); g_assert(node); if (g_strcmp0(name, "input") == 0) { GeglNode *input = gegl_node_get_input_proxy (gegl, "input"); gegl_node_connect_to (input, "output", node, "input"); } else { gegl_operation_meta_redirect (operation, name, node, port); } } g_list_free(inport_names); } if (json_object_has_member(root, "outports")) { JsonObject *outports = json_object_get_object_member(root, "outports"); GList *outport_names = json_object_get_members(outports); for (l = outport_names; l != NULL; l = l->next) { const gchar *name = l->data; JsonObject *conn = json_object_get_object_member(outports, name); const gchar *proc = json_object_get_string_member(conn, "process"); const gchar *port = json_object_get_string_member(conn, "port"); GeglNode *node = g_hash_table_lookup(self->nodes, proc); g_assert(node); if (g_strcmp0(name, "output") == 0) { GeglNode *proxy = gegl_node_get_output_proxy (gegl, "output"); gegl_node_connect_to (node, port, proxy, "input"); } else { g_warning("Unsupported output '%s' exported in .json file", name); } } g_list_free(outport_names); } }
static GVariant * parse_json_dictionary (JsonNode *node, const GVariantType *entry_type, GError **error) { const GVariantType *key_type; const GVariantType *value_type; GVariant *result = NULL; GPtrArray *children; JsonObject *object; JsonNode *key_node; GList *members = NULL; gboolean is_string; GVariant *value; GVariant *key; GVariant *child; GList *l; children = g_ptr_array_new (); if (!check_type (node, JSON_NODE_OBJECT, 0, error)) goto out; object = json_node_get_object (node); key_type = g_variant_type_key (entry_type); value_type = g_variant_type_value (entry_type); is_string = (g_variant_type_equal (key_type, G_VARIANT_TYPE_STRING) || g_variant_type_equal (key_type, G_VARIANT_TYPE_OBJECT_PATH) || g_variant_type_equal (key_type, G_VARIANT_TYPE_SIGNATURE)); members = json_object_get_members (object); for (l = members; l != NULL; l = g_list_next (l)) { if (is_string) { key_node = json_node_init_string (json_node_alloc (), l->data); } else { key_node = cockpit_json_parse (l->data, -1, NULL); if (key_node == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, "Unexpected key '%s' in JSON object", (gchar *)l->data); goto out; } } key = parse_json (key_node, key_type, error); json_node_free (key_node); if (!key) goto out; value = parse_json (json_object_get_member (object, l->data), value_type, error); if (!value) { g_variant_unref (key); goto out; } child = g_variant_new_dict_entry (key, value); g_ptr_array_add (children, child); } result = g_variant_new_array (entry_type, (GVariant *const *)children->pdata, children->len); children->len = 0; out: g_list_free (members); g_ptr_array_foreach (children, (GFunc)g_variant_unref, NULL); g_ptr_array_free (children, TRUE); return result; }