GVariant * gkd_secret_property_append_all (GckAttributes *attrs) { const GckAttribute *attr; DataType data_type; const gchar *name; gulong num, i; GVariantBuilder builder; GVariant *variant; g_return_val_if_fail (attrs, NULL); g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); num = gck_attributes_count (attrs); for (i = 0; i < num; ++i) { attr = gck_attributes_at (attrs, i); if (!attribute_to_property (attr->type, &name, &data_type)) g_return_val_if_reached (NULL); variant = iter_append_variant (data_type, attr); g_variant_builder_add (&builder, "{sv}", name, variant); g_variant_unref (variant); } return g_variant_builder_end (&builder); }
gboolean gkd_secret_property_append_all (DBusMessageIter *array, GckAttributes *attrs) { DBusMessageIter dict; const GckAttribute *attr; DataType data_type; const gchar *name; gulong num, i; g_return_val_if_fail (array, FALSE); g_return_val_if_fail (attrs, FALSE); num = gck_attributes_count (attrs); for (i = 0; i < num; ++i) { attr = gck_attributes_at (attrs, i); if (!attribute_to_property (attr->type, &name, &data_type)) g_return_val_if_reached (FALSE); dbus_message_iter_open_container (array, DBUS_TYPE_DICT_ENTRY, NULL, &dict); dbus_message_iter_append_basic (&dict, DBUS_TYPE_STRING, &name); iter_append_variant (&dict, data_type, attr); dbus_message_iter_close_container (array, &dict); } return TRUE; }
void gck_attributes_dump (GckAttributes *attrs) { GckAttribute *attr; guint i, count; for (i = 0, count = gck_attributes_count (attrs); i < count; ++i) { attr = gck_attributes_at (attrs, i); gck_attribute_dump (attr); } }
gboolean gck_attributes_contains (GckAttributes *attrs, GckAttribute *match) { GckAttribute *attr; guint i; g_return_val_if_fail (attrs && attrs->array, FALSE); for (i = 0; i < attrs->array->len; ++i) { attr = gck_attributes_at (attrs, i); if (gck_attribute_equal (attr, match)) return TRUE; } return FALSE; }
/** * gck_attributes_find: * @attrs: The attributes array to search. * @attr_type: The type of attribute to find. * * Find an attribute with the specified type in the array. * * Return value: The first attribute found with the specified type, or NULL. **/ GckAttribute* gck_attributes_find (GckAttributes *attrs, gulong attr_type) { GckAttribute *attr; guint i; g_return_val_if_fail (attrs && attrs->array, NULL); g_return_val_if_fail (!attrs->locked, NULL); for (i = 0; i < attrs->array->len; ++i) { attr = gck_attributes_at (attrs, i); if (attr->type == attr_type) return attr; } return NULL; }
/** * gck_attributes_unref: * @attrs: An attribute array * * Unreference this attribute array. * * When all outstanding references are NULL, the array will be freed. */ void gck_attributes_unref (GckAttributes *attrs) { guint i; if (!attrs) return; if (g_atomic_int_dec_and_test (&attrs->refs)) { g_return_if_fail (attrs->array); g_return_if_fail (!attrs->locked); for (i = 0; i < attrs->array->len; ++i) attribute_clear (gck_attributes_at (attrs, i), attrs->allocator); g_array_free (attrs->array, TRUE); attrs->array = NULL; g_slice_free (GckAttributes, attrs); } }
/** * gcr_importer_create_for_parsed: * @parsed: a parser with a parsed item to import * * Create a set of importers which can import this parsed item. * The parsed item is represented by the state of the GcrParser at the * time of calling this method. * * Returns: (element-type Gcr.Importer) (transfer full): a list of importers * which can import the parsed item, which should be freed with * g_object_unref(), or %NULL if no types of importers can be created */ GList * gcr_importer_create_for_parsed (GcrParsed *parsed) { GcrRegistered *registered; GcrImporterIface *iface; gpointer instance_class; GckAttributes *attrs; gboolean matched; gulong n_attrs; GList *results = NULL; GHashTable *seen; gulong j; gsize i; g_return_val_if_fail (parsed != NULL, NULL); gcr_importer_register_well_known (); if (!registered_importers) return NULL; if (!registered_sorted) { g_array_sort (registered_importers, sort_registered_by_n_attrs); registered_sorted = TRUE; } attrs = gcr_parsed_get_attributes (parsed); if (attrs != NULL) gck_attributes_ref (attrs); else attrs = gck_attributes_new_empty (GCK_INVALID); seen = g_hash_table_new (g_direct_hash, g_direct_equal); if (_gcr_debugging) { gchar *a = gck_attributes_to_string (attrs); _gcr_debug ("looking for importer for: %s", a); g_free (a); } for (i = 0; i < registered_importers->len; ++i) { registered = &(g_array_index (registered_importers, GcrRegistered, i)); n_attrs = gck_attributes_count (registered->attrs); matched = TRUE; for (j = 0; j < n_attrs; ++j) { if (!gck_attributes_contains (attrs, gck_attributes_at (registered->attrs, j))) { matched = FALSE; break; } } if (_gcr_debugging) { gchar *a = gck_attributes_to_string (registered->attrs); _gcr_debug ("importer %s %s: %s", g_type_name (registered->importer_type), matched ? "matched" : "didn't match", a); g_free (a); } if (matched) { if (check_if_seen_or_add (seen, GUINT_TO_POINTER (registered->importer_type))) continue; instance_class = g_type_class_ref (registered->importer_type); iface = g_type_interface_peek (instance_class, GCR_TYPE_IMPORTER); g_return_val_if_fail (iface != NULL, NULL); g_return_val_if_fail (iface->create_for_parsed, NULL); results = g_list_concat (results, (iface->create_for_parsed) (parsed)); g_type_class_unref (instance_class); } } g_hash_table_unref (seen); gck_attributes_unref (attrs); return results; }