diff options
45 files changed, 10061 insertions, 175 deletions
diff --git a/Cargo.lock b/Cargo.lock index 4d6c133..57e9bbb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -116,8 +116,8 @@ version = "1.0.0" dependencies = [ "futures", "gettext-rs", - "gio 0.20.4", - "glib 0.20.4", + "gio", + "glib", "gtk4", "kittybox-indieauth", "kittybox-util", @@ -163,7 +163,7 @@ checksum = "e8a0ea147c94108c9613235388f540e4d14c327f7081c9e471fc8ee8a2533e69" dependencies = [ "bitflags", "cairo-sys-rs", - "glib 0.20.4", + "glib", "libc", ] @@ -173,7 +173,7 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "428290f914b9b86089f60f5d8a9f6e440508e1bcff23b25afd51502b0a2da88f" dependencies = [ - "glib-sys 0.20.4", + "glib-sys", "libc", "system-deps 7.0.3", ] @@ -439,8 +439,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4c29071a9e92337d8270a85cb0510cda4ac478be26d09ad027cc1d081911b19" dependencies = [ "gdk-pixbuf-sys", - "gio 0.20.4", - "glib 0.20.4", + "gio", + "glib", "libc", ] @@ -450,9 +450,9 @@ version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "687343b059b91df5f3fbd87b4307038fa9e647fcc0461d0d3f93e94fee20bf3d" dependencies = [ - "gio-sys 0.20.4", - "glib-sys 0.20.4", - "gobject-sys 0.20.4", + "gio-sys", + "glib-sys", + "gobject-sys", "libc", "system-deps 7.0.3", ] @@ -466,8 +466,8 @@ dependencies = [ "cairo-rs", "gdk-pixbuf", "gdk4-sys", - "gio 0.20.4", - "glib 0.20.4", + "gio", + "glib", "libc", "pango", ] @@ -480,9 +480,9 @@ checksum = "7d3c03d1ea9d5199f14f060890fde68a3b5ec5699144773d1fa6abf337bfbc9c" dependencies = [ "cairo-sys-rs", "gdk-pixbuf-sys", - "gio-sys 0.20.4", - "glib-sys 0.20.4", - "gobject-sys 0.20.4", + "gio-sys", + "glib-sys", + "gobject-sys", "libc", "pango-sys", "pkg-config", @@ -540,24 +540,6 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "gio" -version = "0.19.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c49f117d373ffcc98a35d114db5478bc223341cff53e39a5d6feced9e2ddffe" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-util", - "gio-sys 0.19.8", - "glib 0.19.9", - "libc", - "pin-project-lite", - "smallvec", - "thiserror", -] - -[[package]] -name = "gio" version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8d999e8fb09583e96080867e364bc1e701284ad206c76a5af480d63833ad43c" @@ -566,8 +548,8 @@ dependencies = [ "futures-core", "futures-io", "futures-util", - "gio-sys 0.20.4", - "glib 0.20.4", + "gio-sys", + "glib", "libc", "pin-project-lite", "smallvec", @@ -575,25 +557,12 @@ dependencies = [ [[package]] name = "gio-sys" -version = "0.19.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cd743ba4714d671ad6b6234e8ab2a13b42304d0e13ab7eba1dcdd78a7d6d4ef" -dependencies = [ - "glib-sys 0.19.8", - "gobject-sys 0.19.8", - "libc", - "system-deps 6.2.2", - "windows-sys 0.52.0", -] - -[[package]] -name = "gio-sys" version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f7efc368de04755344f0084104835b6bb71df2c1d41e37d863947392a894779" dependencies = [ - "glib-sys 0.20.4", - "gobject-sys 0.20.4", + "glib-sys", + "gobject-sys", "libc", "system-deps 7.0.3", "windows-sys 0.52.0", @@ -601,28 +570,6 @@ dependencies = [ [[package]] name = "glib" -version = "0.19.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39650279f135469465018daae0ba53357942a5212137515777d5fdca74984a44" -dependencies = [ - "bitflags", - "futures-channel", - "futures-core", - "futures-executor", - "futures-task", - "futures-util", - "gio-sys 0.19.8", - "glib-macros 0.19.9", - "glib-sys 0.19.8", - "gobject-sys 0.19.8", - "libc", - "memchr", - "smallvec", - "thiserror", -] - -[[package]] -name = "glib" version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adcf1ec6d3650bf9fdbc6cee242d4fcebc6f6bfd9bea5b929b6a8b7344eb85ff" @@ -633,10 +580,10 @@ dependencies = [ "futures-executor", "futures-task", "futures-util", - "gio-sys 0.20.4", - "glib-macros 0.20.4", - "glib-sys 0.20.4", - "gobject-sys 0.20.4", + "gio-sys", + "glib-macros", + "glib-sys", + "gobject-sys", "libc", "log", "memchr", @@ -645,19 +592,6 @@ dependencies = [ [[package]] name = "glib-macros" -version = "0.19.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4429b0277a14ae9751350ad9b658b1be0abb5b54faa5bcdf6e74a3372582fad7" -dependencies = [ - "heck", - "proc-macro-crate", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "glib-macros" version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6bf88f70cd5720a6197639dcabcb378dd528d0cb68cb1f45e3b358bcb841cd7" @@ -671,16 +605,6 @@ dependencies = [ [[package]] name = "glib-sys" -version = "0.19.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c2dc18d3a82b0006d470b13304fbbb3e0a9bd4884cf985a60a7ed733ac2c4a5" -dependencies = [ - "libc", - "system-deps 6.2.2", -] - -[[package]] -name = "glib-sys" version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f9eca5d88cfa6a453b00d203287c34a2b7cac3a7831779aa2bb0b3c7233752b" @@ -691,22 +615,11 @@ dependencies = [ [[package]] name = "gobject-sys" -version = "0.19.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e697e252d6e0416fd1d9e169bda51c0f1c926026c39ca21fbe8b1bb5c3b8b9e" -dependencies = [ - "glib-sys 0.19.8", - "libc", - "system-deps 6.2.2", -] - -[[package]] -name = "gobject-sys" version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4c674d2ff8478cf0ec29d2be730ed779fef54415a2fb4b565c52def62696462" dependencies = [ - "glib-sys 0.20.4", + "glib-sys", "libc", "system-deps 7.0.3", ] @@ -717,7 +630,7 @@ version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f53144c7fe78292705ff23935f1477d511366fb2f73c43d63b37be89076d2fe" dependencies = [ - "glib 0.20.4", + "glib", "graphene-sys", "libc", ] @@ -728,7 +641,7 @@ version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e741797dc5081e59877a4d72c442c72d61efdd99161a0b1c1b29b6b988934b99" dependencies = [ - "glib-sys 0.20.4", + "glib-sys", "libc", "pkg-config", "system-deps 7.0.3", @@ -742,7 +655,7 @@ checksum = "aa21a2f7c51ee1c6cc1242c2faf3aae2b7566138f182696759987bde8219e922" dependencies = [ "cairo-rs", "gdk4", - "glib 0.20.4", + "glib", "graphene-rs", "gsk4-sys", "libc", @@ -757,8 +670,8 @@ checksum = "0f9fb607554f9f4e8829eb7ea301b0fde051e1dbfd5d16b143a8a9c2fac6c01b" dependencies = [ "cairo-sys-rs", "gdk4-sys", - "glib-sys 0.20.4", - "gobject-sys 0.20.4", + "glib-sys", + "gobject-sys", "graphene-sys", "libc", "pango-sys", @@ -776,8 +689,8 @@ dependencies = [ "futures-channel", "gdk-pixbuf", "gdk4", - "gio 0.20.4", - "glib 0.20.4", + "gio", + "glib", "graphene-rs", "gsk4", "gtk4-macros", @@ -807,9 +720,9 @@ dependencies = [ "cairo-sys-rs", "gdk-pixbuf-sys", "gdk4-sys", - "gio-sys 0.20.4", - "glib-sys 0.20.4", - "gobject-sys 0.20.4", + "gio-sys", + "glib-sys", + "gobject-sys", "graphene-sys", "gsk4-sys", "libc", @@ -955,8 +868,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ff9c222b5c783729de45185f07b2fec2d43a7f9c63961e777d3667e20443878" dependencies = [ "gdk4", - "gio 0.20.4", - "glib 0.20.4", + "gio", + "glib", "gtk4", "libadwaita-sys", "libc", @@ -970,9 +883,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c44d8bdbad31d6639e1f20cc9c1424f1a8e02d751fc28d44659bf743fb9eca6" dependencies = [ "gdk4-sys", - "gio-sys 0.20.4", - "glib-sys 0.20.4", - "gobject-sys 0.20.4", + "gio-sys", + "glib-sys", + "gobject-sys", "gtk4-sys", "libc", "pango-sys", @@ -987,25 +900,21 @@ checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "libsecret" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c6ccddc706a38eca477b4d7857acd6c76c7d6fba5d47b4b2e7d800e5a17194" +version = "0.6.0" dependencies = [ - "gio 0.19.8", - "glib 0.19.9", + "gio", + "glib", "libc", "libsecret-sys", ] [[package]] name = "libsecret-sys" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a1af48e61f1c8e77e9705296f346e45b637754a92348a79b4c62df84d0654c2" +version = "0.6.0" dependencies = [ - "gio-sys 0.19.8", - "glib-sys 0.19.8", - "gobject-sys 0.19.8", + "gio-sys", + "glib-sys", + "gobject-sys", "libc", "pkg-config", "system-deps 6.2.2", @@ -1222,8 +1131,8 @@ version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa26aa54b11094d72141a754901cd71d9356432bb8147f9cace8d9c7ba95f356" dependencies = [ - "gio 0.20.4", - "glib 0.20.4", + "gio", + "glib", "libc", "pango-sys", ] @@ -1234,8 +1143,8 @@ version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84fd65917bf12f06544ae2bbc200abf9fc0a513a5a88a0fa81013893aef2b838" dependencies = [ - "glib-sys 0.20.4", - "gobject-sys 0.20.4", + "glib-sys", + "gobject-sys", "libc", "system-deps 7.0.3", ] @@ -1649,8 +1558,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b84ccd1f4aee0854a16b0b489ba843798e2eb4cdcddd4a61248f7db9ce8b6df1" dependencies = [ "futures-channel", - "gio 0.20.4", - "glib 0.20.4", + "gio", + "glib", "libc", "soup3-sys", ] @@ -1661,9 +1570,9 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8869997193d52a61a1db48627bdaa57343f76e2c5132ee6d351245a6ab30631e" dependencies = [ - "gio-sys 0.20.4", - "glib-sys 0.20.4", - "gobject-sys 0.20.4", + "gio-sys", + "glib-sys", + "gobject-sys", "libc", "system-deps 7.0.3", ] diff --git a/Cargo.toml b/Cargo.toml index f9001d2..bdb3dbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ glib = { version = "0.20.1", features = ["log"] } gtk = { version = "0.9.0", package = "gtk4", features = ["gnome_46", "v4_14"] } kittybox-indieauth = { git = "https://git.vikanezrimaya.xyz/kittybox", version = "0.2.0" } kittybox-util = { git = "https://git.vikanezrimaya.xyz/kittybox", version = "0.2.0" } -libsecret = { version = "0.5.0", features = ["v0_21_2"] } +libsecret = { version = "0.6.0", features = ["v0_21_2"] } log = { version = "0.4.22", features = ["std"] } microformats = "0.9.1" relm4 = { version = "0.9.0", features = ["gnome_46", "adw", "css", "macros", "libadwaita"] } @@ -31,3 +31,7 @@ thiserror = "1.0.63" tokio = { version = "1.39.3", features = ["full", "tracing"] } tracing = { version = "0.1.40", features = ["log"] } tracker = "0.2.2" + +[patch.crates-io] +libsecret = { path = "./libsecret" } +libsecret-sys = { path = "./libsecret/sys" } \ No newline at end of file diff --git a/libsecret/.cargo_vcs_info.json b/libsecret/.cargo_vcs_info.json new file mode 100644 index 0000000..38708f8 --- /dev/null +++ b/libsecret/.cargo_vcs_info.json @@ -0,0 +1,6 @@ +{ + "git": { + "sha1": "124286ef3e4c68d8bb2d0f852fcc77d9a2f5229b" + }, + "path_in_vcs": "libsecret" +} \ No newline at end of file diff --git a/libsecret/Cargo.toml b/libsecret/Cargo.toml new file mode 100644 index 0000000..93b9a3a --- /dev/null +++ b/libsecret/Cargo.toml @@ -0,0 +1,95 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2021" +name = "libsecret" +version = "0.6.0" +authors = [ + "Bilal Elmoussaoui <bil.elmoussaoui@gmail.com>", + "Maximiliano Sandoval <msandova@gnome.org>", + "Sophie Herold <sophie@hemio.de>", +] +build = false +exclude = [ + "gir-files/*", + "gir/", +] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "Rust bindings of libsecret" +homepage = "https://world.pages.gitlab.gnome.org/Rust/libsecret-rs" +documentation = "https://world.pages.gitlab.gnome.org/Rust/libsecret-rs/stable/latest/docs/libsecret" +readme = "README.md" +keywords = [ + "libsecret", + "dbus", + "secret", + "bindings", + "freedesktop", +] +categories = ["api-bindings"] +license = "MIT" +repository = "https://gitlab.gnome.org/World/Rust/libsecret-rs" + +[package.metadata.docs.rs] +all-features = true +rustc-args = [ + "--cfg", + "docsrs", +] +rustdoc-args = [ + "--cfg", + "docsrs", +] + +[lib] +name = "libsecret" +path = "src/lib.rs" + +[dependencies.ffi] +version = "0.6" +package = "libsecret-sys" + +[dependencies.gio] +version = "0.20" + +[dependencies.glib] +version = "0.20" + +[dependencies.libc] +version = "0.2" + +[features] +default = ["v0_18"] +v0_18 = ["ffi/v0_18"] +v0_18_6 = [ + "v0_18", + "ffi/v0_18_6", +] +v0_19 = [ + "v0_18_6", + "ffi/v0_19", +] +v0_20 = [ + "v0_19", + "ffi/v0_20", +] +v0_21 = [ + "v0_20", + "ffi/v0_21", +] +v0_21_2 = [ + "v0_21", + "ffi/v0_21_2", +] diff --git a/libsecret/Cargo.toml.orig b/libsecret/Cargo.toml.orig new file mode 100644 index 0000000..d6f13ac --- /dev/null +++ b/libsecret/Cargo.toml.orig @@ -0,0 +1,53 @@ +[package] +name = "libsecret" +version = "0.6.0" +authors = [ + "Bilal Elmoussaoui <bil.elmoussaoui@gmail.com>", + "Maximiliano Sandoval <msandova@gnome.org>", + "Sophie Herold <sophie@hemio.de>", +] +edition = "2021" +exclude = [ + 'gir-files/*', + 'gir/', +] +readme = "../README.md" +license = 'MIT' +repository = 'https://gitlab.gnome.org/World/Rust/libsecret-rs' +documentation = "https://world.pages.gitlab.gnome.org/Rust/libsecret-rs/stable/latest/docs/libsecret" +categories = ["api-bindings"] +description = "Rust bindings of libsecret" +homepage = "https://world.pages.gitlab.gnome.org/Rust/libsecret-rs" +keywords = ["libsecret", "dbus", "secret", "bindings", "freedesktop"] + +[dependencies] +libc = "0.2" + +[dependencies.glib] +git = "https://github.com/gtk-rs/gtk-rs-core" +version = "0.20" +tag = "0.20.4" + +[dependencies.gio] +git = "https://github.com/gtk-rs/gtk-rs-core" +version = "0.20" +tag = "0.20.4" + +[dependencies.ffi] +package = "libsecret-sys" +path = './sys' +version = "0.6" + +[features] +default = [ "v0_18" ] +v0_18 = [ "ffi/v0_18"] +v0_18_6 = [ "v0_18", "ffi/v0_18_6"] +v0_19 = ["v0_18_6", "ffi/v0_19"] +v0_20 = [ "v0_19", "ffi/v0_20" ] +v0_21 = [ "v0_20", "ffi/v0_21" ] +v0_21_2 = ["v0_21", "ffi/v0_21_2"] + +[package.metadata.docs.rs] +all-features = true +rustc-args = ["--cfg", "docsrs"] +rustdoc-args = ["--cfg", "docsrs"] diff --git a/libsecret/Gir.toml b/libsecret/Gir.toml new file mode 100644 index 0000000..d9e0f83 --- /dev/null +++ b/libsecret/Gir.toml @@ -0,0 +1,241 @@ +[external_libraries] +Gio = { min_version = "2.48"} + +[options] +girs_directories = ["../gir-files", "../"] +library = "Secret" +version = "1" +min_cfg_version = "0.1" +target_path = "." +work_mode = "normal" +single_version_file = true +deprecate_by_min_version = true +use_gi_docgen = true +trust_return_value_nullability = true + +external_libraries = [ + "GLib", + "GObject", +] + +ignore = [ + # Github CI don't have its +] + +generate = [ + "Secret.Backend", + "Secret.BackendFlags", + "Secret.CollectionCreateFlags", + "Secret.CollectionFlags", + "Secret.ItemCreateFlags", + "Secret.ItemFlags", + "Secret.SchemaAttribute", + "Secret.SchemaAttributeType", + "Secret.SchemaFlags", + "Secret.SearchFlags", + "Secret.ServiceFlags", + "Secret.SchemaType" +] + +manual = [ + "GLib.Variant", + "GLib.VariantType", + "GLib.Error", + "GLib.List", + "GLib.HashTable", + "Gio.Cancellable", + "Gio.AsyncResult", + "Gio.Initable", + "Gio.DBusInterface", + "Gio.DBusProxy", + "GLib.Quark", +] + +[[object]] +name = "Secret.*" +status = "generate" + [[object.function]] + pattern = "(attributes_build|attributes_buildv)" + ignore = true # va args + [[object.function]] + pattern = "password_(clear|clear_sync|lookup|lookup_binary_sync|lookup_nonpageable_sync|lookup_sync|search|search_sync|store|store_sync|store_binary|store_binary_sync)" + ignore = true # va args + [[object.function]] + name = "password_clearv_sync" + rename = "password_clear_sync" + manual = true + [[object.function]] + name = "password_clearv" + rename = "password_clear" + manual = true + [[object.function]] + name = "password_storev_sync" + rename = "password_store_sync" + manual = true + [[object.function]] + name = "password_storev" + rename = "password_store" + manual = true + [[object.function]] + name = "password_lookupv_binary_sync" + rename = "password_lookup_binary_sync" + manual = true + [[object.function]] + name = "password_lookupv_sync" + rename = "password_lookup_sync" + manual = true + [[object.function]] + name = "password_lookupv" + rename = "password_lookup" + manual = true + [[object.function]] + name = "password_lookupv_nonpageable_sync" + rename = "password_lookup_nonpageable_sync" + manual = true + [[object.function]] + name = "password_storev_binary_sync" + rename = "password_store_binary_sync" + manual = true + [[object.function]] + name = "password_storev_binary" + rename = "password_store_binary" + manual = true + [[object.function]] + name = "password_searchv_sync" + rename = "password_search_sync" + manual = true + [[object.function]] + name = "password_searchv" + rename = "password_search" + manual = true + + +[[object]] +name = "Secret.Collection" +status = "generate" +manual_traits = ["CollectionExtManual"] + [[object.function]] + name = "search" + manual = true + [[object.function]] + name = "search_sync" + manual = true + [[object.function]] + name = "search_for_dbus_paths_sync" + manual = true + [[object.function]] + name = "search_for_dbus_paths" + manual = true + +[[object]] +name = "Secret.Error" +status = "generate" + [[object.function]] + name = "get_quark" + ignore = true # we implement ErrorDomain instead + +[[object]] +name = "Secret.Item" +status = "generate" + [[object.function]] + name = "load_secrets_sync" + manual = true + [[object.function]] + name = "load_secrets" + manual = true + [[object.function]] + name = "create" + manual = true + [[object.function]] + name = "create_sync" + manual = true + [[object.function]] + name = "get_attributes" + manual = true + [[object.function]] + name = "set_attributes" + manual = true + [[object.function]] + name = "set_attributes_sync" + manual = true + +[[object]] +name = "Secret.Prompt" +status = "generate" +manual_traits = ["PromptExtManual"] + [[object.function]] + name = "perform" + manual = true + +[[object]] +name = "Secret.Retrievable" +status = "generate" +manual_traits = ["RetrievableExtManual"] + [[object.function]] + name = "get_attributes" + manual = true + +[[object]] +name = "Secret.Schema" +status = "generate" + [[object.function]] + name = "new" + ignore = true + [[object.function]] + name = "newv" + rename = "new" + manual = true + +[[object]] +name = "Secret.Service" +status = "generate" +manual_traits = ["ServiceExtManual"] + [[object.function]] + name = "lock_dbus_paths_sync" + manual = true + [[object.function]] + name = "lock" + manual = true + [[object.function]] + name = "lock_future" + manual = true + [[object.function]] + name = "unlock_dbus_paths" + manual = true + [[object.function]] + name = "unlock" + manual = true + [[object.function]] + name = "lock_dbus_paths" + manual = true + [[object.function]] + name = "store" + manual = true + [[object.function]] + name = "search" + manual = true + [[object.function]] + name = "lookup" + manual = true + [[object.function]] + name = "clear" + manual = true + [[object.function]] + name = "create_item_dbus_path" + manual = true + [[object.function]] + name = "create_collection_dbus_path" + manual = true + [[object.function]] + name = "get_secrets_for_dbus_paths" + manual = true + [[object.function]] + name = "search_for_dbus_paths" + manual = true + +[[object]] +name = "Secret.Value" +status = "manual" + [[object.function]] + name = "new_full" + ignore = true diff --git a/libsecret/README.md b/libsecret/README.md new file mode 100644 index 0000000..9a47559 --- /dev/null +++ b/libsecret/README.md @@ -0,0 +1,10 @@ +# libsecret-rs + +The Rust bindings of [libsecret](https://gitlab.gnome.org/GNOME/libsecret). + +- Website: <https://gitlab.gnome.org/World/Rust/libsecret-rs/> + +# Documentation + +- libsecret: <https://world.pages.gitlab.gnome.org/Rust/libsecret-rs/stable/latest/docs/libsecret> +- libsecret_sys: <https://world.pages.gitlab.gnome.org/Rust/libsecret-rs/stable/latest/docs/libsecret_sys> diff --git a/libsecret/src/auto/backend.rs b/libsecret/src/auto/backend.rs new file mode 100644 index 0000000..bba5bf0 --- /dev/null +++ b/libsecret/src/auto/backend.rs @@ -0,0 +1,92 @@ +// This file was generated by gir (https://github.com/gtk-rs/gir) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git) +// DO NOT EDIT + +use crate::{BackendFlags, ServiceFlags}; +use glib::{prelude::*, translate::*}; +use std::{boxed::Box as Box_, pin::Pin}; + +glib::wrapper! { + #[doc(alias = "SecretBackend")] + pub struct Backend(Interface<ffi::SecretBackend, ffi::SecretBackendInterface>); + + match fn { + type_ => || ffi::secret_backend_get_type(), + } +} + +impl Backend { + pub const NONE: Option<&'static Backend> = None; + + #[doc(alias = "secret_backend_get")] + pub fn get<P: FnOnce(Result<Backend, glib::Error>) + 'static>( + flags: BackendFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn get_trampoline<P: FnOnce(Result<Backend, glib::Error>) + 'static>( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_backend_get_finish(res, &mut error); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = get_trampoline::<P>; + unsafe { + ffi::secret_backend_get( + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + pub fn get_future( + flags: BackendFlags, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<Backend, glib::Error>> + 'static>> { + Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| { + Self::get(flags, Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } +} + +mod sealed { + pub trait Sealed {} + impl<T: super::IsA<super::Backend>> Sealed for T {} +} + +pub trait BackendExt: IsA<Backend> + sealed::Sealed + 'static { + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + fn flags(&self) -> ServiceFlags { + ObjectExt::property(self.as_ref(), "flags") + } +} + +impl<O: IsA<Backend>> BackendExt for O {} diff --git a/libsecret/src/auto/collection.rs b/libsecret/src/auto/collection.rs new file mode 100644 index 0000000..8c91b65 --- /dev/null +++ b/libsecret/src/auto/collection.rs @@ -0,0 +1,742 @@ +// This file was generated by gir (https://github.com/gtk-rs/gir) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git) +// DO NOT EDIT + +use crate::{CollectionCreateFlags, CollectionFlags, Item, Service}; +use glib::{ + prelude::*, + signal::{connect_raw, SignalHandlerId}, + translate::*, +}; +use std::{boxed::Box as Box_, pin::Pin}; + +glib::wrapper! { + #[doc(alias = "SecretCollection")] + pub struct Collection(Object<ffi::SecretCollection, ffi::SecretCollectionClass>) @extends gio::DBusProxy, @implements gio::DBusInterface, gio::Initable; + + match fn { + type_ => || ffi::secret_collection_get_type(), + } +} + +impl Collection { + pub const NONE: Option<&'static Collection> = None; + + #[doc(alias = "secret_collection_new_for_dbus_path_sync")] + #[doc(alias = "new_for_dbus_path_sync")] + pub fn for_dbus_path_sync( + service: Option<&impl IsA<Service>>, + collection_path: &str, + flags: CollectionFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<Collection, glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_collection_new_for_dbus_path_sync( + service.map(|p| p.as_ref()).to_glib_none().0, + collection_path.to_glib_none().0, + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "secret_collection_create")] + pub fn create<P: FnOnce(Result<Collection, glib::Error>) + 'static>( + service: Option<&impl IsA<Service>>, + label: &str, + alias: Option<&str>, + flags: CollectionCreateFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn create_trampoline< + P: FnOnce(Result<Collection, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_collection_create_finish(res, &mut error); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = create_trampoline::<P>; + unsafe { + ffi::secret_collection_create( + service.map(|p| p.as_ref()).to_glib_none().0, + label.to_glib_none().0, + alias.to_glib_none().0, + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + pub fn create_future( + service: Option<&(impl IsA<Service> + Clone + 'static)>, + label: &str, + alias: Option<&str>, + flags: CollectionCreateFlags, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<Collection, glib::Error>> + 'static>> + { + let service = service.map(ToOwned::to_owned); + let label = String::from(label); + let alias = alias.map(ToOwned::to_owned); + Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| { + Self::create( + service.as_ref().map(::std::borrow::Borrow::borrow), + &label, + alias.as_ref().map(::std::borrow::Borrow::borrow), + flags, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + #[doc(alias = "secret_collection_create_sync")] + pub fn create_sync( + service: Option<&impl IsA<Service>>, + label: &str, + alias: Option<&str>, + flags: CollectionCreateFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<Collection, glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_collection_create_sync( + service.map(|p| p.as_ref()).to_glib_none().0, + label.to_glib_none().0, + alias.to_glib_none().0, + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "secret_collection_for_alias")] + pub fn for_alias<P: FnOnce(Result<Option<Collection>, glib::Error>) + 'static>( + service: Option<&impl IsA<Service>>, + alias: &str, + flags: CollectionFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn for_alias_trampoline< + P: FnOnce(Result<Option<Collection>, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_collection_for_alias_finish(res, &mut error); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = for_alias_trampoline::<P>; + unsafe { + ffi::secret_collection_for_alias( + service.map(|p| p.as_ref()).to_glib_none().0, + alias.to_glib_none().0, + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + pub fn for_alias_future( + service: Option<&(impl IsA<Service> + Clone + 'static)>, + alias: &str, + flags: CollectionFlags, + ) -> Pin< + Box_<dyn std::future::Future<Output = Result<Option<Collection>, glib::Error>> + 'static>, + > { + let service = service.map(ToOwned::to_owned); + let alias = String::from(alias); + Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| { + Self::for_alias( + service.as_ref().map(::std::borrow::Borrow::borrow), + &alias, + flags, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + #[doc(alias = "secret_collection_for_alias_sync")] + pub fn for_alias_sync( + service: Option<&impl IsA<Service>>, + alias: &str, + flags: CollectionFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<Option<Collection>, glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_collection_for_alias_sync( + service.map(|p| p.as_ref()).to_glib_none().0, + alias.to_glib_none().0, + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "secret_collection_new_for_dbus_path")] + pub fn new_for_dbus_path<P: FnOnce(Result<Collection, glib::Error>) + 'static>( + service: Option<&impl IsA<Service>>, + collection_path: &str, + flags: CollectionFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn new_for_dbus_path_trampoline< + P: FnOnce(Result<Collection, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_collection_new_for_dbus_path_finish(res, &mut error); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = new_for_dbus_path_trampoline::<P>; + unsafe { + ffi::secret_collection_new_for_dbus_path( + service.map(|p| p.as_ref()).to_glib_none().0, + collection_path.to_glib_none().0, + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + pub fn new_for_dbus_path_future( + service: Option<&(impl IsA<Service> + Clone + 'static)>, + collection_path: &str, + flags: CollectionFlags, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<Collection, glib::Error>> + 'static>> + { + let service = service.map(ToOwned::to_owned); + let collection_path = String::from(collection_path); + Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| { + Self::new_for_dbus_path( + service.as_ref().map(::std::borrow::Borrow::borrow), + &collection_path, + flags, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } +} + +mod sealed { + pub trait Sealed {} + impl<T: super::IsA<super::Collection>> Sealed for T {} +} + +pub trait CollectionExt: IsA<Collection> + sealed::Sealed + 'static { + #[doc(alias = "secret_collection_delete")] + fn delete<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn delete_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let _ = ffi::secret_collection_delete_finish(_source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = delete_trampoline::<P>; + unsafe { + ffi::secret_collection_delete( + self.as_ref().to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn delete_future( + &self, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.delete(Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + #[doc(alias = "secret_collection_delete_sync")] + fn delete_sync( + &self, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<(), glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let is_ok = ffi::secret_collection_delete_sync( + self.as_ref().to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); + if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "secret_collection_get_created")] + #[doc(alias = "get_created")] + fn created(&self) -> u64 { + unsafe { ffi::secret_collection_get_created(self.as_ref().to_glib_none().0) } + } + + #[doc(alias = "secret_collection_get_flags")] + #[doc(alias = "get_flags")] + fn flags(&self) -> CollectionFlags { + unsafe { + from_glib(ffi::secret_collection_get_flags( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "secret_collection_get_items")] + #[doc(alias = "get_items")] + fn items(&self) -> Vec<Item> { + unsafe { + FromGlibPtrContainer::from_glib_full(ffi::secret_collection_get_items( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "secret_collection_get_label")] + #[doc(alias = "get_label")] + fn label(&self) -> glib::GString { + unsafe { + from_glib_full(ffi::secret_collection_get_label( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "secret_collection_get_locked")] + #[doc(alias = "get_locked")] + fn is_locked(&self) -> bool { + unsafe { + from_glib(ffi::secret_collection_get_locked( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "secret_collection_get_modified")] + #[doc(alias = "get_modified")] + fn modified(&self) -> u64 { + unsafe { ffi::secret_collection_get_modified(self.as_ref().to_glib_none().0) } + } + + #[doc(alias = "secret_collection_get_service")] + #[doc(alias = "get_service")] + fn service(&self) -> Service { + unsafe { + from_glib_none(ffi::secret_collection_get_service( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "secret_collection_load_items")] + fn load_items<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn load_items_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let _ = + ffi::secret_collection_load_items_finish(_source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = load_items_trampoline::<P>; + unsafe { + ffi::secret_collection_load_items( + self.as_ref().to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn load_items_future( + &self, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.load_items(Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + #[doc(alias = "secret_collection_load_items_sync")] + fn load_items_sync( + &self, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<(), glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let is_ok = ffi::secret_collection_load_items_sync( + self.as_ref().to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); + if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "secret_collection_refresh")] + fn refresh(&self) { + unsafe { + ffi::secret_collection_refresh(self.as_ref().to_glib_none().0); + } + } + + #[doc(alias = "secret_collection_set_label")] + fn set_label<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + label: &str, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn set_label_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let _ = + ffi::secret_collection_set_label_finish(_source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = set_label_trampoline::<P>; + unsafe { + ffi::secret_collection_set_label( + self.as_ref().to_glib_none().0, + label.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn set_label_future( + &self, + label: &str, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { + let label = String::from(label); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.set_label(&label, Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + #[doc(alias = "secret_collection_set_label_sync")] + fn set_label_sync( + &self, + label: &str, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<(), glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let is_ok = ffi::secret_collection_set_label_sync( + self.as_ref().to_glib_none().0, + label.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); + if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + } + } + } + + fn set_created(&self, created: u64) { + ObjectExt::set_property(self.as_ref(), "created", created) + } + + fn set_modified(&self, modified: u64) { + ObjectExt::set_property(self.as_ref(), "modified", modified) + } + + #[doc(alias = "created")] + fn connect_created_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { + unsafe extern "C" fn notify_created_trampoline<P: IsA<Collection>, F: Fn(&P) + 'static>( + this: *mut ffi::SecretCollection, + _param_spec: glib::ffi::gpointer, + f: glib::ffi::gpointer, + ) { + let f: &F = &*(f as *const F); + f(Collection::from_glib_borrow(this).unsafe_cast_ref()) + } + unsafe { + let f: Box_<F> = Box_::new(f); + connect_raw( + self.as_ptr() as *mut _, + b"notify::created\0".as_ptr() as *const _, + Some(std::mem::transmute::<_, unsafe extern "C" fn()>( + notify_created_trampoline::<Self, F> as *const (), + )), + Box_::into_raw(f), + ) + } + } + + #[doc(alias = "label")] + fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { + unsafe extern "C" fn notify_label_trampoline<P: IsA<Collection>, F: Fn(&P) + 'static>( + this: *mut ffi::SecretCollection, + _param_spec: glib::ffi::gpointer, + f: glib::ffi::gpointer, + ) { + let f: &F = &*(f as *const F); + f(Collection::from_glib_borrow(this).unsafe_cast_ref()) + } + unsafe { + let f: Box_<F> = Box_::new(f); + connect_raw( + self.as_ptr() as *mut _, + b"notify::label\0".as_ptr() as *const _, + Some(std::mem::transmute::<_, unsafe extern "C" fn()>( + notify_label_trampoline::<Self, F> as *const (), + )), + Box_::into_raw(f), + ) + } + } + + #[doc(alias = "locked")] + fn connect_locked_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { + unsafe extern "C" fn notify_locked_trampoline<P: IsA<Collection>, F: Fn(&P) + 'static>( + this: *mut ffi::SecretCollection, + _param_spec: glib::ffi::gpointer, + f: glib::ffi::gpointer, + ) { + let f: &F = &*(f as *const F); + f(Collection::from_glib_borrow(this).unsafe_cast_ref()) + } + unsafe { + let f: Box_<F> = Box_::new(f); + connect_raw( + self.as_ptr() as *mut _, + b"notify::locked\0".as_ptr() as *const _, + Some(std::mem::transmute::<_, unsafe extern "C" fn()>( + notify_locked_trampoline::<Self, F> as *const (), + )), + Box_::into_raw(f), + ) + } + } + + #[doc(alias = "modified")] + fn connect_modified_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { + unsafe extern "C" fn notify_modified_trampoline<P: IsA<Collection>, F: Fn(&P) + 'static>( + this: *mut ffi::SecretCollection, + _param_spec: glib::ffi::gpointer, + f: glib::ffi::gpointer, + ) { + let f: &F = &*(f as *const F); + f(Collection::from_glib_borrow(this).unsafe_cast_ref()) + } + unsafe { + let f: Box_<F> = Box_::new(f); + connect_raw( + self.as_ptr() as *mut _, + b"notify::modified\0".as_ptr() as *const _, + Some(std::mem::transmute::<_, unsafe extern "C" fn()>( + notify_modified_trampoline::<Self, F> as *const (), + )), + Box_::into_raw(f), + ) + } + } +} + +impl<O: IsA<Collection>> CollectionExt for O {} diff --git a/libsecret/src/auto/constants.rs b/libsecret/src/auto/constants.rs new file mode 100644 index 0000000..1086b79 --- /dev/null +++ b/libsecret/src/auto/constants.rs @@ -0,0 +1,16 @@ +// This file was generated by gir (https://github.com/gtk-rs/gir) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git) +// DO NOT EDIT + +use glib::GStr; + +#[doc(alias = "SECRET_BACKEND_EXTENSION_POINT_NAME")] +pub static BACKEND_EXTENSION_POINT_NAME: &GStr = + unsafe { GStr::from_utf8_with_nul_unchecked(ffi::SECRET_BACKEND_EXTENSION_POINT_NAME) }; +#[doc(alias = "SECRET_COLLECTION_DEFAULT")] +pub static COLLECTION_DEFAULT: &GStr = + unsafe { GStr::from_utf8_with_nul_unchecked(ffi::SECRET_COLLECTION_DEFAULT) }; +#[doc(alias = "SECRET_COLLECTION_SESSION")] +pub static COLLECTION_SESSION: &GStr = + unsafe { GStr::from_utf8_with_nul_unchecked(ffi::SECRET_COLLECTION_SESSION) }; diff --git a/libsecret/src/auto/enums.rs b/libsecret/src/auto/enums.rs new file mode 100644 index 0000000..d9cf2ff --- /dev/null +++ b/libsecret/src/auto/enums.rs @@ -0,0 +1,462 @@ +// This file was generated by gir (https://github.com/gtk-rs/gir) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git) +// DO NOT EDIT + +use glib::{prelude::*, translate::*}; + +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] +#[non_exhaustive] +#[doc(alias = "SecretBackendFlags")] +pub enum BackendFlags { + #[doc(alias = "SECRET_BACKEND_NONE")] + None, + #[doc(alias = "SECRET_BACKEND_OPEN_SESSION")] + OpenSession, + #[doc(alias = "SECRET_BACKEND_LOAD_COLLECTIONS")] + LoadCollections, + #[doc(hidden)] + __Unknown(i32), +} + +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +#[doc(hidden)] +impl IntoGlib for BackendFlags { + type GlibType = ffi::SecretBackendFlags; + + #[inline] + fn into_glib(self) -> ffi::SecretBackendFlags { + match self { + Self::None => ffi::SECRET_BACKEND_NONE, + Self::OpenSession => ffi::SECRET_BACKEND_OPEN_SESSION, + Self::LoadCollections => ffi::SECRET_BACKEND_LOAD_COLLECTIONS, + Self::__Unknown(value) => value, + } + } +} + +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +#[doc(hidden)] +impl FromGlib<ffi::SecretBackendFlags> for BackendFlags { + #[inline] + unsafe fn from_glib(value: ffi::SecretBackendFlags) -> Self { + match value { + ffi::SECRET_BACKEND_NONE => Self::None, + ffi::SECRET_BACKEND_OPEN_SESSION => Self::OpenSession, + ffi::SECRET_BACKEND_LOAD_COLLECTIONS => Self::LoadCollections, + value => Self::__Unknown(value), + } + } +} + +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +impl StaticType for BackendFlags { + #[inline] + #[doc(alias = "secret_backend_flags_get_type")] + fn static_type() -> glib::Type { + unsafe { from_glib(ffi::secret_backend_flags_get_type()) } + } +} + +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +impl glib::HasParamSpec for BackendFlags { + type ParamSpec = glib::ParamSpecEnum; + type SetValue = Self; + type BuilderFn = fn(&str, Self) -> glib::ParamSpecEnumBuilder<Self>; + + fn param_spec_builder() -> Self::BuilderFn { + Self::ParamSpec::builder_with_default + } +} + +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +impl glib::value::ValueType for BackendFlags { + type Type = Self; +} + +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +unsafe impl<'a> glib::value::FromValue<'a> for BackendFlags { + type Checker = glib::value::GenericValueTypeChecker<Self>; + + #[inline] + unsafe fn from_value(value: &'a glib::Value) -> Self { + from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0)) + } +} + +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +impl ToValue for BackendFlags { + #[inline] + fn to_value(&self) -> glib::Value { + let mut value = glib::Value::for_value_type::<Self>(); + unsafe { + glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib()); + } + value + } + + #[inline] + fn value_type(&self) -> glib::Type { + Self::static_type() + } +} + +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +impl From<BackendFlags> for glib::Value { + #[inline] + fn from(v: BackendFlags) -> Self { + ToValue::to_value(&v) + } +} + +#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] +#[non_exhaustive] +#[doc(alias = "SecretError")] +pub enum Error { + #[doc(alias = "SECRET_ERROR_PROTOCOL")] + Protocol, + #[doc(alias = "SECRET_ERROR_IS_LOCKED")] + IsLocked, + #[doc(alias = "SECRET_ERROR_NO_SUCH_OBJECT")] + NoSuchObject, + #[doc(alias = "SECRET_ERROR_ALREADY_EXISTS")] + AlreadyExists, + #[doc(alias = "SECRET_ERROR_INVALID_FILE_FORMAT")] + InvalidFileFormat, + #[cfg(feature = "v0_21_2")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_21_2")))] + #[doc(alias = "SECRET_ERROR_MISMATCHED_SCHEMA")] + MismatchedSchema, + #[cfg(feature = "v0_21_2")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_21_2")))] + #[doc(alias = "SECRET_ERROR_NO_MATCHING_ATTRIBUTE")] + NoMatchingAttribute, + #[cfg(feature = "v0_21_2")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_21_2")))] + #[doc(alias = "SECRET_ERROR_WRONG_TYPE")] + WrongType, + #[cfg(feature = "v0_21_2")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_21_2")))] + #[doc(alias = "SECRET_ERROR_EMPTY_TABLE")] + EmptyTable, + #[doc(hidden)] + __Unknown(i32), +} + +#[doc(hidden)] +impl IntoGlib for Error { + type GlibType = ffi::SecretError; + + #[inline] + fn into_glib(self) -> ffi::SecretError { + match self { + Self::Protocol => ffi::SECRET_ERROR_PROTOCOL, + Self::IsLocked => ffi::SECRET_ERROR_IS_LOCKED, + Self::NoSuchObject => ffi::SECRET_ERROR_NO_SUCH_OBJECT, + Self::AlreadyExists => ffi::SECRET_ERROR_ALREADY_EXISTS, + Self::InvalidFileFormat => ffi::SECRET_ERROR_INVALID_FILE_FORMAT, + #[cfg(feature = "v0_21_2")] + Self::MismatchedSchema => ffi::SECRET_ERROR_MISMATCHED_SCHEMA, + #[cfg(feature = "v0_21_2")] + Self::NoMatchingAttribute => ffi::SECRET_ERROR_NO_MATCHING_ATTRIBUTE, + #[cfg(feature = "v0_21_2")] + Self::WrongType => ffi::SECRET_ERROR_WRONG_TYPE, + #[cfg(feature = "v0_21_2")] + Self::EmptyTable => ffi::SECRET_ERROR_EMPTY_TABLE, + Self::__Unknown(value) => value, + } + } +} + +#[doc(hidden)] +impl FromGlib<ffi::SecretError> for Error { + #[inline] + unsafe fn from_glib(value: ffi::SecretError) -> Self { + match value { + ffi::SECRET_ERROR_PROTOCOL => Self::Protocol, + ffi::SECRET_ERROR_IS_LOCKED => Self::IsLocked, + ffi::SECRET_ERROR_NO_SUCH_OBJECT => Self::NoSuchObject, + ffi::SECRET_ERROR_ALREADY_EXISTS => Self::AlreadyExists, + ffi::SECRET_ERROR_INVALID_FILE_FORMAT => Self::InvalidFileFormat, + #[cfg(feature = "v0_21_2")] + ffi::SECRET_ERROR_MISMATCHED_SCHEMA => Self::MismatchedSchema, + #[cfg(feature = "v0_21_2")] + ffi::SECRET_ERROR_NO_MATCHING_ATTRIBUTE => Self::NoMatchingAttribute, + #[cfg(feature = "v0_21_2")] + ffi::SECRET_ERROR_WRONG_TYPE => Self::WrongType, + #[cfg(feature = "v0_21_2")] + ffi::SECRET_ERROR_EMPTY_TABLE => Self::EmptyTable, + value => Self::__Unknown(value), + } + } +} + +impl StaticType for Error { + #[inline] + #[doc(alias = "secret_error_get_type")] + fn static_type() -> glib::Type { + unsafe { from_glib(ffi::secret_error_get_type()) } + } +} + +impl glib::HasParamSpec for Error { + type ParamSpec = glib::ParamSpecEnum; + type SetValue = Self; + type BuilderFn = fn(&str, Self) -> glib::ParamSpecEnumBuilder<Self>; + + fn param_spec_builder() -> Self::BuilderFn { + Self::ParamSpec::builder_with_default + } +} + +impl glib::value::ValueType for Error { + type Type = Self; +} + +unsafe impl<'a> glib::value::FromValue<'a> for Error { + type Checker = glib::value::GenericValueTypeChecker<Self>; + + #[inline] + unsafe fn from_value(value: &'a glib::Value) -> Self { + from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0)) + } +} + +impl ToValue for Error { + #[inline] + fn to_value(&self) -> glib::Value { + let mut value = glib::Value::for_value_type::<Self>(); + unsafe { + glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib()); + } + value + } + + #[inline] + fn value_type(&self) -> glib::Type { + Self::static_type() + } +} + +impl From<Error> for glib::Value { + #[inline] + fn from(v: Error) -> Self { + ToValue::to_value(&v) + } +} + +#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] +#[non_exhaustive] +#[doc(alias = "SecretSchemaAttributeType")] +pub enum SchemaAttributeType { + #[doc(alias = "SECRET_SCHEMA_ATTRIBUTE_STRING")] + String, + #[doc(alias = "SECRET_SCHEMA_ATTRIBUTE_INTEGER")] + Integer, + #[doc(alias = "SECRET_SCHEMA_ATTRIBUTE_BOOLEAN")] + Boolean, + #[doc(hidden)] + __Unknown(i32), +} + +#[doc(hidden)] +impl IntoGlib for SchemaAttributeType { + type GlibType = ffi::SecretSchemaAttributeType; + + #[inline] + fn into_glib(self) -> ffi::SecretSchemaAttributeType { + match self { + Self::String => ffi::SECRET_SCHEMA_ATTRIBUTE_STRING, + Self::Integer => ffi::SECRET_SCHEMA_ATTRIBUTE_INTEGER, + Self::Boolean => ffi::SECRET_SCHEMA_ATTRIBUTE_BOOLEAN, + Self::__Unknown(value) => value, + } + } +} + +#[doc(hidden)] +impl FromGlib<ffi::SecretSchemaAttributeType> for SchemaAttributeType { + #[inline] + unsafe fn from_glib(value: ffi::SecretSchemaAttributeType) -> Self { + match value { + ffi::SECRET_SCHEMA_ATTRIBUTE_STRING => Self::String, + ffi::SECRET_SCHEMA_ATTRIBUTE_INTEGER => Self::Integer, + ffi::SECRET_SCHEMA_ATTRIBUTE_BOOLEAN => Self::Boolean, + value => Self::__Unknown(value), + } + } +} + +impl StaticType for SchemaAttributeType { + #[inline] + #[doc(alias = "secret_schema_attribute_type_get_type")] + fn static_type() -> glib::Type { + unsafe { from_glib(ffi::secret_schema_attribute_type_get_type()) } + } +} + +impl glib::HasParamSpec for SchemaAttributeType { + type ParamSpec = glib::ParamSpecEnum; + type SetValue = Self; + type BuilderFn = fn(&str, Self) -> glib::ParamSpecEnumBuilder<Self>; + + fn param_spec_builder() -> Self::BuilderFn { + Self::ParamSpec::builder_with_default + } +} + +impl glib::value::ValueType for SchemaAttributeType { + type Type = Self; +} + +unsafe impl<'a> glib::value::FromValue<'a> for SchemaAttributeType { + type Checker = glib::value::GenericValueTypeChecker<Self>; + + #[inline] + unsafe fn from_value(value: &'a glib::Value) -> Self { + from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0)) + } +} + +impl ToValue for SchemaAttributeType { + #[inline] + fn to_value(&self) -> glib::Value { + let mut value = glib::Value::for_value_type::<Self>(); + unsafe { + glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib()); + } + value + } + + #[inline] + fn value_type(&self) -> glib::Type { + Self::static_type() + } +} + +impl From<SchemaAttributeType> for glib::Value { + #[inline] + fn from(v: SchemaAttributeType) -> Self { + ToValue::to_value(&v) + } +} + +#[cfg(feature = "v0_18_6")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))] +#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] +#[non_exhaustive] +#[doc(alias = "SecretSchemaType")] +pub enum SchemaType { + #[doc(alias = "SECRET_SCHEMA_TYPE_NOTE")] + Note, + #[doc(alias = "SECRET_SCHEMA_TYPE_COMPAT_NETWORK")] + CompatNetwork, + #[doc(hidden)] + __Unknown(i32), +} + +#[cfg(feature = "v0_18_6")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))] +#[doc(hidden)] +impl IntoGlib for SchemaType { + type GlibType = ffi::SecretSchemaType; + + #[inline] + fn into_glib(self) -> ffi::SecretSchemaType { + match self { + Self::Note => ffi::SECRET_SCHEMA_TYPE_NOTE, + Self::CompatNetwork => ffi::SECRET_SCHEMA_TYPE_COMPAT_NETWORK, + Self::__Unknown(value) => value, + } + } +} + +#[cfg(feature = "v0_18_6")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))] +#[doc(hidden)] +impl FromGlib<ffi::SecretSchemaType> for SchemaType { + #[inline] + unsafe fn from_glib(value: ffi::SecretSchemaType) -> Self { + match value { + ffi::SECRET_SCHEMA_TYPE_NOTE => Self::Note, + ffi::SECRET_SCHEMA_TYPE_COMPAT_NETWORK => Self::CompatNetwork, + value => Self::__Unknown(value), + } + } +} + +#[cfg(feature = "v0_18_6")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))] +impl StaticType for SchemaType { + #[inline] + #[doc(alias = "secret_schema_type_get_type")] + fn static_type() -> glib::Type { + unsafe { from_glib(ffi::secret_schema_type_get_type()) } + } +} + +#[cfg(feature = "v0_18_6")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))] +impl glib::HasParamSpec for SchemaType { + type ParamSpec = glib::ParamSpecEnum; + type SetValue = Self; + type BuilderFn = fn(&str, Self) -> glib::ParamSpecEnumBuilder<Self>; + + fn param_spec_builder() -> Self::BuilderFn { + Self::ParamSpec::builder_with_default + } +} + +#[cfg(feature = "v0_18_6")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))] +impl glib::value::ValueType for SchemaType { + type Type = Self; +} + +#[cfg(feature = "v0_18_6")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))] +unsafe impl<'a> glib::value::FromValue<'a> for SchemaType { + type Checker = glib::value::GenericValueTypeChecker<Self>; + + #[inline] + unsafe fn from_value(value: &'a glib::Value) -> Self { + from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0)) + } +} + +#[cfg(feature = "v0_18_6")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))] +impl ToValue for SchemaType { + #[inline] + fn to_value(&self) -> glib::Value { + let mut value = glib::Value::for_value_type::<Self>(); + unsafe { + glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib()); + } + value + } + + #[inline] + fn value_type(&self) -> glib::Type { + Self::static_type() + } +} + +#[cfg(feature = "v0_18_6")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))] +impl From<SchemaType> for glib::Value { + #[inline] + fn from(v: SchemaType) -> Self { + ToValue::to_value(&v) + } +} diff --git a/libsecret/src/auto/flags.rs b/libsecret/src/auto/flags.rs new file mode 100644 index 0000000..81c0f71 --- /dev/null +++ b/libsecret/src/auto/flags.rs @@ -0,0 +1,591 @@ +// This file was generated by gir (https://github.com/gtk-rs/gir) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git) +// DO NOT EDIT + +use glib::{bitflags::bitflags, prelude::*, translate::*}; + +bitflags! { + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] + #[doc(alias = "SecretCollectionCreateFlags")] + pub struct CollectionCreateFlags: u32 { + #[doc(alias = "SECRET_COLLECTION_CREATE_NONE")] + const NONE = ffi::SECRET_COLLECTION_CREATE_NONE as _; + } +} + +#[doc(hidden)] +impl IntoGlib for CollectionCreateFlags { + type GlibType = ffi::SecretCollectionCreateFlags; + + #[inline] + fn into_glib(self) -> ffi::SecretCollectionCreateFlags { + self.bits() + } +} + +#[doc(hidden)] +impl FromGlib<ffi::SecretCollectionCreateFlags> for CollectionCreateFlags { + #[inline] + unsafe fn from_glib(value: ffi::SecretCollectionCreateFlags) -> Self { + Self::from_bits_truncate(value) + } +} + +impl StaticType for CollectionCreateFlags { + #[inline] + #[doc(alias = "secret_collection_create_flags_get_type")] + fn static_type() -> glib::Type { + unsafe { from_glib(ffi::secret_collection_create_flags_get_type()) } + } +} + +impl glib::HasParamSpec for CollectionCreateFlags { + type ParamSpec = glib::ParamSpecFlags; + type SetValue = Self; + type BuilderFn = fn(&str) -> glib::ParamSpecFlagsBuilder<Self>; + + fn param_spec_builder() -> Self::BuilderFn { + Self::ParamSpec::builder + } +} + +impl glib::value::ValueType for CollectionCreateFlags { + type Type = Self; +} + +unsafe impl<'a> glib::value::FromValue<'a> for CollectionCreateFlags { + type Checker = glib::value::GenericValueTypeChecker<Self>; + + #[inline] + unsafe fn from_value(value: &'a glib::Value) -> Self { + from_glib(glib::gobject_ffi::g_value_get_flags(value.to_glib_none().0)) + } +} + +impl ToValue for CollectionCreateFlags { + #[inline] + fn to_value(&self) -> glib::Value { + let mut value = glib::Value::for_value_type::<Self>(); + unsafe { + glib::gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, self.into_glib()); + } + value + } + + #[inline] + fn value_type(&self) -> glib::Type { + Self::static_type() + } +} + +impl From<CollectionCreateFlags> for glib::Value { + #[inline] + fn from(v: CollectionCreateFlags) -> Self { + ToValue::to_value(&v) + } +} + +bitflags! { + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] + #[doc(alias = "SecretCollectionFlags")] + pub struct CollectionFlags: u32 { + #[doc(alias = "SECRET_COLLECTION_NONE")] + const NONE = ffi::SECRET_COLLECTION_NONE as _; + #[doc(alias = "SECRET_COLLECTION_LOAD_ITEMS")] + const LOAD_ITEMS = ffi::SECRET_COLLECTION_LOAD_ITEMS as _; + } +} + +#[doc(hidden)] +impl IntoGlib for CollectionFlags { + type GlibType = ffi::SecretCollectionFlags; + + #[inline] + fn into_glib(self) -> ffi::SecretCollectionFlags { + self.bits() + } +} + +#[doc(hidden)] +impl FromGlib<ffi::SecretCollectionFlags> for CollectionFlags { + #[inline] + unsafe fn from_glib(value: ffi::SecretCollectionFlags) -> Self { + Self::from_bits_truncate(value) + } +} + +impl StaticType for CollectionFlags { + #[inline] + #[doc(alias = "secret_collection_flags_get_type")] + fn static_type() -> glib::Type { + unsafe { from_glib(ffi::secret_collection_flags_get_type()) } + } +} + +impl glib::HasParamSpec for CollectionFlags { + type ParamSpec = glib::ParamSpecFlags; + type SetValue = Self; + type BuilderFn = fn(&str) -> glib::ParamSpecFlagsBuilder<Self>; + + fn param_spec_builder() -> Self::BuilderFn { + Self::ParamSpec::builder + } +} + +impl glib::value::ValueType for CollectionFlags { + type Type = Self; +} + +unsafe impl<'a> glib::value::FromValue<'a> for CollectionFlags { + type Checker = glib::value::GenericValueTypeChecker<Self>; + + #[inline] + unsafe fn from_value(value: &'a glib::Value) -> Self { + from_glib(glib::gobject_ffi::g_value_get_flags(value.to_glib_none().0)) + } +} + +impl ToValue for CollectionFlags { + #[inline] + fn to_value(&self) -> glib::Value { + let mut value = glib::Value::for_value_type::<Self>(); + unsafe { + glib::gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, self.into_glib()); + } + value + } + + #[inline] + fn value_type(&self) -> glib::Type { + Self::static_type() + } +} + +impl From<CollectionFlags> for glib::Value { + #[inline] + fn from(v: CollectionFlags) -> Self { + ToValue::to_value(&v) + } +} + +bitflags! { + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] + #[doc(alias = "SecretItemCreateFlags")] + pub struct ItemCreateFlags: u32 { + #[doc(alias = "SECRET_ITEM_CREATE_NONE")] + const NONE = ffi::SECRET_ITEM_CREATE_NONE as _; + #[doc(alias = "SECRET_ITEM_CREATE_REPLACE")] + const REPLACE = ffi::SECRET_ITEM_CREATE_REPLACE as _; + } +} + +#[doc(hidden)] +impl IntoGlib for ItemCreateFlags { + type GlibType = ffi::SecretItemCreateFlags; + + #[inline] + fn into_glib(self) -> ffi::SecretItemCreateFlags { + self.bits() + } +} + +#[doc(hidden)] +impl FromGlib<ffi::SecretItemCreateFlags> for ItemCreateFlags { + #[inline] + unsafe fn from_glib(value: ffi::SecretItemCreateFlags) -> Self { + Self::from_bits_truncate(value) + } +} + +impl StaticType for ItemCreateFlags { + #[inline] + #[doc(alias = "secret_item_create_flags_get_type")] + fn static_type() -> glib::Type { + unsafe { from_glib(ffi::secret_item_create_flags_get_type()) } + } +} + +impl glib::HasParamSpec for ItemCreateFlags { + type ParamSpec = glib::ParamSpecFlags; + type SetValue = Self; + type BuilderFn = fn(&str) -> glib::ParamSpecFlagsBuilder<Self>; + + fn param_spec_builder() -> Self::BuilderFn { + Self::ParamSpec::builder + } +} + +impl glib::value::ValueType for ItemCreateFlags { + type Type = Self; +} + +unsafe impl<'a> glib::value::FromValue<'a> for ItemCreateFlags { + type Checker = glib::value::GenericValueTypeChecker<Self>; + + #[inline] + unsafe fn from_value(value: &'a glib::Value) -> Self { + from_glib(glib::gobject_ffi::g_value_get_flags(value.to_glib_none().0)) + } +} + +impl ToValue for ItemCreateFlags { + #[inline] + fn to_value(&self) -> glib::Value { + let mut value = glib::Value::for_value_type::<Self>(); + unsafe { + glib::gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, self.into_glib()); + } + value + } + + #[inline] + fn value_type(&self) -> glib::Type { + Self::static_type() + } +} + +impl From<ItemCreateFlags> for glib::Value { + #[inline] + fn from(v: ItemCreateFlags) -> Self { + ToValue::to_value(&v) + } +} + +bitflags! { + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] + #[doc(alias = "SecretItemFlags")] + pub struct ItemFlags: u32 { + #[doc(alias = "SECRET_ITEM_NONE")] + const NONE = ffi::SECRET_ITEM_NONE as _; + #[doc(alias = "SECRET_ITEM_LOAD_SECRET")] + const LOAD_SECRET = ffi::SECRET_ITEM_LOAD_SECRET as _; + } +} + +#[doc(hidden)] +impl IntoGlib for ItemFlags { + type GlibType = ffi::SecretItemFlags; + + #[inline] + fn into_glib(self) -> ffi::SecretItemFlags { + self.bits() + } +} + +#[doc(hidden)] +impl FromGlib<ffi::SecretItemFlags> for ItemFlags { + #[inline] + unsafe fn from_glib(value: ffi::SecretItemFlags) -> Self { + Self::from_bits_truncate(value) + } +} + +impl StaticType for ItemFlags { + #[inline] + #[doc(alias = "secret_item_flags_get_type")] + fn static_type() -> glib::Type { + unsafe { from_glib(ffi::secret_item_flags_get_type()) } + } +} + +impl glib::HasParamSpec for ItemFlags { + type ParamSpec = glib::ParamSpecFlags; + type SetValue = Self; + type BuilderFn = fn(&str) -> glib::ParamSpecFlagsBuilder<Self>; + + fn param_spec_builder() -> Self::BuilderFn { + Self::ParamSpec::builder + } +} + +impl glib::value::ValueType for ItemFlags { + type Type = Self; +} + +unsafe impl<'a> glib::value::FromValue<'a> for ItemFlags { + type Checker = glib::value::GenericValueTypeChecker<Self>; + + #[inline] + unsafe fn from_value(value: &'a glib::Value) -> Self { + from_glib(glib::gobject_ffi::g_value_get_flags(value.to_glib_none().0)) + } +} + +impl ToValue for ItemFlags { + #[inline] + fn to_value(&self) -> glib::Value { + let mut value = glib::Value::for_value_type::<Self>(); + unsafe { + glib::gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, self.into_glib()); + } + value + } + + #[inline] + fn value_type(&self) -> glib::Type { + Self::static_type() + } +} + +impl From<ItemFlags> for glib::Value { + #[inline] + fn from(v: ItemFlags) -> Self { + ToValue::to_value(&v) + } +} + +bitflags! { + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] + #[doc(alias = "SecretSchemaFlags")] + pub struct SchemaFlags: u32 { + #[doc(alias = "SECRET_SCHEMA_NONE")] + const NONE = ffi::SECRET_SCHEMA_NONE as _; + #[doc(alias = "SECRET_SCHEMA_DONT_MATCH_NAME")] + const DONT_MATCH_NAME = ffi::SECRET_SCHEMA_DONT_MATCH_NAME as _; + } +} + +#[doc(hidden)] +impl IntoGlib for SchemaFlags { + type GlibType = ffi::SecretSchemaFlags; + + #[inline] + fn into_glib(self) -> ffi::SecretSchemaFlags { + self.bits() + } +} + +#[doc(hidden)] +impl FromGlib<ffi::SecretSchemaFlags> for SchemaFlags { + #[inline] + unsafe fn from_glib(value: ffi::SecretSchemaFlags) -> Self { + Self::from_bits_truncate(value) + } +} + +impl StaticType for SchemaFlags { + #[inline] + #[doc(alias = "secret_schema_flags_get_type")] + fn static_type() -> glib::Type { + unsafe { from_glib(ffi::secret_schema_flags_get_type()) } + } +} + +impl glib::HasParamSpec for SchemaFlags { + type ParamSpec = glib::ParamSpecFlags; + type SetValue = Self; + type BuilderFn = fn(&str) -> glib::ParamSpecFlagsBuilder<Self>; + + fn param_spec_builder() -> Self::BuilderFn { + Self::ParamSpec::builder + } +} + +impl glib::value::ValueType for SchemaFlags { + type Type = Self; +} + +unsafe impl<'a> glib::value::FromValue<'a> for SchemaFlags { + type Checker = glib::value::GenericValueTypeChecker<Self>; + + #[inline] + unsafe fn from_value(value: &'a glib::Value) -> Self { + from_glib(glib::gobject_ffi::g_value_get_flags(value.to_glib_none().0)) + } +} + +impl ToValue for SchemaFlags { + #[inline] + fn to_value(&self) -> glib::Value { + let mut value = glib::Value::for_value_type::<Self>(); + unsafe { + glib::gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, self.into_glib()); + } + value + } + + #[inline] + fn value_type(&self) -> glib::Type { + Self::static_type() + } +} + +impl From<SchemaFlags> for glib::Value { + #[inline] + fn from(v: SchemaFlags) -> Self { + ToValue::to_value(&v) + } +} + +bitflags! { + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] + #[doc(alias = "SecretSearchFlags")] + pub struct SearchFlags: u32 { + #[doc(alias = "SECRET_SEARCH_NONE")] + const NONE = ffi::SECRET_SEARCH_NONE as _; + #[doc(alias = "SECRET_SEARCH_ALL")] + const ALL = ffi::SECRET_SEARCH_ALL as _; + #[doc(alias = "SECRET_SEARCH_UNLOCK")] + const UNLOCK = ffi::SECRET_SEARCH_UNLOCK as _; + #[doc(alias = "SECRET_SEARCH_LOAD_SECRETS")] + const LOAD_SECRETS = ffi::SECRET_SEARCH_LOAD_SECRETS as _; + } +} + +#[doc(hidden)] +impl IntoGlib for SearchFlags { + type GlibType = ffi::SecretSearchFlags; + + #[inline] + fn into_glib(self) -> ffi::SecretSearchFlags { + self.bits() + } +} + +#[doc(hidden)] +impl FromGlib<ffi::SecretSearchFlags> for SearchFlags { + #[inline] + unsafe fn from_glib(value: ffi::SecretSearchFlags) -> Self { + Self::from_bits_truncate(value) + } +} + +impl StaticType for SearchFlags { + #[inline] + #[doc(alias = "secret_search_flags_get_type")] + fn static_type() -> glib::Type { + unsafe { from_glib(ffi::secret_search_flags_get_type()) } + } +} + +impl glib::HasParamSpec for SearchFlags { + type ParamSpec = glib::ParamSpecFlags; + type SetValue = Self; + type BuilderFn = fn(&str) -> glib::ParamSpecFlagsBuilder<Self>; + + fn param_spec_builder() -> Self::BuilderFn { + Self::ParamSpec::builder + } +} + +impl glib::value::ValueType for SearchFlags { + type Type = Self; +} + +unsafe impl<'a> glib::value::FromValue<'a> for SearchFlags { + type Checker = glib::value::GenericValueTypeChecker<Self>; + + #[inline] + unsafe fn from_value(value: &'a glib::Value) -> Self { + from_glib(glib::gobject_ffi::g_value_get_flags(value.to_glib_none().0)) + } +} + +impl ToValue for SearchFlags { + #[inline] + fn to_value(&self) -> glib::Value { + let mut value = glib::Value::for_value_type::<Self>(); + unsafe { + glib::gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, self.into_glib()); + } + value + } + + #[inline] + fn value_type(&self) -> glib::Type { + Self::static_type() + } +} + +impl From<SearchFlags> for glib::Value { + #[inline] + fn from(v: SearchFlags) -> Self { + ToValue::to_value(&v) + } +} + +bitflags! { + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] + #[doc(alias = "SecretServiceFlags")] + pub struct ServiceFlags: u32 { + #[doc(alias = "SECRET_SERVICE_NONE")] + const NONE = ffi::SECRET_SERVICE_NONE as _; + #[doc(alias = "SECRET_SERVICE_OPEN_SESSION")] + const OPEN_SESSION = ffi::SECRET_SERVICE_OPEN_SESSION as _; + #[doc(alias = "SECRET_SERVICE_LOAD_COLLECTIONS")] + const LOAD_COLLECTIONS = ffi::SECRET_SERVICE_LOAD_COLLECTIONS as _; + } +} + +#[doc(hidden)] +impl IntoGlib for ServiceFlags { + type GlibType = ffi::SecretServiceFlags; + + #[inline] + fn into_glib(self) -> ffi::SecretServiceFlags { + self.bits() + } +} + +#[doc(hidden)] +impl FromGlib<ffi::SecretServiceFlags> for ServiceFlags { + #[inline] + unsafe fn from_glib(value: ffi::SecretServiceFlags) -> Self { + Self::from_bits_truncate(value) + } +} + +impl StaticType for ServiceFlags { + #[inline] + #[doc(alias = "secret_service_flags_get_type")] + fn static_type() -> glib::Type { + unsafe { from_glib(ffi::secret_service_flags_get_type()) } + } +} + +impl glib::HasParamSpec for ServiceFlags { + type ParamSpec = glib::ParamSpecFlags; + type SetValue = Self; + type BuilderFn = fn(&str) -> glib::ParamSpecFlagsBuilder<Self>; + + fn param_spec_builder() -> Self::BuilderFn { + Self::ParamSpec::builder + } +} + +impl glib::value::ValueType for ServiceFlags { + type Type = Self; +} + +unsafe impl<'a> glib::value::FromValue<'a> for ServiceFlags { + type Checker = glib::value::GenericValueTypeChecker<Self>; + + #[inline] + unsafe fn from_value(value: &'a glib::Value) -> Self { + from_glib(glib::gobject_ffi::g_value_get_flags(value.to_glib_none().0)) + } +} + +impl ToValue for ServiceFlags { + #[inline] + fn to_value(&self) -> glib::Value { + let mut value = glib::Value::for_value_type::<Self>(); + unsafe { + glib::gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, self.into_glib()); + } + value + } + + #[inline] + fn value_type(&self) -> glib::Type { + Self::static_type() + } +} + +impl From<ServiceFlags> for glib::Value { + #[inline] + fn from(v: ServiceFlags) -> Self { + ToValue::to_value(&v) + } +} diff --git a/libsecret/src/auto/functions.rs b/libsecret/src/auto/functions.rs new file mode 100644 index 0000000..173139f --- /dev/null +++ b/libsecret/src/auto/functions.rs @@ -0,0 +1,41 @@ +// This file was generated by gir (https://github.com/gtk-rs/gir) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git) +// DO NOT EDIT + +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +use crate::{Retrievable, Value}; +#[cfg(feature = "v0_18_6")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))] +use crate::{Schema, SchemaType}; +use glib::{prelude::*, translate::*}; + +//#[cfg(feature = "v0_21_2")] +//#[cfg_attr(docsrs, doc(cfg(feature = "v0_21_2")))] +//#[doc(alias = "secret_attributes_validate")] +//pub fn attributes_validate(schema: &Schema, attributes: /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 25 }/TypeId { ns_id: 0, id: 25 }) -> Result<(), glib::Error> { +// unsafe { TODO: call ffi:secret_attributes_validate() } +//} + +#[cfg(feature = "v0_18_6")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))] +#[doc(alias = "secret_get_schema")] +#[doc(alias = "get_schema")] +pub fn schema(type_: SchemaType) -> Schema { + unsafe { from_glib_none(ffi::secret_get_schema(type_.into_glib())) } +} + +#[doc(alias = "secret_password_free")] +pub fn password_free(password: Option<&str>) { + unsafe { + ffi::secret_password_free(password.to_glib_none().0); + } +} + +#[doc(alias = "secret_password_wipe")] +pub fn password_wipe(password: Option<&str>) { + unsafe { + ffi::secret_password_wipe(password.to_glib_none().0); + } +} diff --git a/libsecret/src/auto/item.rs b/libsecret/src/auto/item.rs new file mode 100644 index 0000000..5fb03e6 --- /dev/null +++ b/libsecret/src/auto/item.rs @@ -0,0 +1,556 @@ +// This file was generated by gir (https://github.com/gtk-rs/gir) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git) +// DO NOT EDIT + +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +use crate::Retrievable; +use crate::{ItemFlags, Service, Value}; +use glib::{ + prelude::*, + signal::{connect_raw, SignalHandlerId}, + translate::*, +}; +use std::{boxed::Box as Box_, pin::Pin}; + +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +glib::wrapper! { + #[doc(alias = "SecretItem")] + pub struct Item(Object<ffi::SecretItem, ffi::SecretItemClass>) @extends gio::DBusProxy, @implements gio::DBusInterface, gio::Initable, Retrievable; + + match fn { + type_ => || ffi::secret_item_get_type(), + } +} + +#[cfg(not(any(feature = "v0_19")))] +glib::wrapper! { + #[doc(alias = "SecretItem")] + pub struct Item(Object<ffi::SecretItem, ffi::SecretItemClass>) @extends gio::DBusProxy, @implements gio::DBusInterface, gio::Initable; + + match fn { + type_ => || ffi::secret_item_get_type(), + } +} + +impl Item { + pub const NONE: Option<&'static Item> = None; + + #[doc(alias = "secret_item_new_for_dbus_path_sync")] + #[doc(alias = "new_for_dbus_path_sync")] + pub fn for_dbus_path_sync( + service: Option<&impl IsA<Service>>, + item_path: &str, + flags: ItemFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<Item, glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_item_new_for_dbus_path_sync( + service.map(|p| p.as_ref()).to_glib_none().0, + item_path.to_glib_none().0, + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "secret_item_new_for_dbus_path")] + pub fn new_for_dbus_path<P: FnOnce(Result<Item, glib::Error>) + 'static>( + service: Option<&impl IsA<Service>>, + item_path: &str, + flags: ItemFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn new_for_dbus_path_trampoline< + P: FnOnce(Result<Item, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_item_new_for_dbus_path_finish(res, &mut error); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = new_for_dbus_path_trampoline::<P>; + unsafe { + ffi::secret_item_new_for_dbus_path( + service.map(|p| p.as_ref()).to_glib_none().0, + item_path.to_glib_none().0, + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + pub fn new_for_dbus_path_future( + service: Option<&(impl IsA<Service> + Clone + 'static)>, + item_path: &str, + flags: ItemFlags, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<Item, glib::Error>> + 'static>> { + let service = service.map(ToOwned::to_owned); + let item_path = String::from(item_path); + Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| { + Self::new_for_dbus_path( + service.as_ref().map(::std::borrow::Borrow::borrow), + &item_path, + flags, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } +} + +mod sealed { + pub trait Sealed {} + impl<T: super::IsA<super::Item>> Sealed for T {} +} + +pub trait ItemExt: IsA<Item> + sealed::Sealed + 'static { + #[doc(alias = "secret_item_delete")] + fn delete<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn delete_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let _ = ffi::secret_item_delete_finish(_source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = delete_trampoline::<P>; + unsafe { + ffi::secret_item_delete( + self.as_ref().to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn delete_future( + &self, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.delete(Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + #[doc(alias = "secret_item_delete_sync")] + fn delete_sync( + &self, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<(), glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let is_ok = ffi::secret_item_delete_sync( + self.as_ref().to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); + if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + } + } + } + + #[cfg(not(feature = "v0_19"))] + #[cfg_attr(docsrs, doc(cfg(not(feature = "v0_19"))))] + #[doc(alias = "secret_item_get_created")] + #[doc(alias = "get_created")] + fn created(&self) -> u64 { + unsafe { ffi::secret_item_get_created(self.as_ref().to_glib_none().0) } + } + + #[doc(alias = "secret_item_get_flags")] + #[doc(alias = "get_flags")] + fn flags(&self) -> ItemFlags { + unsafe { from_glib(ffi::secret_item_get_flags(self.as_ref().to_glib_none().0)) } + } + + #[cfg(not(feature = "v0_19"))] + #[cfg_attr(docsrs, doc(cfg(not(feature = "v0_19"))))] + #[doc(alias = "secret_item_get_label")] + #[doc(alias = "get_label")] + fn label(&self) -> glib::GString { + unsafe { from_glib_full(ffi::secret_item_get_label(self.as_ref().to_glib_none().0)) } + } + + #[doc(alias = "secret_item_get_locked")] + #[doc(alias = "get_locked")] + fn is_locked(&self) -> bool { + unsafe { from_glib(ffi::secret_item_get_locked(self.as_ref().to_glib_none().0)) } + } + + #[cfg(not(feature = "v0_19"))] + #[cfg_attr(docsrs, doc(cfg(not(feature = "v0_19"))))] + #[doc(alias = "secret_item_get_modified")] + #[doc(alias = "get_modified")] + fn modified(&self) -> u64 { + unsafe { ffi::secret_item_get_modified(self.as_ref().to_glib_none().0) } + } + + #[doc(alias = "secret_item_get_schema_name")] + #[doc(alias = "get_schema_name")] + fn schema_name(&self) -> Option<glib::GString> { + unsafe { + from_glib_full(ffi::secret_item_get_schema_name( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "secret_item_get_secret")] + #[doc(alias = "get_secret")] + fn secret(&self) -> Option<Value> { + unsafe { from_glib_full(ffi::secret_item_get_secret(self.as_ref().to_glib_none().0)) } + } + + #[doc(alias = "secret_item_get_service")] + #[doc(alias = "get_service")] + fn service(&self) -> Service { + unsafe { from_glib_none(ffi::secret_item_get_service(self.as_ref().to_glib_none().0)) } + } + + #[doc(alias = "secret_item_load_secret")] + fn load_secret<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn load_secret_trampoline< + P: FnOnce(Result<(), glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let _ = ffi::secret_item_load_secret_finish(_source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = load_secret_trampoline::<P>; + unsafe { + ffi::secret_item_load_secret( + self.as_ref().to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn load_secret_future( + &self, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.load_secret(Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + #[doc(alias = "secret_item_load_secret_sync")] + fn load_secret_sync( + &self, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<(), glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let is_ok = ffi::secret_item_load_secret_sync( + self.as_ref().to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); + if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "secret_item_refresh")] + fn refresh(&self) { + unsafe { + ffi::secret_item_refresh(self.as_ref().to_glib_none().0); + } + } + + #[doc(alias = "secret_item_set_label")] + fn set_label<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + label: &str, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn set_label_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let _ = ffi::secret_item_set_label_finish(_source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = set_label_trampoline::<P>; + unsafe { + ffi::secret_item_set_label( + self.as_ref().to_glib_none().0, + label.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn set_label_future( + &self, + label: &str, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { + let label = String::from(label); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.set_label(&label, Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + #[doc(alias = "secret_item_set_label_sync")] + fn set_label_sync( + &self, + label: &str, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<(), glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let is_ok = ffi::secret_item_set_label_sync( + self.as_ref().to_glib_none().0, + label.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); + if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "secret_item_set_secret")] + fn set_secret<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + value: &Value, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn set_secret_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let _ = ffi::secret_item_set_secret_finish(_source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = set_secret_trampoline::<P>; + unsafe { + ffi::secret_item_set_secret( + self.as_ref().to_glib_none().0, + value.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn set_secret_future( + &self, + value: &Value, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { + let value = value.clone(); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.set_secret(&value, Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + #[doc(alias = "secret_item_set_secret_sync")] + fn set_secret_sync( + &self, + value: &Value, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<(), glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let is_ok = ffi::secret_item_set_secret_sync( + self.as_ref().to_glib_none().0, + value.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); + if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "locked")] + fn connect_locked_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { + unsafe extern "C" fn notify_locked_trampoline<P: IsA<Item>, F: Fn(&P) + 'static>( + this: *mut ffi::SecretItem, + _param_spec: glib::ffi::gpointer, + f: glib::ffi::gpointer, + ) { + let f: &F = &*(f as *const F); + f(Item::from_glib_borrow(this).unsafe_cast_ref()) + } + unsafe { + let f: Box_<F> = Box_::new(f); + connect_raw( + self.as_ptr() as *mut _, + b"notify::locked\0".as_ptr() as *const _, + Some(std::mem::transmute::<_, unsafe extern "C" fn()>( + notify_locked_trampoline::<Self, F> as *const (), + )), + Box_::into_raw(f), + ) + } + } +} + +impl<O: IsA<Item>> ItemExt for O {} diff --git a/libsecret/src/auto/mod.rs b/libsecret/src/auto/mod.rs new file mode 100644 index 0000000..a8d7346 --- /dev/null +++ b/libsecret/src/auto/mod.rs @@ -0,0 +1,75 @@ +// This file was generated by gir (https://github.com/gtk-rs/gir) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git) +// DO NOT EDIT + +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +mod backend; +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +pub use self::backend::Backend; + +mod collection; +pub use self::collection::Collection; + +mod item; +pub use self::item::Item; + +mod prompt; +pub use self::prompt::Prompt; + +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +mod retrievable; +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +pub use self::retrievable::Retrievable; + +mod service; +pub use self::service::Service; + +mod schema; +pub use self::schema::Schema; + +mod schema_attribute; +pub use self::schema_attribute::SchemaAttribute; + +mod enums; +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +pub use self::enums::BackendFlags; +pub use self::enums::Error; +pub use self::enums::SchemaAttributeType; +#[cfg(feature = "v0_18_6")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))] +pub use self::enums::SchemaType; + +mod flags; +pub use self::flags::CollectionCreateFlags; +pub use self::flags::CollectionFlags; +pub use self::flags::ItemCreateFlags; +pub use self::flags::ItemFlags; +pub use self::flags::SchemaFlags; +pub use self::flags::SearchFlags; +pub use self::flags::ServiceFlags; + +pub(crate) mod functions; + +mod constants; +pub use self::constants::BACKEND_EXTENSION_POINT_NAME; +pub use self::constants::COLLECTION_DEFAULT; +pub use self::constants::COLLECTION_SESSION; + +pub(crate) mod traits { + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub use super::backend::BackendExt; + pub use super::collection::CollectionExt; + pub use super::item::ItemExt; + pub use super::prompt::PromptExt; + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub use super::retrievable::RetrievableExt; + pub use super::service::ServiceExt; +} diff --git a/libsecret/src/auto/prompt.rs b/libsecret/src/auto/prompt.rs new file mode 100644 index 0000000..245f68a --- /dev/null +++ b/libsecret/src/auto/prompt.rs @@ -0,0 +1,76 @@ +// This file was generated by gir (https://github.com/gtk-rs/gir) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git) +// DO NOT EDIT + +use glib::{prelude::*, translate::*}; + +glib::wrapper! { + #[doc(alias = "SecretPrompt")] + pub struct Prompt(Object<ffi::SecretPrompt, ffi::SecretPromptClass>) @extends gio::DBusProxy, @implements gio::DBusInterface, gio::Initable; + + match fn { + type_ => || ffi::secret_prompt_get_type(), + } +} + +impl Prompt { + pub const NONE: Option<&'static Prompt> = None; +} + +mod sealed { + pub trait Sealed {} + impl<T: super::IsA<super::Prompt>> Sealed for T {} +} + +pub trait PromptExt: IsA<Prompt> + sealed::Sealed + 'static { + #[doc(alias = "secret_prompt_perform_sync")] + fn perform_sync( + &self, + window_id: Option<&str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + return_type: &glib::VariantTy, + ) -> Result<glib::Variant, glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_prompt_perform_sync( + self.as_ref().to_glib_none().0, + window_id.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + return_type.to_glib_none().0, + &mut error, + ); + if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "secret_prompt_run")] + fn run( + &self, + window_id: Option<&str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + return_type: &glib::VariantTy, + ) -> Result<glib::Variant, glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_prompt_run( + self.as_ref().to_glib_none().0, + window_id.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + return_type.to_glib_none().0, + &mut error, + ); + if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + } + } + } +} + +impl<O: IsA<Prompt>> PromptExt for O {} diff --git a/libsecret/src/auto/retrievable.rs b/libsecret/src/auto/retrievable.rs new file mode 100644 index 0000000..14ab08f --- /dev/null +++ b/libsecret/src/auto/retrievable.rs @@ -0,0 +1,269 @@ +// This file was generated by gir (https://github.com/gtk-rs/gir) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git) +// DO NOT EDIT + +use crate::Value; +use glib::{ + prelude::*, + signal::{connect_raw, SignalHandlerId}, + translate::*, +}; +use std::{boxed::Box as Box_, pin::Pin}; + +glib::wrapper! { + #[doc(alias = "SecretRetrievable")] + pub struct Retrievable(Interface<ffi::SecretRetrievable, ffi::SecretRetrievableInterface>); + + match fn { + type_ => || ffi::secret_retrievable_get_type(), + } +} + +impl Retrievable { + pub const NONE: Option<&'static Retrievable> = None; +} + +mod sealed { + pub trait Sealed {} + impl<T: super::IsA<super::Retrievable>> Sealed for T {} +} + +pub trait RetrievableExt: IsA<Retrievable> + sealed::Sealed + 'static { + #[doc(alias = "secret_retrievable_get_created")] + #[doc(alias = "get_created")] + fn created(&self) -> u64 { + unsafe { ffi::secret_retrievable_get_created(self.as_ref().to_glib_none().0) } + } + + #[doc(alias = "secret_retrievable_get_label")] + #[doc(alias = "get_label")] + fn label(&self) -> glib::GString { + unsafe { + from_glib_full(ffi::secret_retrievable_get_label( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "secret_retrievable_get_modified")] + #[doc(alias = "get_modified")] + fn modified(&self) -> u64 { + unsafe { ffi::secret_retrievable_get_modified(self.as_ref().to_glib_none().0) } + } + + #[doc(alias = "secret_retrievable_retrieve_secret")] + fn retrieve_secret<P: FnOnce(Result<Option<Value>, glib::Error>) + 'static>( + &self, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn retrieve_secret_trampoline< + P: FnOnce(Result<Option<Value>, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_retrievable_retrieve_secret_finish( + _source_object as *mut _, + res, + &mut error, + ); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = retrieve_secret_trampoline::<P>; + unsafe { + ffi::secret_retrievable_retrieve_secret( + self.as_ref().to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn retrieve_secret_future( + &self, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<Option<Value>, glib::Error>> + 'static>> + { + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.retrieve_secret(Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + #[doc(alias = "secret_retrievable_retrieve_secret_sync")] + fn retrieve_secret_sync( + &self, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<Option<Value>, glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_retrievable_retrieve_secret_sync( + self.as_ref().to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + } + } + } + + //#[cfg(feature = "v0_19")] + //#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + //fn set_attributes(&self, attributes: /*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 }) { + // ObjectExt::set_property(self.as_ref(),"attributes", attributes) + //} + + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + fn set_created(&self, created: u64) { + ObjectExt::set_property(self.as_ref(), "created", created) + } + + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + fn set_label(&self, label: Option<&str>) { + ObjectExt::set_property(self.as_ref(), "label", label) + } + + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + fn set_modified(&self, modified: u64) { + ObjectExt::set_property(self.as_ref(), "modified", modified) + } + + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + #[doc(alias = "attributes")] + fn connect_attributes_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { + unsafe extern "C" fn notify_attributes_trampoline< + P: IsA<Retrievable>, + F: Fn(&P) + 'static, + >( + this: *mut ffi::SecretRetrievable, + _param_spec: glib::ffi::gpointer, + f: glib::ffi::gpointer, + ) { + let f: &F = &*(f as *const F); + f(Retrievable::from_glib_borrow(this).unsafe_cast_ref()) + } + unsafe { + let f: Box_<F> = Box_::new(f); + connect_raw( + self.as_ptr() as *mut _, + b"notify::attributes\0".as_ptr() as *const _, + Some(std::mem::transmute::<_, unsafe extern "C" fn()>( + notify_attributes_trampoline::<Self, F> as *const (), + )), + Box_::into_raw(f), + ) + } + } + + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + #[doc(alias = "created")] + fn connect_created_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { + unsafe extern "C" fn notify_created_trampoline<P: IsA<Retrievable>, F: Fn(&P) + 'static>( + this: *mut ffi::SecretRetrievable, + _param_spec: glib::ffi::gpointer, + f: glib::ffi::gpointer, + ) { + let f: &F = &*(f as *const F); + f(Retrievable::from_glib_borrow(this).unsafe_cast_ref()) + } + unsafe { + let f: Box_<F> = Box_::new(f); + connect_raw( + self.as_ptr() as *mut _, + b"notify::created\0".as_ptr() as *const _, + Some(std::mem::transmute::<_, unsafe extern "C" fn()>( + notify_created_trampoline::<Self, F> as *const (), + )), + Box_::into_raw(f), + ) + } + } + + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + #[doc(alias = "label")] + fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { + unsafe extern "C" fn notify_label_trampoline<P: IsA<Retrievable>, F: Fn(&P) + 'static>( + this: *mut ffi::SecretRetrievable, + _param_spec: glib::ffi::gpointer, + f: glib::ffi::gpointer, + ) { + let f: &F = &*(f as *const F); + f(Retrievable::from_glib_borrow(this).unsafe_cast_ref()) + } + unsafe { + let f: Box_<F> = Box_::new(f); + connect_raw( + self.as_ptr() as *mut _, + b"notify::label\0".as_ptr() as *const _, + Some(std::mem::transmute::<_, unsafe extern "C" fn()>( + notify_label_trampoline::<Self, F> as *const (), + )), + Box_::into_raw(f), + ) + } + } + + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + #[doc(alias = "modified")] + fn connect_modified_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { + unsafe extern "C" fn notify_modified_trampoline< + P: IsA<Retrievable>, + F: Fn(&P) + 'static, + >( + this: *mut ffi::SecretRetrievable, + _param_spec: glib::ffi::gpointer, + f: glib::ffi::gpointer, + ) { + let f: &F = &*(f as *const F); + f(Retrievable::from_glib_borrow(this).unsafe_cast_ref()) + } + unsafe { + let f: Box_<F> = Box_::new(f); + connect_raw( + self.as_ptr() as *mut _, + b"notify::modified\0".as_ptr() as *const _, + Some(std::mem::transmute::<_, unsafe extern "C" fn()>( + notify_modified_trampoline::<Self, F> as *const (), + )), + Box_::into_raw(f), + ) + } + } +} + +impl<O: IsA<Retrievable>> RetrievableExt for O {} diff --git a/libsecret/src/auto/schema.rs b/libsecret/src/auto/schema.rs new file mode 100644 index 0000000..9889b31 --- /dev/null +++ b/libsecret/src/auto/schema.rs @@ -0,0 +1,15 @@ +// This file was generated by gir (https://github.com/gtk-rs/gir) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git) +// DO NOT EDIT + +glib::wrapper! { + #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] + pub struct Schema(Shared<ffi::SecretSchema>); + + match fn { + ref => |ptr| ffi::secret_schema_ref(ptr), + unref => |ptr| ffi::secret_schema_unref(ptr), + type_ => || ffi::secret_schema_get_type(), + } +} diff --git a/libsecret/src/auto/schema_attribute.rs b/libsecret/src/auto/schema_attribute.rs new file mode 100644 index 0000000..be20632 --- /dev/null +++ b/libsecret/src/auto/schema_attribute.rs @@ -0,0 +1,15 @@ +// This file was generated by gir (https://github.com/gtk-rs/gir) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git) +// DO NOT EDIT + +glib::wrapper! { + #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] + pub struct SchemaAttribute(Boxed<ffi::SecretSchemaAttribute>); + + match fn { + copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::secret_schema_attribute_get_type(), ptr as *mut _) as *mut ffi::SecretSchemaAttribute, + free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::secret_schema_attribute_get_type(), ptr as *mut _), + type_ => || ffi::secret_schema_attribute_get_type(), + } +} diff --git a/libsecret/src/auto/service.rs b/libsecret/src/auto/service.rs new file mode 100644 index 0000000..b4882b3 --- /dev/null +++ b/libsecret/src/auto/service.rs @@ -0,0 +1,1208 @@ +// This file was generated by gir (https://github.com/gtk-rs/gir) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git) +// DO NOT EDIT + +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +use crate::Backend; +use crate::{Collection, Item, Prompt, ServiceFlags, Value}; +use glib::{prelude::*, translate::*}; +use std::{boxed::Box as Box_, pin::Pin}; + +#[cfg(feature = "v0_19")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] +glib::wrapper! { + #[doc(alias = "SecretService")] + pub struct Service(Object<ffi::SecretService, ffi::SecretServiceClass>) @extends gio::DBusProxy, @implements gio::DBusInterface, gio::Initable, Backend; + + match fn { + type_ => || ffi::secret_service_get_type(), + } +} + +#[cfg(not(any(feature = "v0_19")))] +glib::wrapper! { + #[doc(alias = "SecretService")] + pub struct Service(Object<ffi::SecretService, ffi::SecretServiceClass>) @extends gio::DBusProxy, @implements gio::DBusInterface, gio::Initable; + + match fn { + type_ => || ffi::secret_service_get_type(), + } +} + +impl Service { + pub const NONE: Option<&'static Service> = None; + + #[doc(alias = "secret_service_disconnect")] + pub fn disconnect() { + unsafe { + ffi::secret_service_disconnect(); + } + } + + #[doc(alias = "secret_service_get")] + pub fn get<P: FnOnce(Result<Service, glib::Error>) + 'static>( + flags: ServiceFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn get_trampoline<P: FnOnce(Result<Service, glib::Error>) + 'static>( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_service_get_finish(res, &mut error); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = get_trampoline::<P>; + unsafe { + ffi::secret_service_get( + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + pub fn get_future( + flags: ServiceFlags, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<Service, glib::Error>> + 'static>> { + Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| { + Self::get(flags, Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + #[doc(alias = "secret_service_get_sync")] + #[doc(alias = "get_sync")] + pub fn sync( + flags: ServiceFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<Service, glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_service_get_sync( + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "secret_service_open")] + pub fn open<P: FnOnce(Result<Service, glib::Error>) + 'static>( + service_gtype: glib::types::Type, + service_bus_name: Option<&str>, + flags: ServiceFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn open_trampoline<P: FnOnce(Result<Service, glib::Error>) + 'static>( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_service_open_finish(res, &mut error); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = open_trampoline::<P>; + unsafe { + ffi::secret_service_open( + service_gtype.into_glib(), + service_bus_name.to_glib_none().0, + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + pub fn open_future( + service_gtype: glib::types::Type, + service_bus_name: Option<&str>, + flags: ServiceFlags, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<Service, glib::Error>> + 'static>> { + let service_bus_name = service_bus_name.map(ToOwned::to_owned); + Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| { + Self::open( + service_gtype, + service_bus_name.as_ref().map(::std::borrow::Borrow::borrow), + flags, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + #[doc(alias = "secret_service_open_sync")] + pub fn open_sync( + service_gtype: glib::types::Type, + service_bus_name: Option<&str>, + flags: ServiceFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<Service, glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_service_open_sync( + service_gtype.into_glib(), + service_bus_name.to_glib_none().0, + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + } + } + } +} + +mod sealed { + pub trait Sealed {} + impl<T: super::IsA<super::Service>> Sealed for T {} +} + +pub trait ServiceExt: IsA<Service> + sealed::Sealed + 'static { + //#[doc(alias = "secret_service_clear_sync")] + //fn clear_sync(&self, schema: Option<&Schema>, attributes: /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 }, cancellable: Option<&impl IsA<gio::Cancellable>>) -> Result<(), glib::Error> { + // unsafe { TODO: call ffi:secret_service_clear_sync() } + //} + + //#[doc(alias = "secret_service_create_collection_dbus_path_sync")] + //fn create_collection_dbus_path_sync(&self, properties: /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 2, id: 222 }, alias: Option<&str>, flags: CollectionCreateFlags, cancellable: Option<&impl IsA<gio::Cancellable>>) -> Result<glib::GString, glib::Error> { + // unsafe { TODO: call ffi:secret_service_create_collection_dbus_path_sync() } + //} + + //#[doc(alias = "secret_service_create_item_dbus_path_sync")] + //fn create_item_dbus_path_sync(&self, collection_path: &str, properties: /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 2, id: 222 }, value: &Value, flags: ItemCreateFlags, cancellable: Option<&impl IsA<gio::Cancellable>>) -> Result<glib::GString, glib::Error> { + // unsafe { TODO: call ffi:secret_service_create_item_dbus_path_sync() } + //} + + #[doc(alias = "secret_service_decode_dbus_secret")] + fn decode_dbus_secret(&self, value: &glib::Variant) -> Value { + unsafe { + from_glib_full(ffi::secret_service_decode_dbus_secret( + self.as_ref().to_glib_none().0, + value.to_glib_none().0, + )) + } + } + + #[doc(alias = "secret_service_delete_item_dbus_path")] + fn delete_item_dbus_path<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + item_path: &str, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn delete_item_dbus_path_trampoline< + P: FnOnce(Result<(), glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let _ = ffi::secret_service_delete_item_dbus_path_finish( + _source_object as *mut _, + res, + &mut error, + ); + let result = if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = delete_item_dbus_path_trampoline::<P>; + unsafe { + ffi::secret_service_delete_item_dbus_path( + self.as_ref().to_glib_none().0, + item_path.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn delete_item_dbus_path_future( + &self, + item_path: &str, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { + let item_path = String::from(item_path); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.delete_item_dbus_path(&item_path, Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + #[doc(alias = "secret_service_delete_item_dbus_path_sync")] + fn delete_item_dbus_path_sync( + &self, + item_path: &str, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<(), glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let is_ok = ffi::secret_service_delete_item_dbus_path_sync( + self.as_ref().to_glib_none().0, + item_path.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); + if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "secret_service_encode_dbus_secret")] + fn encode_dbus_secret(&self, value: &Value) -> glib::Variant { + unsafe { + from_glib_none(ffi::secret_service_encode_dbus_secret( + self.as_ref().to_glib_none().0, + value.to_glib_none().0, + )) + } + } + + #[doc(alias = "secret_service_ensure_session")] + fn ensure_session<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn ensure_session_trampoline< + P: FnOnce(Result<(), glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let _ = ffi::secret_service_ensure_session_finish( + _source_object as *mut _, + res, + &mut error, + ); + let result = if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = ensure_session_trampoline::<P>; + unsafe { + ffi::secret_service_ensure_session( + self.as_ref().to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn ensure_session_future( + &self, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.ensure_session(Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + #[doc(alias = "secret_service_ensure_session_sync")] + fn ensure_session_sync( + &self, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<(), glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let is_ok = ffi::secret_service_ensure_session_sync( + self.as_ref().to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); + if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "secret_service_get_collection_gtype")] + #[doc(alias = "get_collection_gtype")] + fn collection_gtype(&self) -> glib::types::Type { + unsafe { + from_glib(ffi::secret_service_get_collection_gtype( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "secret_service_get_collections")] + #[doc(alias = "get_collections")] + fn collections(&self) -> Vec<Collection> { + unsafe { + FromGlibPtrContainer::from_glib_full(ffi::secret_service_get_collections( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "secret_service_get_flags")] + #[doc(alias = "get_flags")] + fn flags(&self) -> ServiceFlags { + unsafe { + from_glib(ffi::secret_service_get_flags( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "secret_service_get_item_gtype")] + #[doc(alias = "get_item_gtype")] + fn item_gtype(&self) -> glib::types::Type { + unsafe { + from_glib(ffi::secret_service_get_item_gtype( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "secret_service_get_secret_for_dbus_path")] + #[doc(alias = "get_secret_for_dbus_path")] + fn secret_for_dbus_path<P: FnOnce(Result<Option<Value>, glib::Error>) + 'static>( + &self, + item_path: &str, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn secret_for_dbus_path_trampoline< + P: FnOnce(Result<Option<Value>, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_service_get_secret_for_dbus_path_finish( + _source_object as *mut _, + res, + &mut error, + ); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = secret_for_dbus_path_trampoline::<P>; + unsafe { + ffi::secret_service_get_secret_for_dbus_path( + self.as_ref().to_glib_none().0, + item_path.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn secret_for_dbus_path_future( + &self, + item_path: &str, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<Option<Value>, glib::Error>> + 'static>> + { + let item_path = String::from(item_path); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.secret_for_dbus_path(&item_path, Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + #[doc(alias = "secret_service_get_secret_for_dbus_path_sync")] + #[doc(alias = "get_secret_for_dbus_path_sync")] + fn secret_for_dbus_path_sync( + &self, + item_path: &str, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<Option<Value>, glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_service_get_secret_for_dbus_path_sync( + self.as_ref().to_glib_none().0, + item_path.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + } + } + } + + //#[doc(alias = "secret_service_get_secrets_for_dbus_paths_sync")] + //#[doc(alias = "get_secrets_for_dbus_paths_sync")] + //fn secrets_for_dbus_paths_sync(&self, item_paths: &str, cancellable: Option<&impl IsA<gio::Cancellable>>) -> Result</*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 1, id: 3 }, glib::Error> { + // unsafe { TODO: call ffi:secret_service_get_secrets_for_dbus_paths_sync() } + //} + + #[doc(alias = "secret_service_get_session_algorithms")] + #[doc(alias = "get_session_algorithms")] + fn session_algorithms(&self) -> Option<glib::GString> { + unsafe { + from_glib_none(ffi::secret_service_get_session_algorithms( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "secret_service_get_session_dbus_path")] + #[doc(alias = "get_session_dbus_path")] + fn session_dbus_path(&self) -> Option<glib::GString> { + unsafe { + from_glib_none(ffi::secret_service_get_session_dbus_path( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "secret_service_load_collections")] + fn load_collections<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn load_collections_trampoline< + P: FnOnce(Result<(), glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let _ = ffi::secret_service_load_collections_finish( + _source_object as *mut _, + res, + &mut error, + ); + let result = if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = load_collections_trampoline::<P>; + unsafe { + ffi::secret_service_load_collections( + self.as_ref().to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn load_collections_future( + &self, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.load_collections(Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + #[doc(alias = "secret_service_load_collections_sync")] + fn load_collections_sync( + &self, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<(), glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let is_ok = ffi::secret_service_load_collections_sync( + self.as_ref().to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); + if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + } + } + } + + //#[doc(alias = "secret_service_lock_sync")] + //fn lock_sync(&self, objects: &[gio::DBusProxy], cancellable: Option<&impl IsA<gio::Cancellable>>, locked: /*Unimplemented*/Vec<gio::DBusProxy>) -> Result<i32, glib::Error> { + // unsafe { TODO: call ffi:secret_service_lock_sync() } + //} + + //#[doc(alias = "secret_service_lookup_sync")] + //fn lookup_sync(&self, schema: Option<&Schema>, attributes: /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 }, cancellable: Option<&impl IsA<gio::Cancellable>>) -> Result<Value, glib::Error> { + // unsafe { TODO: call ffi:secret_service_lookup_sync() } + //} + + #[doc(alias = "secret_service_prompt")] + fn prompt<P: FnOnce(Result<glib::Variant, glib::Error>) + 'static>( + &self, + prompt: &impl IsA<Prompt>, + return_type: Option<&glib::VariantTy>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn prompt_trampoline< + P: FnOnce(Result<glib::Variant, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_service_prompt_finish(_source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = prompt_trampoline::<P>; + unsafe { + ffi::secret_service_prompt( + self.as_ref().to_glib_none().0, + prompt.as_ref().to_glib_none().0, + return_type.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn prompt_future( + &self, + prompt: &(impl IsA<Prompt> + Clone + 'static), + return_type: Option<&glib::VariantTy>, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<glib::Variant, glib::Error>> + 'static>> + { + let prompt = prompt.clone(); + let return_type = return_type.map(ToOwned::to_owned); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.prompt( + &prompt, + return_type.as_ref().map(::std::borrow::Borrow::borrow), + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + #[doc(alias = "secret_service_prompt_at_dbus_path")] + fn prompt_at_dbus_path<P: FnOnce(Result<Option<glib::Variant>, glib::Error>) + 'static>( + &self, + prompt_path: &str, + return_type: Option<&glib::VariantTy>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn prompt_at_dbus_path_trampoline< + P: FnOnce(Result<Option<glib::Variant>, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_service_prompt_at_dbus_path_finish( + _source_object as *mut _, + res, + &mut error, + ); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = prompt_at_dbus_path_trampoline::<P>; + unsafe { + ffi::secret_service_prompt_at_dbus_path( + self.as_ref().to_glib_none().0, + prompt_path.to_glib_none().0, + return_type.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn prompt_at_dbus_path_future( + &self, + prompt_path: &str, + return_type: Option<&glib::VariantTy>, + ) -> Pin< + Box_< + dyn std::future::Future<Output = Result<Option<glib::Variant>, glib::Error>> + 'static, + >, + > { + let prompt_path = String::from(prompt_path); + let return_type = return_type.map(ToOwned::to_owned); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.prompt_at_dbus_path( + &prompt_path, + return_type.as_ref().map(::std::borrow::Borrow::borrow), + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + #[doc(alias = "secret_service_prompt_at_dbus_path_sync")] + fn prompt_at_dbus_path_sync( + &self, + prompt_path: &str, + cancellable: Option<&impl IsA<gio::Cancellable>>, + return_type: Option<&glib::VariantTy>, + ) -> Result<Option<glib::Variant>, glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_service_prompt_at_dbus_path_sync( + self.as_ref().to_glib_none().0, + prompt_path.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + return_type.to_glib_none().0, + &mut error, + ); + if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "secret_service_prompt_sync")] + fn prompt_sync( + &self, + prompt: &impl IsA<Prompt>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + return_type: &glib::VariantTy, + ) -> Result<glib::Variant, glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_service_prompt_sync( + self.as_ref().to_glib_none().0, + prompt.as_ref().to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + return_type.to_glib_none().0, + &mut error, + ); + if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "secret_service_read_alias_dbus_path")] + fn read_alias_dbus_path<P: FnOnce(Result<Option<glib::GString>, glib::Error>) + 'static>( + &self, + alias: &str, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn read_alias_dbus_path_trampoline< + P: FnOnce(Result<Option<glib::GString>, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_service_read_alias_dbus_path_finish( + _source_object as *mut _, + res, + &mut error, + ); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = read_alias_dbus_path_trampoline::<P>; + unsafe { + ffi::secret_service_read_alias_dbus_path( + self.as_ref().to_glib_none().0, + alias.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn read_alias_dbus_path_future( + &self, + alias: &str, + ) -> Pin< + Box_< + dyn std::future::Future<Output = Result<Option<glib::GString>, glib::Error>> + 'static, + >, + > { + let alias = String::from(alias); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.read_alias_dbus_path(&alias, Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + #[doc(alias = "secret_service_read_alias_dbus_path_sync")] + fn read_alias_dbus_path_sync( + &self, + alias: &str, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<Option<glib::GString>, glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_service_read_alias_dbus_path_sync( + self.as_ref().to_glib_none().0, + alias.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + } + } + } + + //#[doc(alias = "secret_service_search_for_dbus_paths_sync")] + //fn search_for_dbus_paths_sync(&self, schema: Option<&Schema>, attributes: /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 }, cancellable: Option<&impl IsA<gio::Cancellable>>) -> Result<(Vec<glib::GString>, Vec<glib::GString>), glib::Error> { + // unsafe { TODO: call ffi:secret_service_search_for_dbus_paths_sync() } + //} + + //#[doc(alias = "secret_service_search_sync")] + //fn search_sync(&self, schema: Option<&Schema>, attributes: /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 }, flags: SearchFlags, cancellable: Option<&impl IsA<gio::Cancellable>>) -> Result<Vec<Item>, glib::Error> { + // unsafe { TODO: call ffi:secret_service_search_sync() } + //} + + #[doc(alias = "secret_service_set_alias")] + fn set_alias<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + alias: &str, + collection: Option<&impl IsA<Collection>>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn set_alias_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let _ = ffi::secret_service_set_alias_finish(_source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = set_alias_trampoline::<P>; + unsafe { + ffi::secret_service_set_alias( + self.as_ref().to_glib_none().0, + alias.to_glib_none().0, + collection.map(|p| p.as_ref()).to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn set_alias_future( + &self, + alias: &str, + collection: Option<&(impl IsA<Collection> + Clone + 'static)>, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { + let alias = String::from(alias); + let collection = collection.map(ToOwned::to_owned); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.set_alias( + &alias, + collection.as_ref().map(::std::borrow::Borrow::borrow), + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + #[doc(alias = "secret_service_set_alias_sync")] + fn set_alias_sync( + &self, + alias: &str, + collection: Option<&impl IsA<Collection>>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<(), glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let is_ok = ffi::secret_service_set_alias_sync( + self.as_ref().to_glib_none().0, + alias.to_glib_none().0, + collection.map(|p| p.as_ref()).to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); + if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "secret_service_set_alias_to_dbus_path")] + fn set_alias_to_dbus_path<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + alias: &str, + collection_path: Option<&str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn set_alias_to_dbus_path_trampoline< + P: FnOnce(Result<(), glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let _ = ffi::secret_service_set_alias_to_dbus_path_finish( + _source_object as *mut _, + res, + &mut error, + ); + let result = if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = set_alias_to_dbus_path_trampoline::<P>; + unsafe { + ffi::secret_service_set_alias_to_dbus_path( + self.as_ref().to_glib_none().0, + alias.to_glib_none().0, + collection_path.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn set_alias_to_dbus_path_future( + &self, + alias: &str, + collection_path: Option<&str>, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { + let alias = String::from(alias); + let collection_path = collection_path.map(ToOwned::to_owned); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.set_alias_to_dbus_path( + &alias, + collection_path.as_ref().map(::std::borrow::Borrow::borrow), + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + #[doc(alias = "secret_service_set_alias_to_dbus_path_sync")] + fn set_alias_to_dbus_path_sync( + &self, + alias: &str, + collection_path: Option<&str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<(), glib::Error> { + unsafe { + let mut error = std::ptr::null_mut(); + let is_ok = ffi::secret_service_set_alias_to_dbus_path_sync( + self.as_ref().to_glib_none().0, + alias.to_glib_none().0, + collection_path.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); + if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + } + } + } + + //#[doc(alias = "secret_service_store_sync")] + //fn store_sync(&self, schema: Option<&Schema>, attributes: /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 }, collection: Option<&str>, label: &str, value: &Value, cancellable: Option<&impl IsA<gio::Cancellable>>) -> Result<(), glib::Error> { + // unsafe { TODO: call ffi:secret_service_store_sync() } + //} + + #[doc(alias = "secret_service_unlock_dbus_paths_sync")] + fn unlock_dbus_paths_sync( + &self, + paths: &[&str], + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<(i32, Vec<glib::GString>), glib::Error> { + unsafe { + let mut unlocked = std::ptr::null_mut(); + let mut error = std::ptr::null_mut(); + let ret = ffi::secret_service_unlock_dbus_paths_sync( + self.as_ref().to_glib_none().0, + paths.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut unlocked, + &mut error, + ); + if error.is_null() { + Ok((ret, FromGlibPtrContainer::from_glib_full(unlocked))) + } else { + Err(from_glib_full(error)) + } + } + } + + //#[doc(alias = "secret_service_unlock_sync")] + //fn unlock_sync(&self, objects: &[gio::DBusProxy], cancellable: Option<&impl IsA<gio::Cancellable>>, unlocked: /*Unimplemented*/Vec<gio::DBusProxy>) -> Result<i32, glib::Error> { + // unsafe { TODO: call ffi:secret_service_unlock_sync() } + //} +} + +impl<O: IsA<Service>> ServiceExt for O {} diff --git a/libsecret/src/auto/versions.txt b/libsecret/src/auto/versions.txt new file mode 100644 index 0000000..21d9cc7 --- /dev/null +++ b/libsecret/src/auto/versions.txt @@ -0,0 +1,3 @@ +Generated by gir (https://github.com/gtk-rs/gir @ 4dd714f7f3b1) +from +from gir-files (https://github.com/gtk-rs/gir-files.git @ b9db716f1bb7) diff --git a/libsecret/src/collection.rs b/libsecret/src/collection.rs new file mode 100644 index 0000000..6360a09 --- /dev/null +++ b/libsecret/src/collection.rs @@ -0,0 +1,267 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use crate::{hashtable::attribute_names_and_values, Item}; +use crate::{Collection, Schema, SearchFlags}; + +use glib::object::IsA; +use glib::translate::*; + +use std::boxed::Box as Box_; +use std::collections::HashMap; +use std::pin::Pin; +use std::ptr; + +pub trait CollectionExtManual: 'static { + #[doc(alias = "secret_collection_search")] + fn search<P: FnOnce(Result<Vec<Item>, glib::Error>) + 'static>( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + flags: SearchFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ); + + fn search_future( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + flags: SearchFlags, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<Item>, glib::Error>> + 'static>>; + + #[doc(alias = "secret_collection_search_sync")] + fn search_sync( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + flags: SearchFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<Vec<Item>, glib::Error>; + + #[doc(alias = "secret_collection_search_for_dbus_paths")] + fn search_for_dbus_paths<P: FnOnce(Result<Vec<glib::GString>, glib::Error>) + 'static>( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ); + + fn search_for_dbus_paths_future( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + ) -> Pin< + Box_<dyn std::future::Future<Output = Result<Vec<glib::GString>, glib::Error>> + 'static>, + >; + + #[doc(alias = "secret_collection_search_for_dbus_paths_sync")] + fn search_for_dbus_paths_sync( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<Vec<glib::GString>, glib::Error>; +} + +impl<O: IsA<Collection>> CollectionExtManual for O { + fn search<P: FnOnce(Result<Vec<Item>, glib::Error>) + 'static>( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + flags: SearchFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + unsafe { + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn search_trampoline< + P: FnOnce(Result<Vec<Item>, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let ret = + ffi::secret_collection_search_finish(_source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(FromGlibPtrContainer::from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = search_trampoline::<P>; + + ffi::secret_collection_search( + self.as_ref().to_glib_none().0, + schema.to_glib_none().0, + attribute_names_and_values(attributes), + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn search_future( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + flags: SearchFlags, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<Item>, glib::Error>> + 'static>> { + let schema = schema.map(ToOwned::to_owned); + let owned_map = attributes + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect::<HashMap<String, String>>(); + + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + let attributes = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v.as_str())) + .collect::<HashMap<&str, &str>>(); + + obj.search( + schema.as_ref().map(::std::borrow::Borrow::borrow), + attributes, + flags, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + fn search_sync( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + flags: SearchFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<Vec<Item>, glib::Error> { + unsafe { + let mut err = std::ptr::null_mut(); + let res = ffi::secret_collection_search_sync( + self.as_ref().to_glib_none().0, + schema.to_glib_none().0, + attribute_names_and_values(attributes), + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut err, + ); + if err.is_null() { + Ok(FromGlibPtrContainer::from_glib_full(res)) + } else { + Err(from_glib_full(err)) + } + } + } + #[doc(alias = "secret_collection_search_for_dbus_paths_sync")] + fn search_for_dbus_paths_sync( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<Vec<glib::GString>, glib::Error> { + unsafe { + let mut err = std::ptr::null_mut(); + let res = ffi::secret_collection_search_for_dbus_paths_sync( + self.as_ref().to_glib_none().0, + schema.to_glib_none().0, + attribute_names_and_values(attributes), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut err, + ); + if err.is_null() { + Ok(FromGlibPtrContainer::from_glib_full(res)) + } else { + Err(from_glib_full(err)) + } + } + } + + #[doc(alias = "secret_collection_search_for_dbus_paths")] + fn search_for_dbus_paths<P: FnOnce(Result<Vec<glib::GString>, glib::Error>) + 'static>( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + unsafe { + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn search_trampoline< + P: FnOnce(Result<Vec<glib::GString>, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let ret = ffi::secret_collection_search_for_dbus_paths_finish( + _source_object as *mut _, + res, + &mut error, + ); + let result = if error.is_null() { + Ok(FromGlibPtrContainer::from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = search_trampoline::<P>; + + ffi::secret_collection_search_for_dbus_paths( + self.as_ref().to_glib_none().0, + schema.to_glib_none().0, + attribute_names_and_values(attributes), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn search_for_dbus_paths_future( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + ) -> Pin< + Box_<dyn std::future::Future<Output = Result<Vec<glib::GString>, glib::Error>> + 'static>, + > { + let schema = schema.map(ToOwned::to_owned); + let owned_map = attributes + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect::<HashMap<String, String>>(); + + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + let attributes = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v.as_str())) + .collect::<HashMap<&str, &str>>(); + + obj.search_for_dbus_paths( + schema.as_ref().map(::std::borrow::Borrow::borrow), + attributes, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } +} diff --git a/libsecret/src/enums.rs b/libsecret/src/enums.rs new file mode 100644 index 0000000..59de400 --- /dev/null +++ b/libsecret/src/enums.rs @@ -0,0 +1,25 @@ +use glib::error::ErrorDomain; +use glib::translate::*; + +use crate::Error; + +impl ErrorDomain for Error { + fn domain() -> glib::Quark { + unsafe { from_glib(ffi::secret_error_get_quark()) } + } + + fn code(self) -> i32 { + self.into_glib() + } + + fn from(code: i32) -> Option<Self> { + match code { + ffi::SECRET_ERROR_PROTOCOL => Some(Self::Protocol), + ffi::SECRET_ERROR_IS_LOCKED => Some(Self::IsLocked), + ffi::SECRET_ERROR_NO_SUCH_OBJECT => Some(Self::NoSuchObject), + ffi::SECRET_ERROR_ALREADY_EXISTS => Some(Self::AlreadyExists), + ffi::SECRET_ERROR_INVALID_FILE_FORMAT => Some(Self::InvalidFileFormat), + value => Some(Self::__Unknown(value)), + } + } +} diff --git a/libsecret/src/functions.rs b/libsecret/src/functions.rs new file mode 100644 index 0000000..6dce25e --- /dev/null +++ b/libsecret/src/functions.rs @@ -0,0 +1,741 @@ +use std::boxed::Box as Box_; +use std::collections::HashMap; + +use crate::{hashtable::attribute_names_and_values, Schema}; +#[cfg(any(feature = "v0_19", feature = "dox"))] +#[cfg_attr(feature = "dox", doc(cfg(feature = "v0_19")))] +use crate::{Retrievable, SearchFlags, Value}; +use glib::{object::IsA, translate::*}; + +#[doc(alias = "secret_password_clearv_sync")] +#[doc(alias = "secret_password_clear_sync")] +#[doc(alias = "password_clearv_sync")] +pub fn password_clear_sync( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, +) -> Result<(), glib::Error> { + unsafe { + let mut err = std::ptr::null_mut(); + ffi::secret_password_clearv_sync( + schema.to_glib_none().0, + attribute_names_and_values(attributes), + cancellable.map(|c| c.as_ref()).to_glib_none().0, + &mut err, + ); + if err.is_null() { + Ok(()) + } else { + Err(from_glib_full(err)) + } + } +} + +#[cfg(any(feature = "v0_19", feature = "dox"))] +#[cfg_attr(feature = "dox", doc(cfg(feature = "v0_19")))] +#[doc(alias = "secret_password_lookupv_binary_sync")] +#[doc(alias = "secret_password_lookup_binary_sync")] +#[doc(alias = "password_lookupv_binary_sync")] +pub fn password_lookup_binary_sync( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, +) -> Result<Option<Value>, glib::Error> { + unsafe { + let mut err = std::ptr::null_mut(); + let value = ffi::secret_password_lookupv_binary_sync( + schema.to_glib_none().0, + attribute_names_and_values(attributes), + cancellable.map(|c| c.as_ref()).to_glib_none().0, + &mut err, + ); + if err.is_null() { + Ok(from_glib_full(value)) + } else { + Err(from_glib_full(err)) + } + } +} + +#[doc(alias = "secret_password_lookupv_nonpageable_sync")] +#[doc(alias = "secret_password_lookup_nonpageable_sync")] +#[doc(alias = "password_lookupv_nonpageable_sync")] +pub fn password_lookup_nonpageable_sync( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, +) -> Result<glib::GString, glib::Error> { + unsafe { + let mut err = std::ptr::null_mut(); + let res = ffi::secret_password_lookupv_nonpageable_sync( + schema.to_glib_none().0, + attribute_names_and_values(attributes), + cancellable.map(|c| c.as_ref()).to_glib_none().0, + &mut err, + ); + if err.is_null() { + Ok(from_glib_full(res)) + } else { + Err(from_glib_full(err)) + } + } +} + +#[doc(alias = "secret_password_lookupv_sync")] +#[doc(alias = "secret_password_lookup_sync")] +#[doc(alias = "password_lookupv_sync")] +pub fn password_lookup_sync( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, +) -> Result<Option<glib::GString>, glib::Error> { + unsafe { + let mut err = std::ptr::null_mut(); + let res = ffi::secret_password_lookupv_sync( + schema.to_glib_none().0, + attribute_names_and_values(attributes), + cancellable.map(|c| c.as_ref()).to_glib_none().0, + &mut err, + ); + if err.is_null() { + Ok(from_glib_full(res)) + } else { + Err(from_glib_full(err)) + } + } +} + +#[cfg(any(feature = "v0_19", feature = "dox"))] +#[cfg_attr(feature = "dox", doc(cfg(feature = "v0_19")))] +#[doc(alias = "secret_password_searchv_sync")] +#[doc(alias = "secret_password_search_sync")] +#[doc(alias = "password_searchv_sync")] +pub fn password_search_sync( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + flags: SearchFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, +) -> Result<Vec<Retrievable>, glib::Error> { + unsafe { + let mut err = std::ptr::null_mut(); + let res = ffi::secret_password_searchv_sync( + schema.to_glib_none().0, + attribute_names_and_values(attributes), + flags.into_glib(), + cancellable.map(|c| c.as_ref()).to_glib_none().0, + &mut err, + ); + if err.is_null() { + Ok(FromGlibPtrContainer::from_glib_full(res)) + } else { + Err(from_glib_full(err)) + } + } +} + +#[cfg(any(feature = "v0_19", feature = "dox"))] +#[cfg_attr(feature = "dox", doc(cfg(feature = "v0_19")))] +#[doc(alias = "secret_password_storev_binary_sync")] +#[doc(alias = "secret_password_store_binary_sync")] +#[doc(alias = "password_storev_binary_sync")] +pub fn password_store_binary_sync( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + collection: Option<&str>, + label: &str, + value: &Value, + cancellable: Option<&impl IsA<gio::Cancellable>>, +) -> Result<(), glib::Error> { + unsafe { + let mut err = std::ptr::null_mut(); + ffi::secret_password_storev_binary_sync( + schema.to_glib_none().0, + attribute_names_and_values(attributes), + collection.to_glib_none().0, + label.to_glib_none().0, + value.to_glib_none().0, + cancellable.map(|c| c.as_ref()).to_glib_none().0, + &mut err, + ); + if err.is_null() { + Ok(()) + } else { + Err(from_glib_full(err)) + } + } +} + +#[doc(alias = "secret_password_storev_sync")] +#[doc(alias = "secret_password_store_sync")] +#[doc(alias = "password_storev_sync")] +pub fn password_store_sync( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + collection: Option<&str>, + label: &str, + password: &str, + cancellable: Option<&impl IsA<gio::Cancellable>>, +) -> Result<(), glib::Error> { + unsafe { + let mut err = std::ptr::null_mut(); + ffi::secret_password_storev_sync( + schema.to_glib_none().0, + attribute_names_and_values(attributes), + collection.to_glib_none().0, + label.to_glib_none().0, + password.to_glib_none().0, + cancellable.map(|c| c.as_ref()).to_glib_none().0, + &mut err, + ); + if err.is_null() { + Ok(()) + } else { + Err(from_glib_full(err)) + } + } +} + +#[doc(alias = "secret_password_clearv")] +#[doc(alias = "secret_password_clear")] +#[doc(alias = "password_clearv")] +pub fn password_clear<P: FnOnce(Result<(), glib::Error>) + 'static>( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, +) { + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut err = std::ptr::null_mut(); + ffi::secret_password_clear_finish(res, &mut err); + let result = if err.is_null() { + Ok(()) + } else { + Err(from_glib_full(err)) + }; + + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + + let callback = trampoline::<P>; + unsafe { + ffi::secret_password_clearv( + schema.to_glib_none().0, + attribute_names_and_values(attributes), + cancellable.map(|c| c.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } +} + +#[doc(alias = "secret_password_clearv")] +#[doc(alias = "secret_password_clear")] +#[doc(alias = "password_clearv")] +pub async fn password_clear_future( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, +) -> Result<(), glib::Error> { + let schema = schema.map(ToOwned::to_owned); + let owned_map = attributes + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect::<HashMap<String, String>>(); + gio::GioFuture::new(&(), move |_obj, cancellable, send| { + let attributes = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v.as_str())) + .collect::<HashMap<&str, &str>>(); + password_clear( + schema.as_ref().map(::std::borrow::Borrow::borrow), + attributes, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + }) + .await +} + +#[doc(alias = "secret_password_lookupv")] +#[doc(alias = "secret_password_lookup")] +#[doc(alias = "password_lookupv")] +pub fn password_lookup<P: FnOnce(Result<Option<glib::GString>, glib::Error>) + 'static>( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, +) { + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn trampoline< + P: FnOnce(Result<Option<glib::GString>, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut err = std::ptr::null_mut(); + let res = ffi::secret_password_lookup_finish(res, &mut err); + let result = if err.is_null() { + Ok(from_glib_full(res)) + } else { + Err(from_glib_full(err)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + + let callback = trampoline::<P>; + unsafe { + ffi::secret_password_lookupv( + schema.to_glib_none().0, + attribute_names_and_values(attributes), + cancellable.map(|c| c.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } +} + +#[doc(alias = "secret_password_lookupv")] +#[doc(alias = "secret_password_lookup")] +#[doc(alias = "password_lookupv")] +pub async fn password_lookup_future( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, +) -> Result<Option<glib::GString>, glib::Error> { + let schema = schema.map(ToOwned::to_owned); + let owned_map = attributes + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect::<HashMap<String, String>>(); + gio::GioFuture::new(&(), move |_obj, cancellable, send| { + let attributes = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v.as_str())) + .collect::<HashMap<&str, &str>>(); + password_lookup( + schema.as_ref().map(::std::borrow::Borrow::borrow), + attributes, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + }) + .await +} + +#[cfg(any(feature = "v0_19", feature = "dox"))] +#[cfg_attr(feature = "dox", doc(cfg(feature = "v0_19")))] +#[doc(alias = "secret_password_lookupv_binary")] +#[doc(alias = "secret_password_lookup_binary")] +#[doc(alias = "password_lookupv_binary")] +pub fn password_lookup_binary<P: FnOnce(Result<Option<Value>, glib::Error>) + 'static>( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, +) { + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn trampoline<P: FnOnce(Result<Option<Value>, glib::Error>) + 'static>( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut err = std::ptr::null_mut(); + let res = ffi::secret_password_lookup_binary_finish(res, &mut err); + let result = if err.is_null() { + Ok(from_glib_full(res)) + } else { + Err(from_glib_full(err)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + + let callback = trampoline::<P>; + unsafe { + ffi::secret_password_lookupv( + schema.to_glib_none().0, + attribute_names_and_values(attributes), + cancellable.map(|c| c.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } +} + +#[cfg(any(feature = "v0_19", feature = "dox"))] +#[cfg_attr(feature = "dox", doc(cfg(feature = "v0_19")))] +#[doc(alias = "secret_password_lookupv_binary")] +#[doc(alias = "secret_password_lookup_binary")] +#[doc(alias = "password_lookupv_binary")] +pub async fn password_lookup_binary_future( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, +) -> Result<Option<Value>, glib::Error> { + let schema = schema.map(ToOwned::to_owned); + let owned_map = attributes + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect::<HashMap<String, String>>(); + gio::GioFuture::new(&(), move |_obj, cancellable, send| { + let attributes = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v.as_str())) + .collect::<HashMap<&str, &str>>(); + password_lookup_binary( + schema.as_ref().map(::std::borrow::Borrow::borrow), + attributes, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + }) + .await +} + +#[doc(alias = "secret_password_lookupv_nonpageable")] +#[doc(alias = "secret_password_lookup_nonpageable")] +#[doc(alias = "password_lookupv_nonpageable")] +pub fn password_lookup_nonpageable< + P: FnOnce(Result<Option<glib::GString>, glib::Error>) + 'static, +>( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, +) { + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn trampoline< + P: FnOnce(Result<Option<glib::GString>, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut err = std::ptr::null_mut(); + let res = ffi::secret_password_lookup_nonpageable_finish(res, &mut err); + let result = if err.is_null() { + Ok(from_glib_full(res)) + } else { + Err(from_glib_full(err)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + + let callback = trampoline::<P>; + unsafe { + ffi::secret_password_lookupv( + schema.to_glib_none().0, + attribute_names_and_values(attributes), + cancellable.map(|c| c.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } +} + +#[doc(alias = "secret_password_lookupv_nonpageable")] +#[doc(alias = "secret_password_lookup_nonpageable")] +#[doc(alias = "password_lookupv_nonpageable")] +pub async fn password_lookup_nonpageable_future( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, +) -> Result<Option<glib::GString>, glib::Error> { + let schema = schema.map(ToOwned::to_owned); + let owned_map = attributes + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect::<HashMap<String, String>>(); + gio::GioFuture::new(&(), move |_obj, cancellable, send| { + let attributes = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v.as_str())) + .collect::<HashMap<&str, &str>>(); + password_lookup_nonpageable( + schema.as_ref().map(::std::borrow::Borrow::borrow), + attributes, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + }) + .await +} + +#[doc(alias = "secret_password_storev")] +#[doc(alias = "secret_password_store")] +#[doc(alias = "password_storev")] +pub fn password_store<P: FnOnce(Result<(), glib::Error>) + 'static>( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + collection: Option<&str>, + label: &str, + password: &str, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, +) { + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut err = std::ptr::null_mut(); + ffi::secret_password_store_finish(res, &mut err); + let result = if err.is_null() { + Ok(()) + } else { + Err(from_glib_full(err)) + }; + + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + + let callback = trampoline::<P>; + unsafe { + ffi::secret_password_storev( + schema.to_glib_none().0, + attribute_names_and_values(attributes), + collection.to_glib_none().0, + label.to_glib_none().0, + password.to_glib_none().0, + cancellable.map(|c| c.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } +} + +#[doc(alias = "secret_password_storev")] +#[doc(alias = "secret_password_store")] +#[doc(alias = "password_storev")] +pub async fn password_store_future( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + collection: Option<&str>, + label: &str, + password: &str, +) -> Result<(), glib::Error> { + let schema = schema.map(ToOwned::to_owned); + let collection = collection.map(ToOwned::to_owned); + let label = label.to_owned(); + let password = password.to_owned(); + let owned_map = attributes + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect::<HashMap<String, String>>(); + gio::GioFuture::new(&(), move |_obj, cancellable, send| { + let attributes = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v.as_str())) + .collect::<HashMap<&str, &str>>(); + password_store( + schema.as_ref().map(::std::borrow::Borrow::borrow), + attributes, + collection.as_ref().map(::std::borrow::Borrow::borrow), + &label, + &password, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + }) + .await +} + +#[cfg(any(feature = "v0_19", feature = "dox"))] +#[cfg_attr(feature = "dox", doc(cfg(feature = "v0_19")))] +#[doc(alias = "secret_password_storev_binary")] +#[doc(alias = "secret_password_store_binary")] +#[doc(alias = "password_storev_binary")] +pub fn password_store_binary<P: FnOnce(Result<(), glib::Error>) + 'static>( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + collection: Option<&str>, + label: &str, + value: &Value, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, +) { + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut err = std::ptr::null_mut(); + let _ = ffi::secret_password_store_finish(res, &mut err); + let result = if err.is_null() { + Ok(()) + } else { + Err(from_glib_full(err)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + + let callback = trampoline::<P>; + unsafe { + ffi::secret_password_storev_binary( + schema.to_glib_none().0, + attribute_names_and_values(attributes), + collection.to_glib_none().0, + label.to_glib_none().0, + value.to_glib_none().0, + cancellable.map(|c| c.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } +} + +#[cfg(any(feature = "v0_19", feature = "dox"))] +#[cfg_attr(feature = "dox", doc(cfg(feature = "v0_19")))] +#[doc(alias = "secret_password_storev_binary")] +#[doc(alias = "secret_password_store_binary")] +#[doc(alias = "password_storev_binary")] +pub async fn password_store_binary_future( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + collection: Option<&str>, + label: &str, + value: &Value, +) -> Result<(), glib::Error> { + let schema = schema.map(ToOwned::to_owned); + let collection = collection.map(ToOwned::to_owned); + let label = label.to_owned(); + let password = value.clone(); + let owned_map = attributes + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect::<HashMap<String, String>>(); + gio::GioFuture::new(&(), move |_obj, cancellable, send| { + let attributes = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v.as_str())) + .collect::<HashMap<&str, &str>>(); + password_store_binary( + schema.as_ref().map(::std::borrow::Borrow::borrow), + attributes, + collection.as_ref().map(::std::borrow::Borrow::borrow), + &label, + &password, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + }) + .await +} + +#[cfg(any(feature = "v0_19", feature = "dox"))] +#[cfg_attr(feature = "dox", doc(cfg(feature = "v0_19")))] +#[doc(alias = "secret_password_searchv")] +#[doc(alias = "secret_password_search")] +#[doc(alias = "password_searchv")] +pub fn password_search<P: FnOnce(Result<Vec<Retrievable>, glib::Error>) + 'static>( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + flags: SearchFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, +) { + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn trampoline<P: FnOnce(Result<Vec<Retrievable>, glib::Error>) + 'static>( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut err = std::ptr::null_mut(); + let res = ffi::secret_password_search_finish(res, &mut err); + let result = if err.is_null() { + Ok(FromGlibPtrContainer::from_glib_full(res)) + } else { + Err(from_glib_full(err)) + }; + + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + + let callback = trampoline::<P>; + unsafe { + ffi::secret_password_searchv( + schema.to_glib_none().0, + attribute_names_and_values(attributes), + flags.into_glib(), + cancellable.map(|c| c.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } +} + +#[cfg(any(feature = "v0_19", feature = "dox"))] +#[cfg_attr(feature = "dox", doc(cfg(feature = "v0_19")))] +#[doc(alias = "secret_password_searchv")] +#[doc(alias = "secret_password_search")] +#[doc(alias = "password_searchv")] +pub async fn password_search_future( + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + flags: SearchFlags, +) -> Result<Vec<Retrievable>, glib::Error> { + let schema = schema.map(ToOwned::to_owned); + let owned_map = attributes + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect::<HashMap<String, String>>(); + gio::GioFuture::new(&(), move |_obj, cancellable, send| { + let attributes = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v.as_str())) + .collect::<HashMap<&str, &str>>(); + password_search( + schema.as_ref().map(::std::borrow::Borrow::borrow), + attributes, + flags, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + }) + .await +} diff --git a/libsecret/src/hashtable.rs b/libsecret/src/hashtable.rs new file mode 100644 index 0000000..1f42c95 --- /dev/null +++ b/libsecret/src/hashtable.rs @@ -0,0 +1,63 @@ +use glib::translate::*; +use std::collections::HashMap; + +use crate::Value; + +pub(crate) unsafe fn attribute_names_and_values( + entry: HashMap<&str, &str>, +) -> *mut glib::ffi::GHashTable { + let hash_table = glib::ffi::g_hash_table_new_full( + Some(glib::ffi::g_str_hash), + Some(glib::ffi::g_str_equal), + Some(glib::ffi::g_free), + Some(glib::ffi::g_free), + ); + + for (key, val) in entry { + let key_ptr: *mut libc::c_char = key.to_glib_full(); + let val_ptr: *mut libc::c_char = val.to_glib_full(); + glib::ffi::g_hash_table_insert(hash_table, key_ptr as *mut _, val_ptr as *mut _); + } + + hash_table +} + +pub(crate) unsafe fn attribute_names_and_properties( + hash_map: HashMap<&str, &glib::Variant>, +) -> *mut glib::ffi::GHashTable { + let hash_table = glib::ffi::g_hash_table_new_full( + Some(glib::ffi::g_str_hash), + Some(glib::ffi::g_str_equal), + Some(glib::ffi::g_free), + Some(glib::ffi::g_free), + ); + + for (name, value) in hash_map { + let key_ptr: *mut libc::c_char = name.to_glib_full(); + glib::ffi::g_hash_table_insert(hash_table, key_ptr as *mut _, value.as_ptr() as _); + } + + hash_table +} + +pub(crate) unsafe fn hash_map_from_glib_none( + ptr: *mut glib::ffi::GHashTable, +) -> HashMap<String, Value> { + unsafe extern "C" fn read_string_hash_table( + key: glib::ffi::gpointer, + value: glib::ffi::gpointer, + hash_map: glib::ffi::gpointer, + ) { + let key: String = from_glib_none(key as *const libc::c_char); + let value: Value = from_glib_none(value as *const ffi::SecretValue); + let hash_map: &mut HashMap<String, Value> = &mut *(hash_map as *mut HashMap<String, Value>); + hash_map.insert(key, value); + } + let mut map = HashMap::with_capacity(glib::ffi::g_hash_table_size(ptr) as usize); + glib::ffi::g_hash_table_foreach( + ptr, + Some(read_string_hash_table), + &mut map as *mut HashMap<String, Value> as *mut _, + ); + map +} diff --git a/libsecret/src/item.rs b/libsecret/src/item.rs new file mode 100644 index 0000000..0d0d97f --- /dev/null +++ b/libsecret/src/item.rs @@ -0,0 +1,314 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use crate::{hashtable::attribute_names_and_values, Item}; +use crate::{Collection, ItemCreateFlags, Schema, Value}; + +use glib::object::IsA; +use glib::translate::*; + +use std::boxed::Box as Box_; +use std::collections::HashMap; +use std::pin::Pin; +use std::ptr; + +impl Item { + #[doc(alias = "secret_item_get_attributes")] + pub fn attributes(&self) -> HashMap<String, String> { + unsafe { + let table = ffi::secret_item_get_attributes(self.to_glib_none().0); + FromGlibPtrContainer::from_glib_full(table) + } + } + + #[doc(alias = "secret_item_create_sync")] + pub fn create_sync( + collection: &impl IsA<Collection>, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + label: &str, + value: &Value, + flags: ItemCreateFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<Self, glib::Error> { + unsafe { + let mut err = std::ptr::null_mut(); + let item = ffi::secret_item_create_sync( + collection.as_ref().to_glib_none().0, + schema.to_glib_none().0, + attribute_names_and_values(attributes), + label.to_glib_none().0, + value.to_glib_none().0, + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut err, + ); + if err.is_null() { + Ok(from_glib_full(item)) + } else { + Err(from_glib_full(err)) + } + } + } + + #[doc(alias = "secret_item_load_secrets_sync")] + pub fn load_secrets_sync( + items: &[Item], + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<(), glib::Error> { + unsafe { + let mut error = ptr::null_mut(); + let is_ok = ffi::secret_item_load_secrets_sync( + items.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut error, + ); + assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); + if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "secret_item_load_secrets")] + pub fn load_secrets<P: FnOnce(Result<(), glib::Error>) + 'static>( + items: &[Item], + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn load_secrets_trampoline< + P: FnOnce(Result<(), glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let _ = ffi::secret_item_load_secrets_finish(res, &mut error); + let result = if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = load_secrets_trampoline::<P>; + unsafe { + ffi::secret_item_load_secrets( + items.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + pub fn load_secrets_future( + items: &[Item], + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { + let items = items.to_vec(); + Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| { + Self::load_secrets(&items, Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + #[doc(alias = "secret_item_create")] + pub fn create<P: FnOnce(Result<Item, glib::Error>) + 'static>( + collection: &impl IsA<Collection>, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + label: &str, + value: &Value, + flags: ItemCreateFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + unsafe { + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn create_trampoline< + P: FnOnce(Result<Item, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let ret = ffi::secret_item_create_finish(res, &mut error); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = create_trampoline::<P>; + + ffi::secret_item_create( + collection.as_ref().to_glib_none().0, + schema.to_glib_none().0, + attribute_names_and_values(attributes), + label.to_glib_none().0, + value.to_glib_none().0, + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + pub fn create_future( + collection: &(impl IsA<Collection> + Clone + 'static), + schema: Option<&Schema>, + attributes: HashMap<String, &str>, + label: &str, + value: &Value, + flags: ItemCreateFlags, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<Item, glib::Error>> + 'static>> { + let collection = collection.clone(); + let schema = schema.map(ToOwned::to_owned); + let label = String::from(label); + let value = value.clone(); + let owned_map = attributes + .into_iter() + .map(|(k, v)| (k, v.to_string())) + .collect::<HashMap<String, String>>(); + + Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| { + let attributes = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v.as_str())) + .collect::<HashMap<&str, &str>>(); + Self::create( + &collection, + schema.as_ref().map(::std::borrow::Borrow::borrow), + attributes, + &label, + &value, + flags, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + #[doc(alias = "secret_item_set_attributes")] + pub fn set_attributes<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + unsafe { + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn set_attributes_trampoline< + P: FnOnce(Result<(), glib::Error>) + 'static, + >( + source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut err = ptr::null_mut(); + let _ = + ffi::secret_item_set_attributes_finish(source_object as *mut _, res, &mut err); + let result = if err.is_null() { + Ok(()) + } else { + Err(from_glib_full(err)) + }; + + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = set_attributes_trampoline::<P>; + + ffi::secret_item_set_attributes( + self.to_glib_none().0, + schema.to_glib_none().0, + attribute_names_and_values(attributes), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + pub fn set_attributes_future( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { + let schema = schema.map(ToOwned::to_owned); + + let owned_map = attributes + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect::<HashMap<String, String>>(); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + let attributes = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v.as_str())) + .collect::<HashMap<&str, &str>>(); + obj.set_attributes( + schema.as_ref().map(::std::borrow::Borrow::borrow), + attributes, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + #[doc(alias = "secret_item_set_attributes_sync")] + pub fn set_attributes_sync( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<(), glib::Error> { + unsafe { + let mut err = std::ptr::null_mut(); + ffi::secret_item_set_attributes_sync( + self.to_glib_none().0, + schema.to_glib_none().0, + attribute_names_and_values(attributes), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut err, + ); + if err.is_null() { + Ok(()) + } else { + Err(from_glib_full(err)) + } + } + } +} diff --git a/libsecret/src/lib.rs b/libsecret/src/lib.rs new file mode 100644 index 0000000..8d4c306 --- /dev/null +++ b/libsecret/src/lib.rs @@ -0,0 +1,123 @@ +#![cfg_attr(feature = "dox", feature(doc_cfg))] +//! # Rust Libsecret bindings +//! +//! This library contains safe Rust bindings for +//! [Libsecret](https://gitlab.gnome.org/GNOME/libsecret/), a library that +//! offers access to the Secret Service API. +//! +//! See also +//! +//! - [gtk-rs project overview](https://gtk-rs.org/) +//! +//! ## Usage +//! +//! You can add libsecret by adding it in your `Cargo.toml` file: +//! +//! ```toml +//! [dependencies.secret] +//! package = "libsecret" +//! version = "0.x.y" +//! ``` +//! +//! ### Define a password schema +//! +//! Each stored password has a set of attributes which are later used to lookup +//! the password. The names and types of the attributes are defined in a schema. +//! The schema is usually defined once globally. Here’s how to define a schema: +//! +//! ```no_run +//! let mut attributes = std::collections::HashMap::new(); +//! attributes.insert("number", libsecret::SchemaAttributeType::Integer); +//! attributes.insert("string", libsecret::SchemaAttributeType::String); +//! attributes.insert("even", libsecret::SchemaAttributeType::Boolean); +//! +//! let schema = libsecret::Schema::new("some.app.Id", libsecret::SchemaFlags::NONE, attributes); +//! ``` +//! +//! ### Store a password +//! +//! Each stored password has a set of attributes which are later used to lookup +//! the password. The attributes should not contain secrets, as they are not +//! stored in an encrypted fashion. +//! +//! This first example stores a password asynchronously, and is appropriate for GUI applications so that the UI does not block. +//! +//! ```no_run +//! let mut attributes = std::collections::HashMap::new(); +//! attributes.insert("number", "8"); +//! attributes.insert("string", "eight"); +//! attributes.insert("even", "true"); +//! +//! let collection = libsecret::COLLECTION_DEFAULT; +//! libsecret::password_store_future(Some(&schema), attributes, Some(&collection), "The Label", "the password").await?; +//! ``` +//! +//! ### Lookup a password +//! +//! Each stored password has a set of attributes which are used to lookup the +//! password. If multiple passwords match the lookup attributes, then the one +//! stored most recently is returned. +//! +//! This first example looks up a password asynchronously, and is appropriate +//! for GUI applications so that the UI does not block. +//! +//! ```no_run +//! let mut attributes = std::collections::HashMap::new(); +//! attributes.insert("number", "8"); +//! attributes.insert("even", "true"); +//! +//! let password = libsecret::password_lookup_future(Some(&schema), attributes).await?; +//! ``` +//! ### Remove a password +//! +//! Each stored password has a set of attributes which are used to find which +//! password to remove. If multiple passwords match the attributes, then the one +//! stored most recently is removed. +//! +//! This first example removes a password asynchronously, and is appropriate for +//! GUI applications so that the UI does not block. +//! +//! ```no_run +//! let mut attributes = std::collections::HashMap::new(); +//! attributes.insert("number", "8"); +//! attributes.insert("even", "true"); +//! +//! libsecret::password_clear_future(Some(&schema), attributes).await?; +//! ``` +#[allow(unused_imports)] +mod auto; + +pub use auto::functions::*; +pub use auto::*; +pub use functions::*; + +mod collection; +mod enums; +mod functions; +mod hashtable; +#[allow(clippy::too_many_arguments)] +mod item; +mod prompt; +#[cfg(any(feature = "v0_19", feature = "dox"))] +#[cfg_attr(feature = "dox", doc(cfg(feature = "v0_19")))] +mod retrievable; +mod schema; +mod schema_attribute; +#[allow(clippy::type_complexity)] +#[allow(clippy::too_many_arguments)] +mod service; +mod value; + +pub use value::Value; + +pub use ffi; + +pub mod prelude { + pub use super::auto::traits::*; + pub use super::collection::CollectionExtManual; + pub use super::prompt::PromptExtManual; + #[cfg(any(feature = "v0_19", feature = "dox"))] + #[cfg_attr(feature = "dox", doc(cfg(feature = "v0_19")))] + pub use super::retrievable::RetrievableExtManual; + pub use super::service::ServiceExtManual; +} diff --git a/libsecret/src/prompt.rs b/libsecret/src/prompt.rs new file mode 100644 index 0000000..bfb7845 --- /dev/null +++ b/libsecret/src/prompt.rs @@ -0,0 +1,100 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use crate::Prompt; + +use glib::object::IsA; +use glib::translate::*; + +use std::boxed::Box as Box_; +use std::pin::Pin; +use std::ptr; + +pub trait PromptExtManual: 'static { + #[doc(alias = "secret_prompt_perform")] + fn perform<P: FnOnce(Result<glib::Variant, glib::Error>) + 'static>( + &self, + window_id: Option<&str>, + return_type: &glib::VariantTy, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ); + + fn perform_future( + &self, + window_id: Option<&str>, + return_type: &glib::VariantTy, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<glib::Variant, glib::Error>> + 'static>>; +} + +impl<O: IsA<Prompt>> PromptExtManual for O { + fn perform<P: FnOnce(Result<glib::Variant, glib::Error>) + 'static>( + &self, + window_id: Option<&str>, + return_type: &glib::VariantTy, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn perform_trampoline< + P: FnOnce(Result<glib::Variant, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let ret = ffi::secret_prompt_perform_finish(_source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = perform_trampoline::<P>; + unsafe { + ffi::secret_prompt_perform( + self.as_ref().to_glib_none().0, + window_id.to_glib_none().0, + return_type.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn perform_future( + &self, + window_id: Option<&str>, + return_type: &glib::VariantTy, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<glib::Variant, glib::Error>> + 'static>> + { + let window_id = window_id.map(ToOwned::to_owned); + let return_type = return_type.to_owned(); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.perform( + window_id.as_ref().map(::std::borrow::Borrow::borrow), + &return_type, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } +} diff --git a/libsecret/src/retrievable.rs b/libsecret/src/retrievable.rs new file mode 100644 index 0000000..617d8e3 --- /dev/null +++ b/libsecret/src/retrievable.rs @@ -0,0 +1,20 @@ +use std::collections::HashMap; + +use crate::Retrievable; +use glib::object::IsA; +use glib::translate::*; + +pub trait RetrievableExtManual: 'static { + #[doc(alias = "secret_retrievable_get_attributes")] + #[doc(alias = "get_attributes")] + fn attributes(&self) -> HashMap<String, String>; +} + +impl<O: IsA<Retrievable>> RetrievableExtManual for O { + fn attributes(&self) -> HashMap<String, String> { + unsafe { + let table = ffi::secret_retrievable_get_attributes(self.as_ref().to_glib_none().0); + FromGlibPtrContainer::from_glib_full(table) + } + } +} diff --git a/libsecret/src/schema.rs b/libsecret/src/schema.rs new file mode 100644 index 0000000..b3252e2 --- /dev/null +++ b/libsecret/src/schema.rs @@ -0,0 +1,37 @@ +use crate::{Schema, SchemaAttributeType, SchemaFlags}; +use glib::translate::*; +use std::collections::HashMap; + +impl Schema { + #[doc(alias = "secret_schema_new")] + #[doc(alias = "secret_schema_newv")] + pub fn new( + name: &str, + flags: SchemaFlags, + attribute_names_and_types: HashMap<&str, SchemaAttributeType>, + ) -> Self { + unsafe { + let hash_table = glib::ffi::g_hash_table_new_full( + Some(glib::ffi::g_str_hash), + Some(glib::ffi::g_str_equal), + Some(glib::ffi::g_free), + None, + ); + + for (name, type_) in attribute_names_and_types { + let key_ptr: *mut libc::c_char = name.to_glib_full(); + glib::ffi::g_hash_table_insert( + hash_table, + key_ptr as *mut _, + type_.into_glib() as *mut _, + ); + } + + from_glib_full(ffi::secret_schema_newv( + name.to_glib_none().0, + flags.into_glib(), + hash_table, + )) + } + } +} diff --git a/libsecret/src/schema_attribute.rs b/libsecret/src/schema_attribute.rs new file mode 100644 index 0000000..562381a --- /dev/null +++ b/libsecret/src/schema_attribute.rs @@ -0,0 +1,12 @@ +use crate::{SchemaAttribute, SchemaAttributeType}; +use glib::translate::*; + +impl SchemaAttribute { + pub fn type_(&self) -> SchemaAttributeType { + unsafe { from_glib((*(self.as_ptr())).type_) } + } + + pub fn name(&self) -> glib::GString { + unsafe { from_glib_none((*(self.as_ptr())).name) } + } +} diff --git a/libsecret/src/service.rs b/libsecret/src/service.rs new file mode 100644 index 0000000..2175667 --- /dev/null +++ b/libsecret/src/service.rs @@ -0,0 +1,1147 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use crate::{ + hashtable::{attribute_names_and_properties, attribute_names_and_values}, + Service, +}; +use crate::{CollectionCreateFlags, Item, ItemCreateFlags, Schema, SearchFlags, Value}; + +use glib::object::IsA; +use glib::translate::*; + +use std::boxed::Box as Box_; +use std::collections::HashMap; +use std::pin::Pin; +use std::ptr; + +pub trait ServiceExtManual: 'static { + #[doc(alias = "secret_service_lock")] + fn lock<P: FnOnce(Result<Vec<gio::DBusProxy>, glib::Error>) + 'static>( + &self, + objects: &[gio::DBusProxy], + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ); + + fn lock_future( + &self, + objects: &[gio::DBusProxy], + ) -> Pin< + Box_<dyn std::future::Future<Output = Result<Vec<gio::DBusProxy>, glib::Error>> + 'static>, + >; + + #[doc(alias = "secret_service_lock_dbus_paths")] + fn lock_dbus_paths<P: FnOnce(Result<Vec<glib::GString>, glib::Error>) + 'static>( + &self, + paths: &[&str], + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ); + + fn lock_dbus_paths_future( + &self, + paths: &[&str], + ) -> Pin< + Box_<dyn std::future::Future<Output = Result<Vec<glib::GString>, glib::Error>> + 'static>, + >; + + #[doc(alias = "secret_service_lock_dbus_paths_sync")] + fn lock_dbus_paths_sync( + &self, + paths: Vec<&str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<Vec<glib::GString>, glib::Error>; + + #[doc(alias = "secret_service_unlock")] + fn unlock<P: FnOnce(Result<Vec<gio::DBusProxy>, glib::Error>) + 'static>( + &self, + objects: &[gio::DBusProxy], + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ); + + fn unlock_future( + &self, + objects: &[gio::DBusProxy], + ) -> Pin< + Box_<dyn std::future::Future<Output = Result<Vec<gio::DBusProxy>, glib::Error>> + 'static>, + >; + + #[doc(alias = "secret_service_unlock_dbus_paths")] + fn unlock_dbus_paths<P: FnOnce(Result<Vec<glib::GString>, glib::Error>) + 'static>( + &self, + paths: &[&str], + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ); + + fn unlock_dbus_paths_future( + &self, + paths: &[&str], + ) -> Pin< + Box_<dyn std::future::Future<Output = Result<Vec<glib::GString>, glib::Error>> + 'static>, + >; + + #[doc(alias = "secret_service_store")] + fn store<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + collection: Option<&str>, + label: &str, + value: &Value, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ); + + fn store_future( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + collection: Option<&str>, + label: &str, + value: &Value, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>>; + + #[doc(alias = "secret_service_search")] + fn search<P: FnOnce(Result<Vec<Item>, glib::Error>) + 'static>( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + flags: SearchFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ); + + fn search_future( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + flags: SearchFlags, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<Item>, glib::Error>> + 'static>>; + + #[doc(alias = "secret_service_lookup")] + fn lookup<P: FnOnce(Result<Value, glib::Error>) + 'static>( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ); + + fn lookup_future( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<Value, glib::Error>> + 'static>>; + + #[doc(alias = "secret_service_clear")] + fn clear<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ); + + fn clear_future( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>>; + + #[doc(alias = "secret_service_create_item_dbus_path")] + fn create_item_dbus_path<P: FnOnce(Result<glib::GString, glib::Error>) + 'static>( + &self, + collection_path: &str, + properties: HashMap<&str, &glib::Variant>, + value: &Value, + flags: ItemCreateFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ); + + fn create_item_dbus_path_future( + &self, + collection_path: &str, + properties: HashMap<&str, &glib::Variant>, + value: &Value, + flags: ItemCreateFlags, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<glib::GString, glib::Error>> + 'static>>; + + #[doc(alias = "secret_service_create_collection_dbus_path")] + fn create_collection_dbus_path<P: FnOnce(Result<glib::GString, glib::Error>) + 'static>( + &self, + properties: HashMap<&str, &glib::Variant>, + alias: Option<&str>, + flags: CollectionCreateFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ); + + fn create_collection_dbus_path_future( + &self, + properties: HashMap<&str, &glib::Variant>, + alias: Option<&str>, + flags: CollectionCreateFlags, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<glib::GString, glib::Error>> + 'static>>; + + #[doc(alias = "secret_service_get_secrets_for_dbus_paths")] + #[doc(alias = "get_secrets_for_dbus_paths")] + fn secrets_for_dbus_paths<P: FnOnce(Result<HashMap<String, Value>, glib::Error>) + 'static>( + &self, + item_paths: &str, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ); + + fn secrets_for_dbus_paths_future( + &self, + item_paths: &str, + ) -> Pin< + Box_< + dyn std::future::Future<Output = Result<HashMap<String, Value>, glib::Error>> + 'static, + >, + >; + + #[doc(alias = "secret_service_search_for_dbus_paths")] + fn search_for_dbus_paths< + P: FnOnce(Result<(Vec<glib::GString>, Vec<glib::GString>), glib::Error>) + 'static, + >( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ); + + fn search_for_dbus_paths_future( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + ) -> Pin< + Box_< + dyn std::future::Future< + Output = Result<(Vec<glib::GString>, Vec<glib::GString>), glib::Error>, + > + 'static, + >, + >; +} + +impl<O: IsA<Service>> ServiceExtManual for O { + #[doc(alias = "secret_lock_dbus_paths_sync")] + fn lock_dbus_paths_sync( + &self, + paths: Vec<&str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + ) -> Result<Vec<glib::GString>, glib::Error> { + unsafe { + let mut locked = ptr::null_mut(); + let mut error = ptr::null_mut(); + let _ = ffi::secret_service_lock_dbus_paths_sync( + self.as_ref().to_glib_none().0, + paths.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + &mut locked, + &mut error, + ); + if error.is_null() { + Ok(FromGlibPtrContainer::from_glib_full(locked)) + } else { + Err(from_glib_full(error)) + } + } + } + + fn unlock_dbus_paths<P: FnOnce(Result<Vec<glib::GString>, glib::Error>) + 'static>( + &self, + paths: &[&str], + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn unlock_dbus_paths_trampoline< + P: FnOnce(Result<Vec<glib::GString>, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let mut unlocked = ptr::null_mut(); + let _ = ffi::secret_service_unlock_dbus_paths_finish( + _source_object as *mut _, + res, + &mut unlocked, + &mut error, + ); + let result = if error.is_null() { + Ok(FromGlibPtrContainer::from_glib_full(unlocked)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = unlock_dbus_paths_trampoline::<P>; + + unsafe { + ffi::secret_service_unlock_dbus_paths( + self.as_ref().to_glib_none().0, + paths.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn unlock_dbus_paths_future( + &self, + paths: &[&str], + ) -> Pin< + Box_<dyn std::future::Future<Output = Result<Vec<glib::GString>, glib::Error>> + 'static>, + > { + let paths = paths.iter().copied().map(String::from).collect::<Vec<_>>(); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + let paths = paths.iter().map(|s| s.as_str()).collect::<Vec<_>>(); + obj.unlock_dbus_paths(&paths, Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + fn unlock<P: FnOnce(Result<Vec<gio::DBusProxy>, glib::Error>) + 'static>( + &self, + objects: &[gio::DBusProxy], + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn unlock_trampoline< + P: FnOnce(Result<Vec<gio::DBusProxy>, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let mut unlocked = ptr::null_mut(); + let _ = ffi::secret_service_unlock_finish( + _source_object as *mut _, + res, + &mut unlocked, + &mut error, + ); + let result = if error.is_null() { + Ok(FromGlibPtrContainer::from_glib_full(unlocked)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = unlock_trampoline::<P>; + unsafe { + ffi::secret_service_unlock( + self.as_ref().to_glib_none().0, + objects.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn unlock_future( + &self, + objects: &[gio::DBusProxy], + ) -> Pin< + Box_<dyn std::future::Future<Output = Result<Vec<gio::DBusProxy>, glib::Error>> + 'static>, + > { + let objects = objects.to_vec(); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.unlock(&objects, Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + fn lock_dbus_paths<P: FnOnce(Result<Vec<glib::GString>, glib::Error>) + 'static>( + &self, + paths: &[&str], + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn lock_dbus_paths_trampoline< + P: FnOnce(Result<Vec<glib::GString>, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let mut locked = ptr::null_mut(); + let _ = ffi::secret_service_lock_dbus_paths_finish( + _source_object as *mut _, + res, + &mut locked, + &mut error, + ); + let result = if error.is_null() { + Ok(FromGlibPtrContainer::from_glib_full(locked)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = lock_dbus_paths_trampoline::<P>; + unsafe { + ffi::secret_service_lock_dbus_paths( + self.as_ref().to_glib_none().0, + paths.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn lock_dbus_paths_future( + &self, + paths: &[&str], + ) -> Pin< + Box_<dyn std::future::Future<Output = Result<Vec<glib::GString>, glib::Error>> + 'static>, + > { + let paths = paths.iter().copied().map(String::from).collect::<Vec<_>>(); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + let paths = paths.iter().map(|s| s.as_str()).collect::<Vec<_>>(); + obj.lock_dbus_paths(&paths, Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + fn lock<P: FnOnce(Result<Vec<gio::DBusProxy>, glib::Error>) + 'static>( + &self, + objects: &[gio::DBusProxy], + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn lock_trampoline< + P: FnOnce(Result<Vec<gio::DBusProxy>, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let mut locked = ptr::null_mut(); + let _ = ffi::secret_service_lock_finish( + _source_object as *mut _, + res, + &mut locked, + &mut error, + ); + let result = if error.is_null() { + Ok(FromGlibPtrContainer::from_glib_full(locked)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = lock_trampoline::<P>; + unsafe { + ffi::secret_service_lock( + self.as_ref().to_glib_none().0, + objects.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn lock_future( + &self, + objects: &[gio::DBusProxy], + ) -> Pin< + Box_<dyn std::future::Future<Output = Result<Vec<gio::DBusProxy>, glib::Error>> + 'static>, + > { + let objects = objects.to_vec(); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.lock(&objects, Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + fn store<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + collection: Option<&str>, + label: &str, + value: &Value, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + unsafe { + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn store_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>( + source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let _ = ffi::secret_service_store_finish(source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = store_trampoline::<P>; + + ffi::secret_service_store( + self.as_ref().to_glib_none().0, + schema.to_glib_none().0, + attribute_names_and_values(attributes), + collection.to_glib_none().0, + label.to_glib_none().0, + value.to_glib_none().0, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn store_future( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + collection: Option<&str>, + label: &str, + value: &Value, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { + let schema = schema.map(ToOwned::to_owned); + let collection = collection.map(ToOwned::to_owned); + let label = String::from(label); + let value = value.clone(); + let owned_map = attributes + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect::<HashMap<String, String>>(); + + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + let attributes = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v.as_str())) + .collect::<HashMap<&str, &str>>(); + obj.store( + schema.as_ref().map(::std::borrow::Borrow::borrow), + attributes, + collection.as_ref().map(::std::borrow::Borrow::borrow), + &label, + &value, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + fn search<P: FnOnce(Result<Vec<Item>, glib::Error>) + 'static>( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + flags: SearchFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + unsafe { + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn search_trampoline< + P: FnOnce(Result<Vec<Item>, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let ret = + ffi::secret_service_search_finish(_source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(FromGlibPtrContainer::from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = search_trampoline::<P>; + + ffi::secret_service_search( + self.as_ref().to_glib_none().0, + schema.to_glib_none().0, + attribute_names_and_values(attributes), + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn search_future( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + flags: SearchFlags, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<Item>, glib::Error>> + 'static>> { + let schema = schema.map(ToOwned::to_owned); + let owned_map = attributes + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect::<HashMap<String, String>>(); + + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + let attributes = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v.as_str())) + .collect::<HashMap<&str, &str>>(); + obj.search( + schema.as_ref().map(::std::borrow::Borrow::borrow), + attributes, + flags, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + fn lookup<P: FnOnce(Result<Value, glib::Error>) + 'static>( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + unsafe { + let hash_table = attribute_names_and_values(attributes); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn lookup_trampoline< + P: FnOnce(Result<Value, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let ret = + ffi::secret_service_lookup_finish(_source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = lookup_trampoline::<P>; + + ffi::secret_service_lookup( + self.as_ref().to_glib_none().0, + schema.to_glib_none().0, + hash_table, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn lookup_future( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<Value, glib::Error>> + 'static>> { + let schema = schema.map(ToOwned::to_owned); + let owned_map = attributes + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect::<HashMap<String, String>>(); + + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + let attributes = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v.as_str())) + .collect::<HashMap<&str, &str>>(); + + obj.lookup( + schema.as_ref().map(::std::borrow::Borrow::borrow), + attributes, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + fn clear<P: FnOnce(Result<(), glib::Error>) + 'static>( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + unsafe { + let hash_table = attribute_names_and_values(attributes); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn clear_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let _ = ffi::secret_service_clear_finish(_source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = clear_trampoline::<P>; + + ffi::secret_service_clear( + self.as_ref().to_glib_none().0, + schema.to_glib_none().0, + hash_table, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn clear_future( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { + let schema = schema.map(ToOwned::to_owned); + let owned_map = attributes + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect::<HashMap<String, String>>(); + + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + let attributes = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v.as_str())) + .collect::<HashMap<&str, &str>>(); + obj.clear( + schema.as_ref().map(::std::borrow::Borrow::borrow), + attributes, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + fn create_item_dbus_path<P: FnOnce(Result<glib::GString, glib::Error>) + 'static>( + &self, + collection_path: &str, + properties: HashMap<&str, &glib::Variant>, + value: &Value, + flags: ItemCreateFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + unsafe { + let hash_table = attribute_names_and_properties(properties); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn create_item_dbus_path_trampoline< + P: FnOnce(Result<glib::GString, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let ret = ffi::secret_service_create_item_dbus_path_finish( + _source_object as *mut _, + res, + &mut error, + ); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = create_item_dbus_path_trampoline::<P>; + + ffi::secret_service_create_item_dbus_path( + self.as_ref().to_glib_none().0, + collection_path.to_glib_none().0, + hash_table, + value.to_glib_none().0, + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn create_item_dbus_path_future( + &self, + collection_path: &str, + properties: HashMap<&str, &glib::Variant>, + value: &Value, + flags: ItemCreateFlags, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<glib::GString, glib::Error>> + 'static>> + { + let collection_path = String::from(collection_path); + let value = value.clone(); + let owned_map = properties + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_owned())) + .collect::<HashMap<String, glib::Variant>>(); + + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + let properties = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v)) + .collect::<HashMap<&str, &glib::Variant>>(); + obj.create_item_dbus_path( + &collection_path, + properties, + &value, + flags, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + fn create_collection_dbus_path<P: FnOnce(Result<glib::GString, glib::Error>) + 'static>( + &self, + properties: HashMap<&str, &glib::Variant>, + alias: Option<&str>, + flags: CollectionCreateFlags, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + unsafe { + let hash_table = attribute_names_and_properties(properties); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn create_collection_dbus_path_trampoline< + P: FnOnce(Result<glib::GString, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let ret = ffi::secret_service_create_collection_dbus_path_finish( + _source_object as *mut _, + res, + &mut error, + ); + let result = if error.is_null() { + Ok(from_glib_full(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = create_collection_dbus_path_trampoline::<P>; + + ffi::secret_service_create_collection_dbus_path( + self.as_ref().to_glib_none().0, + hash_table, + alias.to_glib_none().0, + flags.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn create_collection_dbus_path_future( + &self, + properties: HashMap<&str, &glib::Variant>, + alias: Option<&str>, + flags: CollectionCreateFlags, + ) -> Pin<Box_<dyn std::future::Future<Output = Result<glib::GString, glib::Error>> + 'static>> + { + let alias = alias.map(ToOwned::to_owned); + let owned_map = properties + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_owned())) + .collect::<HashMap<String, glib::Variant>>(); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + let properties = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v)) + .collect::<HashMap<&str, &glib::Variant>>(); + obj.create_collection_dbus_path( + properties, + alias.as_ref().map(::std::borrow::Borrow::borrow), + flags, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + fn secrets_for_dbus_paths<P: FnOnce(Result<HashMap<String, Value>, glib::Error>) + 'static>( + &self, + item_paths: &str, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + unsafe { + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn secrets_for_dbus_paths_trampoline< + P: FnOnce(Result<HashMap<String, Value>, glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let ret = ffi::secret_service_get_secrets_for_dbus_paths_finish( + _source_object as *mut _, + res, + &mut error, + ); + + let result = if error.is_null() { + Ok(crate::hashtable::hash_map_from_glib_none(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = secrets_for_dbus_paths_trampoline::<P>; + + let mut item_paths = item_paths.to_string(); + ffi::secret_service_get_secrets_for_dbus_paths( + self.as_ref().to_glib_none().0, + &mut item_paths as *mut _ as *mut *const libc::c_char, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn secrets_for_dbus_paths_future( + &self, + item_paths: &str, + ) -> Pin< + Box_< + dyn std::future::Future<Output = Result<HashMap<String, Value>, glib::Error>> + 'static, + >, + > { + let item_paths = String::from(item_paths); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.secrets_for_dbus_paths(&item_paths, Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + + fn search_for_dbus_paths< + P: FnOnce(Result<(Vec<glib::GString>, Vec<glib::GString>), glib::Error>) + 'static, + >( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + cancellable: Option<&impl IsA<gio::Cancellable>>, + callback: P, + ) { + unsafe { + let hash_table = attribute_names_and_values(attributes); + + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn search_for_dbus_paths_trampoline< + P: FnOnce(Result<(Vec<glib::GString>, Vec<glib::GString>), glib::Error>) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let mut unlocked = ptr::null_mut(); + let mut locked = ptr::null_mut(); + let _ = ffi::secret_service_search_for_dbus_paths_finish( + _source_object as *mut _, + res, + &mut unlocked, + &mut locked, + &mut error, + ); + let result = if error.is_null() { + Ok(( + FromGlibPtrContainer::from_glib_full(unlocked), + FromGlibPtrContainer::from_glib_full(locked), + )) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = search_for_dbus_paths_trampoline::<P>; + + ffi::secret_service_search_for_dbus_paths( + self.as_ref().to_glib_none().0, + schema.to_glib_none().0, + hash_table, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + fn search_for_dbus_paths_future( + &self, + schema: Option<&Schema>, + attributes: HashMap<&str, &str>, + ) -> Pin< + Box_< + dyn std::future::Future< + Output = Result<(Vec<glib::GString>, Vec<glib::GString>), glib::Error>, + > + 'static, + >, + > { + let schema = schema.map(ToOwned::to_owned); + let owned_map = attributes + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect::<HashMap<String, String>>(); + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + let attributes = owned_map + .iter() + .map(|(k, v)| (k.as_str(), v.as_str())) + .collect::<HashMap<&str, &str>>(); + obj.search_for_dbus_paths( + schema.as_ref().map(::std::borrow::Borrow::borrow), + attributes, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } +} diff --git a/libsecret/src/value.rs b/libsecret/src/value.rs new file mode 100644 index 0000000..ef43da8 --- /dev/null +++ b/libsecret/src/value.rs @@ -0,0 +1,67 @@ +use glib::translate::*; +use std::mem; +use std::os::raw::c_void; + +glib::wrapper! { + #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] + pub struct Value(Shared<ffi::SecretValue>); + + match fn { + ref => |ptr| ffi::secret_value_ref(ptr), + // Manual + unref => |ptr| ffi::secret_value_unref(ptr as *mut _ as *mut c_void), + type_ => || ffi::secret_value_get_type(), + } +} + +impl Value { + #[doc(alias = "secret_value_new")] + pub fn new(secret: &str, content_type: &str) -> Value { + let length = secret.len() as isize; + unsafe { + from_glib_full(ffi::secret_value_new( + secret.to_glib_none().0, + length, + content_type.to_glib_none().0, + )) + } + } + + #[doc(alias = "secret_value_get")] + pub fn get(&self) -> Vec<u8> { + unsafe { + let mut length = mem::MaybeUninit::uninit(); + let ret = FromGlibContainer::from_glib_none_num( + ffi::secret_value_get(self.to_glib_none().0, length.as_mut_ptr()), + length.assume_init() as _, + ); + ret + } + } + + #[doc(alias = "secret_value_get_content_type")] + #[doc(alias = "get_content_type")] + pub fn content_type(&self) -> glib::GString { + unsafe { from_glib_none(ffi::secret_value_get_content_type(self.to_glib_none().0)) } + } + + #[doc(alias = "secret_value_get_text")] + #[doc(alias = "get_text")] + pub fn text(&self) -> Option<glib::GString> { + unsafe { from_glib_none(ffi::secret_value_get_text(self.to_glib_none().0)) } + } + + #[cfg(any(feature = "v0_19", feature = "dox"))] + #[cfg_attr(feature = "dox", doc(cfg(feature = "v0_19")))] + #[doc(alias = "secret_value_unref_to_password")] + pub fn unref_to_password(&self) -> glib::GString { + unsafe { + let mut length = std::mem::MaybeUninit::uninit(); + let password = + ffi::secret_value_unref_to_password(self.to_glib_none().0, length.as_mut_ptr()); + length.assume_init(); + + from_glib_full(password) + } + } +} diff --git a/libsecret/sys/.cargo_vcs_info.json b/libsecret/sys/.cargo_vcs_info.json new file mode 100644 index 0000000..038c98b --- /dev/null +++ b/libsecret/sys/.cargo_vcs_info.json @@ -0,0 +1,6 @@ +{ + "git": { + "sha1": "124286ef3e4c68d8bb2d0f852fcc77d9a2f5229b" + }, + "path_in_vcs": "libsecret/sys" +} \ No newline at end of file diff --git a/libsecret/sys/Cargo.toml b/libsecret/sys/Cargo.toml new file mode 100644 index 0000000..5ed8b41 --- /dev/null +++ b/libsecret/sys/Cargo.toml @@ -0,0 +1,110 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2021" +name = "libsecret-sys" +version = "0.6.0" +build = "build.rs" +links = "secret" +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "ffi bindings of libsecret" +homepage = "https://world.pages.gitlab.gnome.org/Rust/libsecret-rs" +documentation = "https://world.pages.gitlab.gnome.org/Rust/libsecret-rs/stable/latest/docs/libsecret_sys" +readme = "README.md" +keywords = [ + "libsecret", + "dbus", + "secret", + "bindings", + "freedesktop", +] +categories = ["api-bindings"] +license = "MIT" +repository = "https://gitlab.gnome.org/World/Rust/libsecret-rs" + +[package.metadata.docs.rs] +features = [] +rustc-args = [ + "--cfg", + "docsrs", +] +rustdoc-args = [ + "--cfg", + "docsrs", + "--generate-link-to-definition", +] + +[package.metadata.system-deps.libsecret_1] +name = "libsecret-1" +version = "0.0" + +[package.metadata.system-deps.libsecret_1.v0_18] +version = "0.18" + +[package.metadata.system-deps.libsecret_1.v0_18_6] +version = "0.18.6" + +[package.metadata.system-deps.libsecret_1.v0_19] +version = "0.19" + +[package.metadata.system-deps.libsecret_1.v0_20] +version = "0.20" + +[package.metadata.system-deps.libsecret_1.v0_21] +version = "0.21" + +[package.metadata.system-deps.libsecret_1.v0_21_2] +version = "0.21.2" + +[lib] +name = "libsecret_sys" +path = "src/lib.rs" + +[[test]] +name = "abi" +path = "tests/abi.rs" + +[dependencies.gio-sys] +version = "0.20" + +[dependencies.glib-sys] +version = "0.20" + +[dependencies.gobject-sys] +version = "0.20" + +[dependencies.libc] +version = "0.2" + +[dev-dependencies.shell-words] +version = "1.0.0" + +[dev-dependencies.tempfile] +version = "3" + +[build-dependencies.pkg-config] +version = "0.3.7" + +[build-dependencies.system-deps] +version = "6" + +[features] +default = ["v0_18"] +v0_18 = [] +v0_18_6 = [] +v0_19 = ["v0_18_6"] +v0_20 = ["v0_19"] +v0_21 = ["v0_20"] +v0_21_2 = ["v0_21"] diff --git a/libsecret/sys/Cargo.toml.orig b/libsecret/sys/Cargo.toml.orig new file mode 100644 index 0000000..a3b0a0f --- /dev/null +++ b/libsecret/sys/Cargo.toml.orig @@ -0,0 +1,76 @@ +[package] +name = "libsecret-sys" +version = "0.6.0" +links = "secret" +build = "build.rs" +edition = "2021" +readme = "../../README.md" +license = "MIT" +repository = "https://gitlab.gnome.org/World/Rust/libsecret-rs" +documentation = "https://world.pages.gitlab.gnome.org/Rust/libsecret-rs/stable/latest/docs/libsecret_sys" +categories = ["api-bindings"] +description = "ffi bindings of libsecret" +homepage = "https://world.pages.gitlab.gnome.org/Rust/libsecret-rs" +keywords = ["libsecret", "dbus", "secret", "bindings", "freedesktop"] + +[package.metadata.docs.rs] +features = [] +rustc-args = ["--cfg", "docsrs"] +rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"] + +[package.metadata.system-deps.libsecret_1] +name = "libsecret-1" +version = "0.0" + +[package.metadata.system-deps.libsecret_1.v0_18] +version = "0.18" + +[package.metadata.system-deps.libsecret_1.v0_19] +version = "0.19" + +[package.metadata.system-deps.libsecret_1.v0_20] +version = "0.20" + +[package.metadata.system-deps.libsecret_1.v0_21] +version = "0.21" + +[package.metadata.system-deps.libsecret_1.v0_18_6] +version = "0.18.6" + +[package.metadata.system-deps.libsecret_1.v0_21_2] +version = "0.21.2" + +[dependencies] +libc = "0.2" + +[dependencies.gio-sys] +git = "https://github.com/gtk-rs/gtk-rs-core" +version = "0.20" +tag = "0.20.4" + +[dependencies.glib-sys] +git = "https://github.com/gtk-rs/gtk-rs-core" +version = "0.20" +tag = "0.20.4" + +[dependencies.gobject-sys] +git = "https://github.com/gtk-rs/gtk-rs-core" +version = "0.20" +tag = "0.20.4" + +[build-dependencies] +pkg-config = "0.3.7" +system-deps = "6" + +[dev-dependencies] +shell-words = "1.0.0" +tempfile = "3" + +[features] +default = ["v0_18"] +v0_18 = [] +v0_19 = ["v0_18_6"] +v0_20 = ["v0_19"] +v0_21 = ["v0_20"] +v0_18_6 = [] +v0_21_2 = ["v0_21"] diff --git a/libsecret/sys/Gir.toml b/libsecret/sys/Gir.toml new file mode 100644 index 0000000..772ef3c --- /dev/null +++ b/libsecret/sys/Gir.toml @@ -0,0 +1,17 @@ +[options] +work_mode = "sys" +library = "Secret" +version = "1" +girs_directories = ["../../gir-files", "../../"] +min_cfg_version = "0.1" +external_libraries = [ + "GLib", + "GObject", + "Gio", +] + +ignore = [ + "Secret.MAJOR_VERSION", + "Secret.MICRO_VERSION", + "Secret.MINOR_VERSION", +] \ No newline at end of file diff --git a/libsecret/sys/README.md b/libsecret/sys/README.md new file mode 100644 index 0000000..9a47559 --- /dev/null +++ b/libsecret/sys/README.md @@ -0,0 +1,10 @@ +# libsecret-rs + +The Rust bindings of [libsecret](https://gitlab.gnome.org/GNOME/libsecret). + +- Website: <https://gitlab.gnome.org/World/Rust/libsecret-rs/> + +# Documentation + +- libsecret: <https://world.pages.gitlab.gnome.org/Rust/libsecret-rs/stable/latest/docs/libsecret> +- libsecret_sys: <https://world.pages.gitlab.gnome.org/Rust/libsecret-rs/stable/latest/docs/libsecret_sys> diff --git a/libsecret/sys/build.rs b/libsecret/sys/build.rs new file mode 100644 index 0000000..fc0010a --- /dev/null +++ b/libsecret/sys/build.rs @@ -0,0 +1,18 @@ +// Generated by gir (https://github.com/gtk-rs/gir @ 4dd714f7f3b1) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git @ b9db716f1bb7) +// DO NOT EDIT + +#[cfg(not(docsrs))] +use std::process; + +#[cfg(docsrs)] +fn main() {} // prevent linking libraries to avoid documentation failure + +#[cfg(not(docsrs))] +fn main() { + if let Err(s) = system_deps::Config::new().probe() { + println!("cargo:warning={s}"); + process::exit(1); + } +} diff --git a/libsecret/sys/src/lib.rs b/libsecret/sys/src/lib.rs new file mode 100644 index 0000000..6f473ca --- /dev/null +++ b/libsecret/sys/src/lib.rs @@ -0,0 +1,1769 @@ +// Generated by gir (https://github.com/gtk-rs/gir @ 4dd714f7f3b1) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git @ b9db716f1bb7) +// DO NOT EDIT + +#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)] +#![allow( + clippy::approx_constant, + clippy::type_complexity, + clippy::unreadable_literal, + clippy::upper_case_acronyms +)] +#![cfg_attr(docsrs, feature(doc_cfg))] + +use gio_sys as gio; +use glib_sys as glib; +use gobject_sys as gobject; + +#[allow(unused_imports)] +use libc::{ + c_char, c_double, c_float, c_int, c_long, c_short, c_uchar, c_uint, c_ulong, c_ushort, c_void, + intptr_t, size_t, ssize_t, uintptr_t, FILE, +}; + +#[allow(unused_imports)] +use glib::{gboolean, gconstpointer, gpointer, GType}; + +// Enums +pub type SecretBackendFlags = c_int; +pub const SECRET_BACKEND_NONE: SecretBackendFlags = 0; +pub const SECRET_BACKEND_OPEN_SESSION: SecretBackendFlags = 2; +pub const SECRET_BACKEND_LOAD_COLLECTIONS: SecretBackendFlags = 4; + +pub type SecretError = c_int; +pub const SECRET_ERROR_PROTOCOL: SecretError = 1; +pub const SECRET_ERROR_IS_LOCKED: SecretError = 2; +pub const SECRET_ERROR_NO_SUCH_OBJECT: SecretError = 3; +pub const SECRET_ERROR_ALREADY_EXISTS: SecretError = 4; +pub const SECRET_ERROR_INVALID_FILE_FORMAT: SecretError = 5; +#[cfg(feature = "v0_21_2")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_21_2")))] +pub const SECRET_ERROR_MISMATCHED_SCHEMA: SecretError = 6; +#[cfg(feature = "v0_21_2")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_21_2")))] +pub const SECRET_ERROR_NO_MATCHING_ATTRIBUTE: SecretError = 7; +#[cfg(feature = "v0_21_2")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_21_2")))] +pub const SECRET_ERROR_WRONG_TYPE: SecretError = 8; +#[cfg(feature = "v0_21_2")] +#[cfg_attr(docsrs, doc(cfg(feature = "v0_21_2")))] +pub const SECRET_ERROR_EMPTY_TABLE: SecretError = 9; + +pub type SecretSchemaAttributeType = c_int; +pub const SECRET_SCHEMA_ATTRIBUTE_STRING: SecretSchemaAttributeType = 0; +pub const SECRET_SCHEMA_ATTRIBUTE_INTEGER: SecretSchemaAttributeType = 1; +pub const SECRET_SCHEMA_ATTRIBUTE_BOOLEAN: SecretSchemaAttributeType = 2; + +pub type SecretSchemaType = c_int; +pub const SECRET_SCHEMA_TYPE_NOTE: SecretSchemaType = 0; +pub const SECRET_SCHEMA_TYPE_COMPAT_NETWORK: SecretSchemaType = 1; + +// Constants +pub const SECRET_BACKEND_EXTENSION_POINT_NAME: &[u8] = b"secret-backend\0"; +pub const SECRET_COLLECTION_DEFAULT: &[u8] = b"default\0"; +pub const SECRET_COLLECTION_SESSION: &[u8] = b"session\0"; + +// Flags +pub type SecretCollectionCreateFlags = c_uint; +pub const SECRET_COLLECTION_CREATE_NONE: SecretCollectionCreateFlags = 0; + +pub type SecretCollectionFlags = c_uint; +pub const SECRET_COLLECTION_NONE: SecretCollectionFlags = 0; +pub const SECRET_COLLECTION_LOAD_ITEMS: SecretCollectionFlags = 2; + +pub type SecretItemCreateFlags = c_uint; +pub const SECRET_ITEM_CREATE_NONE: SecretItemCreateFlags = 0; +pub const SECRET_ITEM_CREATE_REPLACE: SecretItemCreateFlags = 2; + +pub type SecretItemFlags = c_uint; +pub const SECRET_ITEM_NONE: SecretItemFlags = 0; +pub const SECRET_ITEM_LOAD_SECRET: SecretItemFlags = 2; + +pub type SecretSchemaFlags = c_uint; +pub const SECRET_SCHEMA_NONE: SecretSchemaFlags = 0; +pub const SECRET_SCHEMA_DONT_MATCH_NAME: SecretSchemaFlags = 2; + +pub type SecretSearchFlags = c_uint; +pub const SECRET_SEARCH_NONE: SecretSearchFlags = 0; +pub const SECRET_SEARCH_ALL: SecretSearchFlags = 2; +pub const SECRET_SEARCH_UNLOCK: SecretSearchFlags = 4; +pub const SECRET_SEARCH_LOAD_SECRETS: SecretSearchFlags = 8; + +pub type SecretServiceFlags = c_uint; +pub const SECRET_SERVICE_NONE: SecretServiceFlags = 0; +pub const SECRET_SERVICE_OPEN_SESSION: SecretServiceFlags = 2; +pub const SECRET_SERVICE_LOAD_COLLECTIONS: SecretServiceFlags = 4; + +// Records +#[derive(Copy, Clone)] +#[repr(C)] +pub struct SecretBackendInterface { + pub parent_iface: gobject::GTypeInterface, + pub ensure_for_flags: Option< + unsafe extern "C" fn( + *mut SecretBackend, + SecretBackendFlags, + *mut gio::GCancellable, + gio::GAsyncReadyCallback, + gpointer, + ), + >, + pub ensure_for_flags_finish: Option< + unsafe extern "C" fn( + *mut SecretBackend, + *mut gio::GAsyncResult, + *mut *mut glib::GError, + ) -> gboolean, + >, + pub store: Option< + unsafe extern "C" fn( + *mut SecretBackend, + *const SecretSchema, + *mut glib::GHashTable, + *const c_char, + *const c_char, + *mut SecretValue, + *mut gio::GCancellable, + gio::GAsyncReadyCallback, + gpointer, + ), + >, + pub store_finish: Option< + unsafe extern "C" fn( + *mut SecretBackend, + *mut gio::GAsyncResult, + *mut *mut glib::GError, + ) -> gboolean, + >, + pub lookup: Option< + unsafe extern "C" fn( + *mut SecretBackend, + *const SecretSchema, + *mut glib::GHashTable, + *mut gio::GCancellable, + gio::GAsyncReadyCallback, + gpointer, + ), + >, + pub lookup_finish: Option< + unsafe extern "C" fn( + *mut SecretBackend, + *mut gio::GAsyncResult, + *mut *mut glib::GError, + ) -> *mut SecretValue, + >, + pub clear: Option< + unsafe extern "C" fn( + *mut SecretBackend, + *const SecretSchema, + *mut glib::GHashTable, + *mut gio::GCancellable, + gio::GAsyncReadyCallback, + gpointer, + ), + >, + pub clear_finish: Option< + unsafe extern "C" fn( + *mut SecretBackend, + *mut gio::GAsyncResult, + *mut *mut glib::GError, + ) -> gboolean, + >, + pub search: Option< + unsafe extern "C" fn( + *mut SecretBackend, + *const SecretSchema, + *mut glib::GHashTable, + SecretSearchFlags, + *mut gio::GCancellable, + gio::GAsyncReadyCallback, + gpointer, + ), + >, + pub search_finish: Option< + unsafe extern "C" fn( + *mut SecretBackend, + *mut gio::GAsyncResult, + *mut *mut glib::GError, + ) -> *mut glib::GList, + >, +} + +impl ::std::fmt::Debug for SecretBackendInterface { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("SecretBackendInterface @ {self:p}")) + .field("parent_iface", &self.parent_iface) + .field("ensure_for_flags", &self.ensure_for_flags) + .field("ensure_for_flags_finish", &self.ensure_for_flags_finish) + .field("store", &self.store) + .field("store_finish", &self.store_finish) + .field("lookup", &self.lookup) + .field("lookup_finish", &self.lookup_finish) + .field("clear", &self.clear) + .field("clear_finish", &self.clear_finish) + .field("search", &self.search) + .field("search_finish", &self.search_finish) + .finish() + } +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct SecretCollectionClass { + pub parent_class: gio::GDBusProxyClass, + pub padding: [gpointer; 8], +} + +impl ::std::fmt::Debug for SecretCollectionClass { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("SecretCollectionClass @ {self:p}")) + .field("parent_class", &self.parent_class) + .finish() + } +} + +#[repr(C)] +pub struct _SecretCollectionPrivate { + _data: [u8; 0], + _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, +} + +pub type SecretCollectionPrivate = _SecretCollectionPrivate; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct SecretItemClass { + pub parent_class: gio::GDBusProxyClass, + pub padding: [gpointer; 4], +} + +impl ::std::fmt::Debug for SecretItemClass { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("SecretItemClass @ {self:p}")) + .field("parent_class", &self.parent_class) + .finish() + } +} + +#[repr(C)] +pub struct _SecretItemPrivate { + _data: [u8; 0], + _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, +} + +pub type SecretItemPrivate = _SecretItemPrivate; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct SecretPromptClass { + pub parent_class: gio::GDBusProxyClass, + pub padding: [gpointer; 8], +} + +impl ::std::fmt::Debug for SecretPromptClass { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("SecretPromptClass @ {self:p}")) + .field("parent_class", &self.parent_class) + .finish() + } +} + +#[repr(C)] +pub struct _SecretPromptPrivate { + _data: [u8; 0], + _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, +} + +pub type SecretPromptPrivate = _SecretPromptPrivate; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct SecretRetrievableInterface { + pub parent_iface: gobject::GTypeInterface, + pub retrieve_secret: Option< + unsafe extern "C" fn( + *mut SecretRetrievable, + *mut gio::GCancellable, + gio::GAsyncReadyCallback, + gpointer, + ), + >, + pub retrieve_secret_finish: Option< + unsafe extern "C" fn( + *mut SecretRetrievable, + *mut gio::GAsyncResult, + *mut *mut glib::GError, + ) -> *mut SecretValue, + >, +} + +impl ::std::fmt::Debug for SecretRetrievableInterface { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("SecretRetrievableInterface @ {self:p}")) + .field("parent_iface", &self.parent_iface) + .field("retrieve_secret", &self.retrieve_secret) + .field("retrieve_secret_finish", &self.retrieve_secret_finish) + .finish() + } +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct SecretSchema { + pub name: *const c_char, + pub flags: SecretSchemaFlags, + pub attributes: [SecretSchemaAttribute; 32], + pub reserved: c_int, + pub reserved1: gpointer, + pub reserved2: gpointer, + pub reserved3: gpointer, + pub reserved4: gpointer, + pub reserved5: gpointer, + pub reserved6: gpointer, + pub reserved7: gpointer, +} + +impl ::std::fmt::Debug for SecretSchema { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("SecretSchema @ {self:p}")) + .field("name", &self.name) + .field("flags", &self.flags) + .field("attributes", &self.attributes) + .finish() + } +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct SecretSchemaAttribute { + pub name: *const c_char, + pub type_: SecretSchemaAttributeType, +} + +impl ::std::fmt::Debug for SecretSchemaAttribute { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("SecretSchemaAttribute @ {self:p}")) + .field("name", &self.name) + .field("type_", &self.type_) + .finish() + } +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct SecretServiceClass { + pub parent_class: gio::GDBusProxyClass, + pub collection_gtype: GType, + pub item_gtype: GType, + pub prompt_sync: Option< + unsafe extern "C" fn( + *mut SecretService, + *mut SecretPrompt, + *mut gio::GCancellable, + *const glib::GVariantType, + *mut *mut glib::GError, + ) -> *mut glib::GVariant, + >, + pub prompt_async: Option< + unsafe extern "C" fn( + *mut SecretService, + *mut SecretPrompt, + *const glib::GVariantType, + *mut gio::GCancellable, + gio::GAsyncReadyCallback, + gpointer, + ), + >, + pub prompt_finish: Option< + unsafe extern "C" fn( + *mut SecretService, + *mut gio::GAsyncResult, + *mut *mut glib::GError, + ) -> *mut glib::GVariant, + >, + pub get_collection_gtype: Option<unsafe extern "C" fn(*mut SecretService) -> GType>, + pub get_item_gtype: Option<unsafe extern "C" fn(*mut SecretService) -> GType>, + pub padding: [gpointer; 14], +} + +impl ::std::fmt::Debug for SecretServiceClass { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("SecretServiceClass @ {self:p}")) + .field("parent_class", &self.parent_class) + .field("collection_gtype", &self.collection_gtype) + .field("item_gtype", &self.item_gtype) + .field("prompt_sync", &self.prompt_sync) + .field("prompt_async", &self.prompt_async) + .field("prompt_finish", &self.prompt_finish) + .field("get_collection_gtype", &self.get_collection_gtype) + .field("get_item_gtype", &self.get_item_gtype) + .finish() + } +} + +#[repr(C)] +pub struct _SecretServicePrivate { + _data: [u8; 0], + _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, +} + +pub type SecretServicePrivate = _SecretServicePrivate; + +#[repr(C)] +pub struct SecretValue { + _data: [u8; 0], + _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, +} + +impl ::std::fmt::Debug for SecretValue { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("SecretValue @ {self:p}")).finish() + } +} + +// Classes +#[derive(Copy, Clone)] +#[repr(C)] +pub struct SecretCollection { + pub parent: gio::GDBusProxy, + pub pv: *mut SecretCollectionPrivate, +} + +impl ::std::fmt::Debug for SecretCollection { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("SecretCollection @ {self:p}")) + .field("parent", &self.parent) + .finish() + } +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct SecretItem { + pub parent_instance: gio::GDBusProxy, + pub pv: *mut SecretItemPrivate, +} + +impl ::std::fmt::Debug for SecretItem { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("SecretItem @ {self:p}")) + .field("parent_instance", &self.parent_instance) + .finish() + } +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct SecretPrompt { + pub parent_instance: gio::GDBusProxy, + pub pv: *mut SecretPromptPrivate, +} + +impl ::std::fmt::Debug for SecretPrompt { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("SecretPrompt @ {self:p}")) + .field("parent_instance", &self.parent_instance) + .finish() + } +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct SecretService { + pub parent: gio::GDBusProxy, + pub pv: *mut SecretServicePrivate, +} + +impl ::std::fmt::Debug for SecretService { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("SecretService @ {self:p}")) + .field("parent", &self.parent) + .finish() + } +} + +// Interfaces +#[repr(C)] +pub struct SecretBackend { + _data: [u8; 0], + _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, +} + +impl ::std::fmt::Debug for SecretBackend { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + write!(f, "SecretBackend @ {self:p}") + } +} + +#[repr(C)] +pub struct SecretRetrievable { + _data: [u8; 0], + _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, +} + +impl ::std::fmt::Debug for SecretRetrievable { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + write!(f, "SecretRetrievable @ {self:p}") + } +} + +#[link(name = "secret-1")] +extern "C" { + + //========================================================================= + // SecretBackendFlags + //========================================================================= + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_backend_flags_get_type() -> GType; + + //========================================================================= + // SecretError + //========================================================================= + pub fn secret_error_get_type() -> GType; + pub fn secret_error_get_quark() -> glib::GQuark; + + //========================================================================= + // SecretSchemaAttributeType + //========================================================================= + pub fn secret_schema_attribute_type_get_type() -> GType; + + //========================================================================= + // SecretSchemaType + //========================================================================= + #[cfg(feature = "v0_18_6")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))] + pub fn secret_schema_type_get_type() -> GType; + + //========================================================================= + // SecretCollectionCreateFlags + //========================================================================= + pub fn secret_collection_create_flags_get_type() -> GType; + + //========================================================================= + // SecretCollectionFlags + //========================================================================= + pub fn secret_collection_flags_get_type() -> GType; + + //========================================================================= + // SecretItemCreateFlags + //========================================================================= + pub fn secret_item_create_flags_get_type() -> GType; + + //========================================================================= + // SecretItemFlags + //========================================================================= + pub fn secret_item_flags_get_type() -> GType; + + //========================================================================= + // SecretSchemaFlags + //========================================================================= + pub fn secret_schema_flags_get_type() -> GType; + + //========================================================================= + // SecretSearchFlags + //========================================================================= + pub fn secret_search_flags_get_type() -> GType; + + //========================================================================= + // SecretServiceFlags + //========================================================================= + pub fn secret_service_flags_get_type() -> GType; + + //========================================================================= + // SecretSchema + //========================================================================= + pub fn secret_schema_get_type() -> GType; + pub fn secret_schema_new( + name: *const c_char, + flags: SecretSchemaFlags, + ... + ) -> *mut SecretSchema; + pub fn secret_schema_newv( + name: *const c_char, + flags: SecretSchemaFlags, + attribute_names_and_types: *mut glib::GHashTable, + ) -> *mut SecretSchema; + pub fn secret_schema_ref(schema: *mut SecretSchema) -> *mut SecretSchema; + pub fn secret_schema_unref(schema: *mut SecretSchema); + + //========================================================================= + // SecretSchemaAttribute + //========================================================================= + pub fn secret_schema_attribute_get_type() -> GType; + + //========================================================================= + // SecretValue + //========================================================================= + pub fn secret_value_get_type() -> GType; + pub fn secret_value_new( + secret: *const c_char, + length: ssize_t, + content_type: *const c_char, + ) -> *mut SecretValue; + pub fn secret_value_new_full( + secret: *mut c_char, + length: ssize_t, + content_type: *const c_char, + destroy: glib::GDestroyNotify, + ) -> *mut SecretValue; + pub fn secret_value_get(value: *mut SecretValue, length: *mut size_t) -> *const u8; + pub fn secret_value_get_content_type(value: *mut SecretValue) -> *const c_char; + pub fn secret_value_get_text(value: *mut SecretValue) -> *const c_char; + pub fn secret_value_ref(value: *mut SecretValue) -> *mut SecretValue; + pub fn secret_value_unref(value: gpointer); + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_value_unref_to_password( + value: *mut SecretValue, + length: *mut size_t, + ) -> *mut c_char; + + //========================================================================= + // SecretCollection + //========================================================================= + pub fn secret_collection_get_type() -> GType; + pub fn secret_collection_new_for_dbus_path_finish( + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut SecretCollection; + pub fn secret_collection_new_for_dbus_path_sync( + service: *mut SecretService, + collection_path: *const c_char, + flags: SecretCollectionFlags, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut SecretCollection; + pub fn secret_collection_create( + service: *mut SecretService, + label: *const c_char, + alias: *const c_char, + flags: SecretCollectionCreateFlags, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_collection_create_finish( + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut SecretCollection; + pub fn secret_collection_create_sync( + service: *mut SecretService, + label: *const c_char, + alias: *const c_char, + flags: SecretCollectionCreateFlags, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut SecretCollection; + pub fn secret_collection_for_alias( + service: *mut SecretService, + alias: *const c_char, + flags: SecretCollectionFlags, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_collection_for_alias_finish( + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut SecretCollection; + pub fn secret_collection_for_alias_sync( + service: *mut SecretService, + alias: *const c_char, + flags: SecretCollectionFlags, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut SecretCollection; + pub fn secret_collection_new_for_dbus_path( + service: *mut SecretService, + collection_path: *const c_char, + flags: SecretCollectionFlags, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_collection_delete( + self_: *mut SecretCollection, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_collection_delete_finish( + self_: *mut SecretCollection, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_collection_delete_sync( + self_: *mut SecretCollection, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_collection_get_created(self_: *mut SecretCollection) -> u64; + pub fn secret_collection_get_flags(self_: *mut SecretCollection) -> SecretCollectionFlags; + pub fn secret_collection_get_items(self_: *mut SecretCollection) -> *mut glib::GList; + pub fn secret_collection_get_label(self_: *mut SecretCollection) -> *mut c_char; + pub fn secret_collection_get_locked(self_: *mut SecretCollection) -> gboolean; + pub fn secret_collection_get_modified(self_: *mut SecretCollection) -> u64; + pub fn secret_collection_get_service(self_: *mut SecretCollection) -> *mut SecretService; + pub fn secret_collection_load_items( + self_: *mut SecretCollection, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_collection_load_items_finish( + self_: *mut SecretCollection, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_collection_load_items_sync( + self_: *mut SecretCollection, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_collection_refresh(self_: *mut SecretCollection); + pub fn secret_collection_search( + self_: *mut SecretCollection, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + flags: SecretSearchFlags, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_collection_search_finish( + self_: *mut SecretCollection, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut glib::GList; + pub fn secret_collection_search_for_dbus_paths( + collection: *mut SecretCollection, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_collection_search_for_dbus_paths_finish( + collection: *mut SecretCollection, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut *mut c_char; + pub fn secret_collection_search_for_dbus_paths_sync( + collection: *mut SecretCollection, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut *mut c_char; + pub fn secret_collection_search_sync( + self_: *mut SecretCollection, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + flags: SecretSearchFlags, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut glib::GList; + pub fn secret_collection_set_label( + self_: *mut SecretCollection, + label: *const c_char, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_collection_set_label_finish( + self_: *mut SecretCollection, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_collection_set_label_sync( + self_: *mut SecretCollection, + label: *const c_char, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + + //========================================================================= + // SecretItem + //========================================================================= + pub fn secret_item_get_type() -> GType; + pub fn secret_item_new_for_dbus_path_finish( + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut SecretItem; + pub fn secret_item_new_for_dbus_path_sync( + service: *mut SecretService, + item_path: *const c_char, + flags: SecretItemFlags, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut SecretItem; + pub fn secret_item_create( + collection: *mut SecretCollection, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + label: *const c_char, + value: *mut SecretValue, + flags: SecretItemCreateFlags, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_item_create_finish( + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut SecretItem; + pub fn secret_item_create_sync( + collection: *mut SecretCollection, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + label: *const c_char, + value: *mut SecretValue, + flags: SecretItemCreateFlags, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut SecretItem; + pub fn secret_item_load_secrets( + items: *mut glib::GList, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_item_load_secrets_finish( + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_item_load_secrets_sync( + items: *mut glib::GList, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_item_new_for_dbus_path( + service: *mut SecretService, + item_path: *const c_char, + flags: SecretItemFlags, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_item_delete( + self_: *mut SecretItem, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_item_delete_finish( + self_: *mut SecretItem, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_item_delete_sync( + self_: *mut SecretItem, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_item_get_attributes(self_: *mut SecretItem) -> *mut glib::GHashTable; + pub fn secret_item_get_created(self_: *mut SecretItem) -> u64; + pub fn secret_item_get_flags(self_: *mut SecretItem) -> SecretItemFlags; + pub fn secret_item_get_label(self_: *mut SecretItem) -> *mut c_char; + pub fn secret_item_get_locked(self_: *mut SecretItem) -> gboolean; + pub fn secret_item_get_modified(self_: *mut SecretItem) -> u64; + pub fn secret_item_get_schema_name(self_: *mut SecretItem) -> *mut c_char; + pub fn secret_item_get_secret(self_: *mut SecretItem) -> *mut SecretValue; + pub fn secret_item_get_service(self_: *mut SecretItem) -> *mut SecretService; + pub fn secret_item_load_secret( + self_: *mut SecretItem, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_item_load_secret_finish( + self_: *mut SecretItem, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_item_load_secret_sync( + self_: *mut SecretItem, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_item_refresh(self_: *mut SecretItem); + pub fn secret_item_set_attributes( + self_: *mut SecretItem, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_item_set_attributes_finish( + self_: *mut SecretItem, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_item_set_attributes_sync( + self_: *mut SecretItem, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_item_set_label( + self_: *mut SecretItem, + label: *const c_char, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_item_set_label_finish( + self_: *mut SecretItem, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_item_set_label_sync( + self_: *mut SecretItem, + label: *const c_char, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_item_set_secret( + self_: *mut SecretItem, + value: *mut SecretValue, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_item_set_secret_finish( + self_: *mut SecretItem, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_item_set_secret_sync( + self_: *mut SecretItem, + value: *mut SecretValue, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + + //========================================================================= + // SecretPrompt + //========================================================================= + pub fn secret_prompt_get_type() -> GType; + pub fn secret_prompt_perform( + self_: *mut SecretPrompt, + window_id: *const c_char, + return_type: *const glib::GVariantType, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_prompt_perform_finish( + self_: *mut SecretPrompt, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut glib::GVariant; + pub fn secret_prompt_perform_sync( + self_: *mut SecretPrompt, + window_id: *const c_char, + cancellable: *mut gio::GCancellable, + return_type: *const glib::GVariantType, + error: *mut *mut glib::GError, + ) -> *mut glib::GVariant; + pub fn secret_prompt_run( + self_: *mut SecretPrompt, + window_id: *const c_char, + cancellable: *mut gio::GCancellable, + return_type: *const glib::GVariantType, + error: *mut *mut glib::GError, + ) -> *mut glib::GVariant; + + //========================================================================= + // SecretService + //========================================================================= + pub fn secret_service_get_type() -> GType; + pub fn secret_service_disconnect(); + pub fn secret_service_get( + flags: SecretServiceFlags, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_get_finish( + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut SecretService; + pub fn secret_service_get_sync( + flags: SecretServiceFlags, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut SecretService; + pub fn secret_service_open( + service_gtype: GType, + service_bus_name: *const c_char, + flags: SecretServiceFlags, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_open_finish( + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut SecretService; + pub fn secret_service_open_sync( + service_gtype: GType, + service_bus_name: *const c_char, + flags: SecretServiceFlags, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut SecretService; + pub fn secret_service_clear( + service: *mut SecretService, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_clear_finish( + service: *mut SecretService, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_service_clear_sync( + service: *mut SecretService, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_service_create_collection_dbus_path( + self_: *mut SecretService, + properties: *mut glib::GHashTable, + alias: *const c_char, + flags: SecretCollectionCreateFlags, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_create_collection_dbus_path_finish( + self_: *mut SecretService, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut c_char; + pub fn secret_service_create_collection_dbus_path_sync( + self_: *mut SecretService, + properties: *mut glib::GHashTable, + alias: *const c_char, + flags: SecretCollectionCreateFlags, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut c_char; + pub fn secret_service_create_item_dbus_path( + self_: *mut SecretService, + collection_path: *const c_char, + properties: *mut glib::GHashTable, + value: *mut SecretValue, + flags: SecretItemCreateFlags, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_create_item_dbus_path_finish( + self_: *mut SecretService, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut c_char; + pub fn secret_service_create_item_dbus_path_sync( + self_: *mut SecretService, + collection_path: *const c_char, + properties: *mut glib::GHashTable, + value: *mut SecretValue, + flags: SecretItemCreateFlags, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut c_char; + pub fn secret_service_decode_dbus_secret( + service: *mut SecretService, + value: *mut glib::GVariant, + ) -> *mut SecretValue; + pub fn secret_service_delete_item_dbus_path( + self_: *mut SecretService, + item_path: *const c_char, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_delete_item_dbus_path_finish( + self_: *mut SecretService, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_service_delete_item_dbus_path_sync( + self_: *mut SecretService, + item_path: *const c_char, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_service_encode_dbus_secret( + service: *mut SecretService, + value: *mut SecretValue, + ) -> *mut glib::GVariant; + pub fn secret_service_ensure_session( + self_: *mut SecretService, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_ensure_session_finish( + self_: *mut SecretService, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_service_ensure_session_sync( + self_: *mut SecretService, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_service_get_collection_gtype(self_: *mut SecretService) -> GType; + pub fn secret_service_get_collections(self_: *mut SecretService) -> *mut glib::GList; + pub fn secret_service_get_flags(self_: *mut SecretService) -> SecretServiceFlags; + pub fn secret_service_get_item_gtype(self_: *mut SecretService) -> GType; + pub fn secret_service_get_secret_for_dbus_path( + self_: *mut SecretService, + item_path: *const c_char, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_get_secret_for_dbus_path_finish( + self_: *mut SecretService, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut SecretValue; + pub fn secret_service_get_secret_for_dbus_path_sync( + self_: *mut SecretService, + item_path: *const c_char, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut SecretValue; + pub fn secret_service_get_secrets_for_dbus_paths( + self_: *mut SecretService, + item_paths: *mut *const c_char, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_get_secrets_for_dbus_paths_finish( + self_: *mut SecretService, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut glib::GHashTable; + pub fn secret_service_get_secrets_for_dbus_paths_sync( + self_: *mut SecretService, + item_paths: *mut *const c_char, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut glib::GHashTable; + pub fn secret_service_get_session_algorithms(self_: *mut SecretService) -> *const c_char; + pub fn secret_service_get_session_dbus_path(self_: *mut SecretService) -> *const c_char; + pub fn secret_service_load_collections( + self_: *mut SecretService, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_load_collections_finish( + self_: *mut SecretService, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_service_load_collections_sync( + self_: *mut SecretService, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_service_lock( + service: *mut SecretService, + objects: *mut glib::GList, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_lock_dbus_paths( + self_: *mut SecretService, + paths: *mut *const c_char, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_lock_dbus_paths_finish( + self_: *mut SecretService, + result: *mut gio::GAsyncResult, + locked: *mut *mut *mut c_char, + error: *mut *mut glib::GError, + ) -> c_int; + pub fn secret_service_lock_dbus_paths_sync( + self_: *mut SecretService, + paths: *mut *const c_char, + cancellable: *mut gio::GCancellable, + locked: *mut *mut *mut c_char, + error: *mut *mut glib::GError, + ) -> c_int; + pub fn secret_service_lock_finish( + service: *mut SecretService, + result: *mut gio::GAsyncResult, + locked: *mut *mut glib::GList, + error: *mut *mut glib::GError, + ) -> c_int; + pub fn secret_service_lock_sync( + service: *mut SecretService, + objects: *mut glib::GList, + cancellable: *mut gio::GCancellable, + locked: *mut *mut glib::GList, + error: *mut *mut glib::GError, + ) -> c_int; + pub fn secret_service_lookup( + service: *mut SecretService, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_lookup_finish( + service: *mut SecretService, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut SecretValue; + pub fn secret_service_lookup_sync( + service: *mut SecretService, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut SecretValue; + pub fn secret_service_prompt( + self_: *mut SecretService, + prompt: *mut SecretPrompt, + return_type: *const glib::GVariantType, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_prompt_at_dbus_path( + self_: *mut SecretService, + prompt_path: *const c_char, + return_type: *const glib::GVariantType, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_prompt_at_dbus_path_finish( + self_: *mut SecretService, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut glib::GVariant; + pub fn secret_service_prompt_at_dbus_path_sync( + self_: *mut SecretService, + prompt_path: *const c_char, + cancellable: *mut gio::GCancellable, + return_type: *const glib::GVariantType, + error: *mut *mut glib::GError, + ) -> *mut glib::GVariant; + pub fn secret_service_prompt_finish( + self_: *mut SecretService, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut glib::GVariant; + pub fn secret_service_prompt_sync( + self_: *mut SecretService, + prompt: *mut SecretPrompt, + cancellable: *mut gio::GCancellable, + return_type: *const glib::GVariantType, + error: *mut *mut glib::GError, + ) -> *mut glib::GVariant; + pub fn secret_service_read_alias_dbus_path( + self_: *mut SecretService, + alias: *const c_char, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_read_alias_dbus_path_finish( + self_: *mut SecretService, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut c_char; + pub fn secret_service_read_alias_dbus_path_sync( + self_: *mut SecretService, + alias: *const c_char, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut c_char; + pub fn secret_service_search( + service: *mut SecretService, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + flags: SecretSearchFlags, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_search_finish( + service: *mut SecretService, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut glib::GList; + pub fn secret_service_search_for_dbus_paths( + self_: *mut SecretService, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_search_for_dbus_paths_finish( + self_: *mut SecretService, + result: *mut gio::GAsyncResult, + unlocked: *mut *mut *mut c_char, + locked: *mut *mut *mut c_char, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_service_search_for_dbus_paths_sync( + self_: *mut SecretService, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + cancellable: *mut gio::GCancellable, + unlocked: *mut *mut *mut c_char, + locked: *mut *mut *mut c_char, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_service_search_sync( + service: *mut SecretService, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + flags: SecretSearchFlags, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut glib::GList; + pub fn secret_service_set_alias( + service: *mut SecretService, + alias: *const c_char, + collection: *mut SecretCollection, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_set_alias_finish( + service: *mut SecretService, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_service_set_alias_sync( + service: *mut SecretService, + alias: *const c_char, + collection: *mut SecretCollection, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_service_set_alias_to_dbus_path( + self_: *mut SecretService, + alias: *const c_char, + collection_path: *const c_char, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_set_alias_to_dbus_path_finish( + self_: *mut SecretService, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_service_set_alias_to_dbus_path_sync( + self_: *mut SecretService, + alias: *const c_char, + collection_path: *const c_char, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_service_store( + service: *mut SecretService, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + collection: *const c_char, + label: *const c_char, + value: *mut SecretValue, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_store_finish( + service: *mut SecretService, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_service_store_sync( + service: *mut SecretService, + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + collection: *const c_char, + label: *const c_char, + value: *mut SecretValue, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_service_unlock( + service: *mut SecretService, + objects: *mut glib::GList, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_unlock_dbus_paths( + self_: *mut SecretService, + paths: *mut *const c_char, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_service_unlock_dbus_paths_finish( + self_: *mut SecretService, + result: *mut gio::GAsyncResult, + unlocked: *mut *mut *mut c_char, + error: *mut *mut glib::GError, + ) -> c_int; + pub fn secret_service_unlock_dbus_paths_sync( + self_: *mut SecretService, + paths: *mut *const c_char, + cancellable: *mut gio::GCancellable, + unlocked: *mut *mut *mut c_char, + error: *mut *mut glib::GError, + ) -> c_int; + pub fn secret_service_unlock_finish( + service: *mut SecretService, + result: *mut gio::GAsyncResult, + unlocked: *mut *mut glib::GList, + error: *mut *mut glib::GError, + ) -> c_int; + pub fn secret_service_unlock_sync( + service: *mut SecretService, + objects: *mut glib::GList, + cancellable: *mut gio::GCancellable, + unlocked: *mut *mut glib::GList, + error: *mut *mut glib::GError, + ) -> c_int; + + //========================================================================= + // SecretBackend + //========================================================================= + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_backend_get_type() -> GType; + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_backend_get( + flags: SecretBackendFlags, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_backend_get_finish( + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut SecretBackend; + + //========================================================================= + // SecretRetrievable + //========================================================================= + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_retrievable_get_type() -> GType; + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_retrievable_get_attributes( + self_: *mut SecretRetrievable, + ) -> *mut glib::GHashTable; + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_retrievable_get_created(self_: *mut SecretRetrievable) -> u64; + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_retrievable_get_label(self_: *mut SecretRetrievable) -> *mut c_char; + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_retrievable_get_modified(self_: *mut SecretRetrievable) -> u64; + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_retrievable_retrieve_secret( + self_: *mut SecretRetrievable, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_retrievable_retrieve_secret_finish( + self_: *mut SecretRetrievable, + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut SecretValue; + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_retrievable_retrieve_secret_sync( + self_: *mut SecretRetrievable, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut SecretValue; + + //========================================================================= + // Other functions + //========================================================================= + pub fn secret_attributes_build(schema: *const SecretSchema, ...) -> *mut glib::GHashTable; + //pub fn secret_attributes_buildv(schema: *const SecretSchema, va: /*Unimplemented*/va_list) -> *mut glib::GHashTable; + #[cfg(feature = "v0_21_2")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_21_2")))] + pub fn secret_attributes_validate( + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + error: *mut *mut glib::GError, + ) -> gboolean; + #[cfg(feature = "v0_18_6")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))] + pub fn secret_get_schema(type_: SecretSchemaType) -> *const SecretSchema; + pub fn secret_password_clear( + schema: *const SecretSchema, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ... + ); + pub fn secret_password_clear_finish( + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_password_clear_sync( + schema: *const SecretSchema, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ... + ) -> gboolean; + pub fn secret_password_clearv( + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + pub fn secret_password_clearv_sync( + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_password_free(password: *mut c_char); + pub fn secret_password_lookup( + schema: *const SecretSchema, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ... + ); + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_password_lookup_binary_finish( + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut SecretValue; + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_password_lookup_binary_sync( + schema: *const SecretSchema, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ... + ) -> *mut SecretValue; + pub fn secret_password_lookup_finish( + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut c_char; + pub fn secret_password_lookup_nonpageable_finish( + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut c_char; + pub fn secret_password_lookup_nonpageable_sync( + schema: *const SecretSchema, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ... + ) -> *mut c_char; + pub fn secret_password_lookup_sync( + schema: *const SecretSchema, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ... + ) -> *mut c_char; + pub fn secret_password_lookupv( + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_password_lookupv_binary_sync( + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut SecretValue; + pub fn secret_password_lookupv_nonpageable_sync( + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut c_char; + pub fn secret_password_lookupv_sync( + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut c_char; + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_password_search( + schema: *const SecretSchema, + flags: SecretSearchFlags, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ... + ); + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_password_search_finish( + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> *mut glib::GList; + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_password_search_sync( + schema: *const SecretSchema, + flags: SecretSearchFlags, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ... + ) -> *mut glib::GList; + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_password_searchv( + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + flags: SecretSearchFlags, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_password_searchv_sync( + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + flags: SecretSearchFlags, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> *mut glib::GList; + pub fn secret_password_store( + schema: *const SecretSchema, + collection: *const c_char, + label: *const c_char, + password: *const c_char, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ... + ); + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_password_store_binary( + schema: *const SecretSchema, + collection: *const c_char, + label: *const c_char, + value: *mut SecretValue, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ... + ); + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_password_store_binary_sync( + schema: *const SecretSchema, + collection: *const c_char, + label: *const c_char, + value: *mut SecretValue, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ... + ) -> gboolean; + pub fn secret_password_store_finish( + result: *mut gio::GAsyncResult, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_password_store_sync( + schema: *const SecretSchema, + collection: *const c_char, + label: *const c_char, + password: *const c_char, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ... + ) -> gboolean; + pub fn secret_password_storev( + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + collection: *const c_char, + label: *const c_char, + password: *const c_char, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_password_storev_binary( + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + collection: *const c_char, + label: *const c_char, + value: *mut SecretValue, + cancellable: *mut gio::GCancellable, + callback: gio::GAsyncReadyCallback, + user_data: gpointer, + ); + #[cfg(feature = "v0_19")] + #[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))] + pub fn secret_password_storev_binary_sync( + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + collection: *const c_char, + label: *const c_char, + value: *mut SecretValue, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_password_storev_sync( + schema: *const SecretSchema, + attributes: *mut glib::GHashTable, + collection: *const c_char, + label: *const c_char, + password: *const c_char, + cancellable: *mut gio::GCancellable, + error: *mut *mut glib::GError, + ) -> gboolean; + pub fn secret_password_wipe(password: *mut c_char); + +} diff --git a/libsecret/sys/tests/abi.rs b/libsecret/sys/tests/abi.rs new file mode 100644 index 0000000..591466e --- /dev/null +++ b/libsecret/sys/tests/abi.rs @@ -0,0 +1,405 @@ +// Generated by gir (https://github.com/gtk-rs/gir @ 4dd714f7f3b1) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git @ b9db716f1bb7) +// DO NOT EDIT + +#![cfg(unix)] + +use libsecret_sys::*; +use std::env; +use std::error::Error; +use std::ffi::OsString; +use std::mem::{align_of, size_of}; +use std::path::Path; +use std::process::{Command, Stdio}; +use std::str; +use tempfile::Builder; + +static PACKAGES: &[&str] = &["libsecret-1"]; + +#[derive(Clone, Debug)] +struct Compiler { + pub args: Vec<String>, +} + +impl Compiler { + pub fn new() -> Result<Self, Box<dyn Error>> { + let mut args = get_var("CC", "cc")?; + args.push("-Wno-deprecated-declarations".to_owned()); + // For _Generic + args.push("-std=c11".to_owned()); + // For %z support in printf when using MinGW. + args.push("-D__USE_MINGW_ANSI_STDIO".to_owned()); + args.extend(get_var("CFLAGS", "")?); + args.extend(get_var("CPPFLAGS", "")?); + args.extend(pkg_config_cflags(PACKAGES)?); + Ok(Self { args }) + } + + pub fn compile(&self, src: &Path, out: &Path) -> Result<(), Box<dyn Error>> { + let mut cmd = self.to_command(); + cmd.arg(src); + cmd.arg("-o"); + cmd.arg(out); + let status = cmd.spawn()?.wait()?; + if !status.success() { + return Err(format!("compilation command {cmd:?} failed, {status}").into()); + } + Ok(()) + } + + fn to_command(&self) -> Command { + let mut cmd = Command::new(&self.args[0]); + cmd.args(&self.args[1..]); + cmd + } +} + +fn get_var(name: &str, default: &str) -> Result<Vec<String>, Box<dyn Error>> { + match env::var(name) { + Ok(value) => Ok(shell_words::split(&value)?), + Err(env::VarError::NotPresent) => Ok(shell_words::split(default)?), + Err(err) => Err(format!("{name} {err}").into()), + } +} + +fn pkg_config_cflags(packages: &[&str]) -> Result<Vec<String>, Box<dyn Error>> { + if packages.is_empty() { + return Ok(Vec::new()); + } + let pkg_config = env::var_os("PKG_CONFIG").unwrap_or_else(|| OsString::from("pkg-config")); + let mut cmd = Command::new(pkg_config); + cmd.arg("--cflags"); + cmd.args(packages); + cmd.stderr(Stdio::inherit()); + let out = cmd.output()?; + if !out.status.success() { + let (status, stdout) = (out.status, String::from_utf8_lossy(&out.stdout)); + return Err(format!("command {cmd:?} failed, {status:?}\nstdout: {stdout}").into()); + } + let stdout = str::from_utf8(&out.stdout)?; + Ok(shell_words::split(stdout.trim())?) +} + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +struct Layout { + size: usize, + alignment: usize, +} + +#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)] +struct Results { + /// Number of successfully completed tests. + passed: usize, + /// Total number of failed tests (including those that failed to compile). + failed: usize, +} + +impl Results { + fn record_passed(&mut self) { + self.passed += 1; + } + fn record_failed(&mut self) { + self.failed += 1; + } + fn summary(&self) -> String { + format!("{} passed; {} failed", self.passed, self.failed) + } + fn expect_total_success(&self) { + if self.failed == 0 { + println!("OK: {}", self.summary()); + } else { + panic!("FAILED: {}", self.summary()); + }; + } +} + +#[test] +fn cross_validate_constants_with_c() { + let mut c_constants: Vec<(String, String)> = Vec::new(); + + for l in get_c_output("constant").unwrap().lines() { + let (name, value) = l.split_once(';').expect("Missing ';' separator"); + c_constants.push((name.to_owned(), value.to_owned())); + } + + let mut results = Results::default(); + + for ((rust_name, rust_value), (c_name, c_value)) in + RUST_CONSTANTS.iter().zip(c_constants.iter()) + { + if rust_name != c_name { + results.record_failed(); + eprintln!("Name mismatch:\nRust: {rust_name:?}\nC: {c_name:?}"); + continue; + } + + if rust_value != c_value { + results.record_failed(); + eprintln!( + "Constant value mismatch for {rust_name}\nRust: {rust_value:?}\nC: {c_value:?}", + ); + continue; + } + + results.record_passed(); + } + + results.expect_total_success(); +} + +#[test] +fn cross_validate_layout_with_c() { + let mut c_layouts = Vec::new(); + + for l in get_c_output("layout").unwrap().lines() { + let (name, value) = l.split_once(';').expect("Missing first ';' separator"); + let (size, alignment) = value.split_once(';').expect("Missing second ';' separator"); + let size = size.parse().expect("Failed to parse size"); + let alignment = alignment.parse().expect("Failed to parse alignment"); + c_layouts.push((name.to_owned(), Layout { size, alignment })); + } + + let mut results = Results::default(); + + for ((rust_name, rust_layout), (c_name, c_layout)) in RUST_LAYOUTS.iter().zip(c_layouts.iter()) + { + if rust_name != c_name { + results.record_failed(); + eprintln!("Name mismatch:\nRust: {rust_name:?}\nC: {c_name:?}"); + continue; + } + + if rust_layout != c_layout { + results.record_failed(); + eprintln!("Layout mismatch for {rust_name}\nRust: {rust_layout:?}\nC: {c_layout:?}",); + continue; + } + + results.record_passed(); + } + + results.expect_total_success(); +} + +fn get_c_output(name: &str) -> Result<String, Box<dyn Error>> { + let tmpdir = Builder::new().prefix("abi").tempdir()?; + let exe = tmpdir.path().join(name); + let c_file = Path::new("tests").join(name).with_extension("c"); + + let cc = Compiler::new().expect("configured compiler"); + cc.compile(&c_file, &exe)?; + + let mut cmd = Command::new(exe); + cmd.stderr(Stdio::inherit()); + let out = cmd.output()?; + if !out.status.success() { + let (status, stdout) = (out.status, String::from_utf8_lossy(&out.stdout)); + return Err(format!("command {cmd:?} failed, {status:?}\nstdout: {stdout}").into()); + } + + Ok(String::from_utf8(out.stdout)?) +} + +const RUST_LAYOUTS: &[(&str, Layout)] = &[ + ( + "SecretBackendFlags", + Layout { + size: size_of::<SecretBackendFlags>(), + alignment: align_of::<SecretBackendFlags>(), + }, + ), + ( + "SecretBackendInterface", + Layout { + size: size_of::<SecretBackendInterface>(), + alignment: align_of::<SecretBackendInterface>(), + }, + ), + ( + "SecretCollection", + Layout { + size: size_of::<SecretCollection>(), + alignment: align_of::<SecretCollection>(), + }, + ), + ( + "SecretCollectionClass", + Layout { + size: size_of::<SecretCollectionClass>(), + alignment: align_of::<SecretCollectionClass>(), + }, + ), + ( + "SecretCollectionCreateFlags", + Layout { + size: size_of::<SecretCollectionCreateFlags>(), + alignment: align_of::<SecretCollectionCreateFlags>(), + }, + ), + ( + "SecretCollectionFlags", + Layout { + size: size_of::<SecretCollectionFlags>(), + alignment: align_of::<SecretCollectionFlags>(), + }, + ), + ( + "SecretError", + Layout { + size: size_of::<SecretError>(), + alignment: align_of::<SecretError>(), + }, + ), + ( + "SecretItem", + Layout { + size: size_of::<SecretItem>(), + alignment: align_of::<SecretItem>(), + }, + ), + ( + "SecretItemClass", + Layout { + size: size_of::<SecretItemClass>(), + alignment: align_of::<SecretItemClass>(), + }, + ), + ( + "SecretItemCreateFlags", + Layout { + size: size_of::<SecretItemCreateFlags>(), + alignment: align_of::<SecretItemCreateFlags>(), + }, + ), + ( + "SecretItemFlags", + Layout { + size: size_of::<SecretItemFlags>(), + alignment: align_of::<SecretItemFlags>(), + }, + ), + ( + "SecretPrompt", + Layout { + size: size_of::<SecretPrompt>(), + alignment: align_of::<SecretPrompt>(), + }, + ), + ( + "SecretPromptClass", + Layout { + size: size_of::<SecretPromptClass>(), + alignment: align_of::<SecretPromptClass>(), + }, + ), + ( + "SecretRetrievableInterface", + Layout { + size: size_of::<SecretRetrievableInterface>(), + alignment: align_of::<SecretRetrievableInterface>(), + }, + ), + ( + "SecretSchema", + Layout { + size: size_of::<SecretSchema>(), + alignment: align_of::<SecretSchema>(), + }, + ), + ( + "SecretSchemaAttribute", + Layout { + size: size_of::<SecretSchemaAttribute>(), + alignment: align_of::<SecretSchemaAttribute>(), + }, + ), + ( + "SecretSchemaAttributeType", + Layout { + size: size_of::<SecretSchemaAttributeType>(), + alignment: align_of::<SecretSchemaAttributeType>(), + }, + ), + ( + "SecretSchemaFlags", + Layout { + size: size_of::<SecretSchemaFlags>(), + alignment: align_of::<SecretSchemaFlags>(), + }, + ), + ( + "SecretSchemaType", + Layout { + size: size_of::<SecretSchemaType>(), + alignment: align_of::<SecretSchemaType>(), + }, + ), + ( + "SecretSearchFlags", + Layout { + size: size_of::<SecretSearchFlags>(), + alignment: align_of::<SecretSearchFlags>(), + }, + ), + ( + "SecretService", + Layout { + size: size_of::<SecretService>(), + alignment: align_of::<SecretService>(), + }, + ), + ( + "SecretServiceClass", + Layout { + size: size_of::<SecretServiceClass>(), + alignment: align_of::<SecretServiceClass>(), + }, + ), + ( + "SecretServiceFlags", + Layout { + size: size_of::<SecretServiceFlags>(), + alignment: align_of::<SecretServiceFlags>(), + }, + ), +]; + +const RUST_CONSTANTS: &[(&str, &str)] = &[ + ("SECRET_BACKEND_EXTENSION_POINT_NAME", "secret-backend"), + ("(gint) SECRET_BACKEND_LOAD_COLLECTIONS", "4"), + ("(gint) SECRET_BACKEND_NONE", "0"), + ("(gint) SECRET_BACKEND_OPEN_SESSION", "2"), + ("(guint) SECRET_COLLECTION_CREATE_NONE", "0"), + ("SECRET_COLLECTION_DEFAULT", "default"), + ("(guint) SECRET_COLLECTION_LOAD_ITEMS", "2"), + ("(guint) SECRET_COLLECTION_NONE", "0"), + ("SECRET_COLLECTION_SESSION", "session"), + ("(gint) SECRET_ERROR_ALREADY_EXISTS", "4"), + ("(gint) SECRET_ERROR_EMPTY_TABLE", "9"), + ("(gint) SECRET_ERROR_INVALID_FILE_FORMAT", "5"), + ("(gint) SECRET_ERROR_IS_LOCKED", "2"), + ("(gint) SECRET_ERROR_MISMATCHED_SCHEMA", "6"), + ("(gint) SECRET_ERROR_NO_MATCHING_ATTRIBUTE", "7"), + ("(gint) SECRET_ERROR_NO_SUCH_OBJECT", "3"), + ("(gint) SECRET_ERROR_PROTOCOL", "1"), + ("(gint) SECRET_ERROR_WRONG_TYPE", "8"), + ("(guint) SECRET_ITEM_CREATE_NONE", "0"), + ("(guint) SECRET_ITEM_CREATE_REPLACE", "2"), + ("(guint) SECRET_ITEM_LOAD_SECRET", "2"), + ("(guint) SECRET_ITEM_NONE", "0"), + ("(gint) SECRET_SCHEMA_ATTRIBUTE_BOOLEAN", "2"), + ("(gint) SECRET_SCHEMA_ATTRIBUTE_INTEGER", "1"), + ("(gint) SECRET_SCHEMA_ATTRIBUTE_STRING", "0"), + ("(guint) SECRET_SCHEMA_DONT_MATCH_NAME", "2"), + ("(guint) SECRET_SCHEMA_NONE", "0"), + ("(gint) SECRET_SCHEMA_TYPE_COMPAT_NETWORK", "1"), + ("(gint) SECRET_SCHEMA_TYPE_NOTE", "0"), + ("(guint) SECRET_SEARCH_ALL", "2"), + ("(guint) SECRET_SEARCH_LOAD_SECRETS", "8"), + ("(guint) SECRET_SEARCH_NONE", "0"), + ("(guint) SECRET_SEARCH_UNLOCK", "4"), + ("(guint) SECRET_SERVICE_LOAD_COLLECTIONS", "4"), + ("(guint) SECRET_SERVICE_NONE", "0"), + ("(guint) SECRET_SERVICE_OPEN_SESSION", "2"), +]; diff --git a/libsecret/sys/tests/constant.c b/libsecret/sys/tests/constant.c new file mode 100644 index 0000000..ff0f600 --- /dev/null +++ b/libsecret/sys/tests/constant.c @@ -0,0 +1,69 @@ +// Generated by gir (https://github.com/gtk-rs/gir @ 4dd714f7f3b1) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git @ b9db716f1bb7) +// DO NOT EDIT + +#include "manual.h" +#include <stdio.h> + +#define PRINT_CONSTANT(CONSTANT_NAME) \ + printf("%s;", #CONSTANT_NAME); \ + printf(_Generic((CONSTANT_NAME), \ + char *: "%s", \ + const char *: "%s", \ + char: "%c", \ + signed char: "%hhd", \ + unsigned char: "%hhu", \ + short int: "%hd", \ + unsigned short int: "%hu", \ + int: "%d", \ + unsigned int: "%u", \ + long: "%ld", \ + unsigned long: "%lu", \ + long long: "%lld", \ + unsigned long long: "%llu", \ + float: "%f", \ + double: "%f", \ + long double: "%ld"), \ + CONSTANT_NAME); \ + printf("\n"); + +int main() { + PRINT_CONSTANT(SECRET_BACKEND_EXTENSION_POINT_NAME); + PRINT_CONSTANT((gint) SECRET_BACKEND_LOAD_COLLECTIONS); + PRINT_CONSTANT((gint) SECRET_BACKEND_NONE); + PRINT_CONSTANT((gint) SECRET_BACKEND_OPEN_SESSION); + PRINT_CONSTANT((guint) SECRET_COLLECTION_CREATE_NONE); + PRINT_CONSTANT(SECRET_COLLECTION_DEFAULT); + PRINT_CONSTANT((guint) SECRET_COLLECTION_LOAD_ITEMS); + PRINT_CONSTANT((guint) SECRET_COLLECTION_NONE); + PRINT_CONSTANT(SECRET_COLLECTION_SESSION); + PRINT_CONSTANT((gint) SECRET_ERROR_ALREADY_EXISTS); + PRINT_CONSTANT((gint) SECRET_ERROR_EMPTY_TABLE); + PRINT_CONSTANT((gint) SECRET_ERROR_INVALID_FILE_FORMAT); + PRINT_CONSTANT((gint) SECRET_ERROR_IS_LOCKED); + PRINT_CONSTANT((gint) SECRET_ERROR_MISMATCHED_SCHEMA); + PRINT_CONSTANT((gint) SECRET_ERROR_NO_MATCHING_ATTRIBUTE); + PRINT_CONSTANT((gint) SECRET_ERROR_NO_SUCH_OBJECT); + PRINT_CONSTANT((gint) SECRET_ERROR_PROTOCOL); + PRINT_CONSTANT((gint) SECRET_ERROR_WRONG_TYPE); + PRINT_CONSTANT((guint) SECRET_ITEM_CREATE_NONE); + PRINT_CONSTANT((guint) SECRET_ITEM_CREATE_REPLACE); + PRINT_CONSTANT((guint) SECRET_ITEM_LOAD_SECRET); + PRINT_CONSTANT((guint) SECRET_ITEM_NONE); + PRINT_CONSTANT((gint) SECRET_SCHEMA_ATTRIBUTE_BOOLEAN); + PRINT_CONSTANT((gint) SECRET_SCHEMA_ATTRIBUTE_INTEGER); + PRINT_CONSTANT((gint) SECRET_SCHEMA_ATTRIBUTE_STRING); + PRINT_CONSTANT((guint) SECRET_SCHEMA_DONT_MATCH_NAME); + PRINT_CONSTANT((guint) SECRET_SCHEMA_NONE); + PRINT_CONSTANT((gint) SECRET_SCHEMA_TYPE_COMPAT_NETWORK); + PRINT_CONSTANT((gint) SECRET_SCHEMA_TYPE_NOTE); + PRINT_CONSTANT((guint) SECRET_SEARCH_ALL); + PRINT_CONSTANT((guint) SECRET_SEARCH_LOAD_SECRETS); + PRINT_CONSTANT((guint) SECRET_SEARCH_NONE); + PRINT_CONSTANT((guint) SECRET_SEARCH_UNLOCK); + PRINT_CONSTANT((guint) SECRET_SERVICE_LOAD_COLLECTIONS); + PRINT_CONSTANT((guint) SECRET_SERVICE_NONE); + PRINT_CONSTANT((guint) SECRET_SERVICE_OPEN_SESSION); + return 0; +} diff --git a/libsecret/sys/tests/layout.c b/libsecret/sys/tests/layout.c new file mode 100644 index 0000000..37a6016 --- /dev/null +++ b/libsecret/sys/tests/layout.c @@ -0,0 +1,35 @@ +// Generated by gir (https://github.com/gtk-rs/gir @ 4dd714f7f3b1) +// from +// from gir-files (https://github.com/gtk-rs/gir-files.git @ b9db716f1bb7) +// DO NOT EDIT + +#include "manual.h" +#include <stdalign.h> +#include <stdio.h> + +int main() { + printf("%s;%zu;%zu\n", "SecretBackendFlags", sizeof(SecretBackendFlags), alignof(SecretBackendFlags)); + printf("%s;%zu;%zu\n", "SecretBackendInterface", sizeof(SecretBackendInterface), alignof(SecretBackendInterface)); + printf("%s;%zu;%zu\n", "SecretCollection", sizeof(SecretCollection), alignof(SecretCollection)); + printf("%s;%zu;%zu\n", "SecretCollectionClass", sizeof(SecretCollectionClass), alignof(SecretCollectionClass)); + printf("%s;%zu;%zu\n", "SecretCollectionCreateFlags", sizeof(SecretCollectionCreateFlags), alignof(SecretCollectionCreateFlags)); + printf("%s;%zu;%zu\n", "SecretCollectionFlags", sizeof(SecretCollectionFlags), alignof(SecretCollectionFlags)); + printf("%s;%zu;%zu\n", "SecretError", sizeof(SecretError), alignof(SecretError)); + printf("%s;%zu;%zu\n", "SecretItem", sizeof(SecretItem), alignof(SecretItem)); + printf("%s;%zu;%zu\n", "SecretItemClass", sizeof(SecretItemClass), alignof(SecretItemClass)); + printf("%s;%zu;%zu\n", "SecretItemCreateFlags", sizeof(SecretItemCreateFlags), alignof(SecretItemCreateFlags)); + printf("%s;%zu;%zu\n", "SecretItemFlags", sizeof(SecretItemFlags), alignof(SecretItemFlags)); + printf("%s;%zu;%zu\n", "SecretPrompt", sizeof(SecretPrompt), alignof(SecretPrompt)); + printf("%s;%zu;%zu\n", "SecretPromptClass", sizeof(SecretPromptClass), alignof(SecretPromptClass)); + printf("%s;%zu;%zu\n", "SecretRetrievableInterface", sizeof(SecretRetrievableInterface), alignof(SecretRetrievableInterface)); + printf("%s;%zu;%zu\n", "SecretSchema", sizeof(SecretSchema), alignof(SecretSchema)); + printf("%s;%zu;%zu\n", "SecretSchemaAttribute", sizeof(SecretSchemaAttribute), alignof(SecretSchemaAttribute)); + printf("%s;%zu;%zu\n", "SecretSchemaAttributeType", sizeof(SecretSchemaAttributeType), alignof(SecretSchemaAttributeType)); + printf("%s;%zu;%zu\n", "SecretSchemaFlags", sizeof(SecretSchemaFlags), alignof(SecretSchemaFlags)); + printf("%s;%zu;%zu\n", "SecretSchemaType", sizeof(SecretSchemaType), alignof(SecretSchemaType)); + printf("%s;%zu;%zu\n", "SecretSearchFlags", sizeof(SecretSearchFlags), alignof(SecretSearchFlags)); + printf("%s;%zu;%zu\n", "SecretService", sizeof(SecretService), alignof(SecretService)); + printf("%s;%zu;%zu\n", "SecretServiceClass", sizeof(SecretServiceClass), alignof(SecretServiceClass)); + printf("%s;%zu;%zu\n", "SecretServiceFlags", sizeof(SecretServiceFlags), alignof(SecretServiceFlags)); + return 0; +} diff --git a/libsecret/sys/tests/manual.h b/libsecret/sys/tests/manual.h new file mode 100644 index 0000000..2633804 --- /dev/null +++ b/libsecret/sys/tests/manual.h @@ -0,0 +1,3 @@ +// Feel free to edit this file, it won't be regenerated by gir generator unless removed. + +#include <libsecret/secret.h> diff --git a/src/lib.rs b/src/lib.rs index 37b54a5..a644411 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,24 +55,7 @@ impl App { let mut attrs = std::collections::HashMap::default(); attrs.insert(crate::secrets::TOKEN_KIND, crate::secrets::ACCESS_TOKEN); attrs - }, libsecret::SearchFlags::ALL).await - // SAFETY: the representation of `glib::Error` is the same, since we're - // building against the same C library, so while this is a safety crime, it's - // probably a minor one. - // - // Additionally I'm ensuring the original wrapper is forgotten in case it has - // a drop handler that decrements a reference counter or something. - // - // This is only a workaround for libsecret not being updated in time. - .map_err(|e| unsafe { - let ptr = e.as_ptr(); - std::mem::forget(e); - glib::translate::from_glib_full::<_, glib::Error>( - // We can't name the original type here. - #[allow(clippy::missing_transmute_annotations)] - std::mem::transmute::<_, *mut glib::ffi::GError>(ptr) - ) - })?; + }, libsecret::SearchFlags::ALL).await?; if retrievables.is_empty() { Ok(None) @@ -100,17 +83,7 @@ impl App { let micropub = crate::micropub::Client::new( http.clone(), micropub_uri, - retrievable.retrieve_secret_future().await - // SAFETY: see above - .map_err(|e| unsafe { - let ptr = e.as_ptr(); - std::mem::forget(e); - glib::translate::from_glib_full::<_, glib::Error>( - // We can't name the original type here. - #[allow(clippy::missing_transmute_annotations)] - std::mem::transmute::<_, *mut glib::ffi::GError>(ptr) - ) - })? + retrievable.retrieve_secret_future().await? .unwrap() .text() .unwrap() |