basic lightdm bindings made

This commit is contained in:
2020-04-23 21:49:16 +12:00
commit 7f91dc1164
76 changed files with 631810 additions and 0 deletions

32
lightdm-sys/Cargo.toml Normal file
View File

@@ -0,0 +1,32 @@
[package]
name = "light-dm-sys"
version = "0.0.1"
links = "light_dm"
build = "build.rs"
[package.metadata.docs.rs]
features = ["dox"]
[lib]
name = "light_dm_sys"
[dependencies]
libc = "0.2"
[dependencies.gio-sys]
git = "https://github.com/gtk-rs/sys"
[dependencies.gobject-sys]
git = "https://github.com/gtk-rs/sys"
[dependencies.glib-sys]
git = "https://github.com/gtk-rs/sys"
[build-dependencies]
pkg-config = "0.3.7"
[dev-dependencies]
shell-words = "0.1.0"
tempfile = "3"
[features]
dox = []

9
lightdm-sys/Gir.toml Normal file
View File

@@ -0,0 +1,9 @@
[options]
library = "LightDM"
version = "1"
target_path = "."
min_cfg_version = "1"
work_mode = "sys"
girs_dir = "../gir-files/"
external_libraries = ["Gio", "GObject", "GLib"]

82
lightdm-sys/build.rs Normal file
View File

@@ -0,0 +1,82 @@
// This file was generated by gir (https://github.com/gtk-rs/gir @ 2abca11)
// from gir-files (https://github.com/gtk-rs/gir-files @ b89185a)
// DO NOT EDIT
#[cfg(not(feature = "dox"))]
extern crate pkg_config;
#[cfg(not(feature = "dox"))]
use pkg_config::{Config, Error};
#[cfg(not(feature = "dox"))]
use std::env;
#[cfg(not(feature = "dox"))]
use std::io;
#[cfg(not(feature = "dox"))]
use std::io::prelude::*;
#[cfg(not(feature = "dox"))]
use std::process;
#[cfg(feature = "dox")]
fn main() {} // prevent linking libraries to avoid documentation failure
#[cfg(not(feature = "dox"))]
fn main() {
if let Err(s) = find() {
let _ = writeln!(io::stderr(), "{}", s);
process::exit(1);
}
}
#[cfg(not(feature = "dox"))]
fn find() -> Result<(), Error> {
let package_name = "liblightdm-gobject-1";
let shared_libs = ["lightdm-gobject-1"];
let version = { "1" };
if let Ok(inc_dir) = env::var("GTK_INCLUDE_DIR") {
println!("cargo:include={}", inc_dir);
}
if let Ok(lib_dir) = env::var("GTK_LIB_DIR") {
for lib_ in shared_libs.iter() {
println!("cargo:rustc-link-lib=dylib={}", lib_);
}
println!("cargo:rustc-link-search=native={}", lib_dir);
return Ok(());
}
let target = env::var("TARGET").expect("TARGET environment variable doesn't exist");
let hardcode_shared_libs = target.contains("windows");
let mut config = Config::new();
config.atleast_version(version);
config.print_system_libs(false);
if hardcode_shared_libs {
config.cargo_metadata(false);
}
match config.probe(package_name) {
Ok(library) => {
if let Ok(paths) = std::env::join_paths(library.include_paths) {
println!("cargo:include={}", paths.to_string_lossy());
}
if hardcode_shared_libs {
for lib_ in shared_libs.iter() {
println!("cargo:rustc-link-lib=dylib={}", lib_);
}
for path in library.link_paths.iter() {
println!(
"cargo:rustc-link-search=native={}",
path.to_str().expect("library path doesn't exist")
);
}
}
Ok(())
}
Err(Error::EnvNoPkgConfig(_)) | Err(Error::Command { .. }) => {
for lib_ in shared_libs.iter() {
println!("cargo:rustc-link-lib=dylib={}", lib_);
}
Ok(())
}
Err(err) => Err(err),
}
}

534
lightdm-sys/src/lib.rs Normal file
View File

@@ -0,0 +1,534 @@
// This file was generated by gir (https://github.com/gtk-rs/gir @ 2abca11)
// from gir-files (https://github.com/gtk-rs/gir-files @ b89185a)
// 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
)]
extern crate gio_sys as gio;
extern crate glib_sys as glib;
extern crate gobject_sys as gobject;
extern crate libc;
#[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, time_t, uintptr_t, FILE,
};
#[allow(unused_imports)]
use glib::{gboolean, gconstpointer, gpointer, GType};
// Enums
pub type LightDMGreeterError = c_int;
pub const LIGHTDM_GREETER_ERROR_COMMUNICATION_ERROR: LightDMGreeterError = 0;
pub const LIGHTDM_GREETER_ERROR_CONNECTION_FAILED: LightDMGreeterError = 1;
pub const LIGHTDM_GREETER_ERROR_SESSION_FAILED: LightDMGreeterError = 2;
pub const LIGHTDM_GREETER_ERROR_NO_AUTOLOGIN: LightDMGreeterError = 3;
pub const LIGHTDM_GREETER_ERROR_INVALID_USER: LightDMGreeterError = 4;
pub type LightDMMessageType = c_int;
pub const LIGHTDM_MESSAGE_TYPE_INFO: LightDMMessageType = 0;
pub const LIGHTDM_MESSAGE_TYPE_ERROR: LightDMMessageType = 1;
pub type LightDMPromptType = c_int;
pub const LIGHTDM_PROMPT_TYPE_QUESTION: LightDMPromptType = 0;
pub const LIGHTDM_PROMPT_TYPE_SECRET: LightDMPromptType = 1;
// Constants
pub const LIGHTDM_GREETER_SIGNAL_AUTHENTICATION_COMPLETE: *const c_char =
b"authentication-complete\0" as *const u8 as *const c_char;
pub const LIGHTDM_GREETER_SIGNAL_AUTOLOGIN_TIMER_EXPIRED: *const c_char =
b"autologin-timer-expired\0" as *const u8 as *const c_char;
pub const LIGHTDM_GREETER_SIGNAL_IDLE: *const c_char = b"idle\0" as *const u8 as *const c_char;
pub const LIGHTDM_GREETER_SIGNAL_RESET: *const c_char = b"reset\0" as *const u8 as *const c_char;
pub const LIGHTDM_GREETER_SIGNAL_SHOW_MESSAGE: *const c_char =
b"show-message\0" as *const u8 as *const c_char;
pub const LIGHTDM_GREETER_SIGNAL_SHOW_PROMPT: *const c_char =
b"show-prompt\0" as *const u8 as *const c_char;
pub const LIGHTDM_SIGNAL_USER_CHANGED: *const c_char = b"changed\0" as *const u8 as *const c_char;
pub const LIGHTDM_USER_LIST_SIGNAL_USER_ADDED: *const c_char =
b"user-added\0" as *const u8 as *const c_char;
pub const LIGHTDM_USER_LIST_SIGNAL_USER_CHANGED: *const c_char =
b"user-changed\0" as *const u8 as *const c_char;
pub const LIGHTDM_USER_LIST_SIGNAL_USER_REMOVED: *const c_char =
b"user-removed\0" as *const u8 as *const c_char;
// Records
#[repr(C)]
#[derive(Copy, Clone)]
pub struct LightDMGreeterClass {
pub parent_class: gobject::GObjectClass,
pub show_message:
Option<unsafe extern "C" fn(*mut LightDMGreeter, *const c_char, LightDMMessageType)>,
pub show_prompt:
Option<unsafe extern "C" fn(*mut LightDMGreeter, *const c_char, LightDMPromptType)>,
pub authentication_complete: Option<unsafe extern "C" fn(*mut LightDMGreeter)>,
pub autologin_timer_expired: Option<unsafe extern "C" fn(*mut LightDMGreeter)>,
pub idle: Option<unsafe extern "C" fn(*mut LightDMGreeter)>,
pub reset: Option<unsafe extern "C" fn(*mut LightDMGreeter)>,
pub reserved1: Option<unsafe extern "C" fn()>,
pub reserved2: Option<unsafe extern "C" fn()>,
pub reserved3: Option<unsafe extern "C" fn()>,
pub reserved4: Option<unsafe extern "C" fn()>,
}
impl ::std::fmt::Debug for LightDMGreeterClass {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct(&format!("LightDMGreeterClass @ {:?}", self as *const _))
.field("show_message", &self.show_message)
.field("show_prompt", &self.show_prompt)
.field("authentication_complete", &self.authentication_complete)
.field("autologin_timer_expired", &self.autologin_timer_expired)
.field("idle", &self.idle)
.field("reset", &self.reset)
.field("reserved1", &self.reserved1)
.field("reserved2", &self.reserved2)
.field("reserved3", &self.reserved3)
.field("reserved4", &self.reserved4)
.finish()
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct LightDMLanguageClass {
pub parent_class: gobject::GObjectClass,
pub reserved1: Option<unsafe extern "C" fn()>,
pub reserved2: Option<unsafe extern "C" fn()>,
pub reserved3: Option<unsafe extern "C" fn()>,
pub reserved4: Option<unsafe extern "C" fn()>,
pub reserved5: Option<unsafe extern "C" fn()>,
pub reserved6: Option<unsafe extern "C" fn()>,
}
impl ::std::fmt::Debug for LightDMLanguageClass {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct(&format!("LightDMLanguageClass @ {:?}", self as *const _))
.field("reserved1", &self.reserved1)
.field("reserved2", &self.reserved2)
.field("reserved3", &self.reserved3)
.field("reserved4", &self.reserved4)
.field("reserved5", &self.reserved5)
.field("reserved6", &self.reserved6)
.finish()
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct LightDMLayoutClass {
pub parent_class: gobject::GObjectClass,
pub reserved1: Option<unsafe extern "C" fn()>,
pub reserved2: Option<unsafe extern "C" fn()>,
pub reserved3: Option<unsafe extern "C" fn()>,
pub reserved4: Option<unsafe extern "C" fn()>,
pub reserved5: Option<unsafe extern "C" fn()>,
pub reserved6: Option<unsafe extern "C" fn()>,
}
impl ::std::fmt::Debug for LightDMLayoutClass {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct(&format!("LightDMLayoutClass @ {:?}", self as *const _))
.field("reserved1", &self.reserved1)
.field("reserved2", &self.reserved2)
.field("reserved3", &self.reserved3)
.field("reserved4", &self.reserved4)
.field("reserved5", &self.reserved5)
.field("reserved6", &self.reserved6)
.finish()
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct LightDMSessionClass {
pub parent_class: gobject::GObjectClass,
pub reserved1: Option<unsafe extern "C" fn()>,
pub reserved2: Option<unsafe extern "C" fn()>,
pub reserved3: Option<unsafe extern "C" fn()>,
pub reserved4: Option<unsafe extern "C" fn()>,
pub reserved5: Option<unsafe extern "C" fn()>,
pub reserved6: Option<unsafe extern "C" fn()>,
}
impl ::std::fmt::Debug for LightDMSessionClass {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct(&format!("LightDMSessionClass @ {:?}", self as *const _))
.field("reserved1", &self.reserved1)
.field("reserved2", &self.reserved2)
.field("reserved3", &self.reserved3)
.field("reserved4", &self.reserved4)
.field("reserved5", &self.reserved5)
.field("reserved6", &self.reserved6)
.finish()
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct LightDMUserClass {
pub parent_class: gobject::GObjectClass,
pub changed: Option<unsafe extern "C" fn(*mut LightDMUser)>,
pub reserved1: Option<unsafe extern "C" fn()>,
pub reserved2: Option<unsafe extern "C" fn()>,
pub reserved3: Option<unsafe extern "C" fn()>,
pub reserved4: Option<unsafe extern "C" fn()>,
pub reserved5: Option<unsafe extern "C" fn()>,
pub reserved6: Option<unsafe extern "C" fn()>,
}
impl ::std::fmt::Debug for LightDMUserClass {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct(&format!("LightDMUserClass @ {:?}", self as *const _))
.field("changed", &self.changed)
.field("reserved1", &self.reserved1)
.field("reserved2", &self.reserved2)
.field("reserved3", &self.reserved3)
.field("reserved4", &self.reserved4)
.field("reserved5", &self.reserved5)
.field("reserved6", &self.reserved6)
.finish()
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct LightDMUserListClass {
pub parent_class: gobject::GObjectClass,
pub user_added: Option<unsafe extern "C" fn(*mut LightDMUserList, *mut LightDMUser)>,
pub user_changed: Option<unsafe extern "C" fn(*mut LightDMUserList, *mut LightDMUser)>,
pub user_removed: Option<unsafe extern "C" fn(*mut LightDMUserList, *mut LightDMUser)>,
pub reserved1: Option<unsafe extern "C" fn()>,
pub reserved2: Option<unsafe extern "C" fn()>,
pub reserved3: Option<unsafe extern "C" fn()>,
pub reserved4: Option<unsafe extern "C" fn()>,
pub reserved5: Option<unsafe extern "C" fn()>,
pub reserved6: Option<unsafe extern "C" fn()>,
}
impl ::std::fmt::Debug for LightDMUserListClass {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct(&format!("LightDMUserListClass @ {:?}", self as *const _))
.field("user_added", &self.user_added)
.field("user_changed", &self.user_changed)
.field("user_removed", &self.user_removed)
.field("reserved1", &self.reserved1)
.field("reserved2", &self.reserved2)
.field("reserved3", &self.reserved3)
.field("reserved4", &self.reserved4)
.field("reserved5", &self.reserved5)
.field("reserved6", &self.reserved6)
.finish()
}
}
// Classes
#[repr(C)]
#[derive(Copy, Clone)]
pub struct LightDMGreeter {
pub parent_instance: gobject::GObject,
}
impl ::std::fmt::Debug for LightDMGreeter {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct(&format!("LightDMGreeter @ {:?}", self as *const _))
.field("parent_instance", &self.parent_instance)
.finish()
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct LightDMLanguage {
pub parent_instance: gobject::GObject,
}
impl ::std::fmt::Debug for LightDMLanguage {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct(&format!("LightDMLanguage @ {:?}", self as *const _))
.field("parent_instance", &self.parent_instance)
.finish()
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct LightDMLayout {
pub parent_instance: gobject::GObject,
}
impl ::std::fmt::Debug for LightDMLayout {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct(&format!("LightDMLayout @ {:?}", self as *const _))
.field("parent_instance", &self.parent_instance)
.finish()
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct LightDMSession {
pub parent_instance: gobject::GObject,
}
impl ::std::fmt::Debug for LightDMSession {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct(&format!("LightDMSession @ {:?}", self as *const _))
.field("parent_instance", &self.parent_instance)
.finish()
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct LightDMUser {
pub parent_instance: gobject::GObject,
}
impl ::std::fmt::Debug for LightDMUser {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct(&format!("LightDMUser @ {:?}", self as *const _))
.field("parent_instance", &self.parent_instance)
.finish()
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct LightDMUserList {
pub parent_instance: gobject::GObject,
}
impl ::std::fmt::Debug for LightDMUserList {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct(&format!("LightDMUserList @ {:?}", self as *const _))
.field("parent_instance", &self.parent_instance)
.finish()
}
}
extern "C" {
//=========================================================================
// LightDMGreeterError
//=========================================================================
pub fn lightdm_greeter_error_get_type() -> GType;
pub fn lightdm_greeter_error_quark() -> glib::GQuark;
//=========================================================================
// LightDMMessageType
//=========================================================================
pub fn lightdm_message_type_get_type() -> GType;
//=========================================================================
// LightDMPromptType
//=========================================================================
pub fn lightdm_prompt_type_get_type() -> GType;
//=========================================================================
// LightDMGreeter
//=========================================================================
pub fn lightdm_greeter_get_type() -> GType;
pub fn lightdm_greeter_new() -> *mut LightDMGreeter;
pub fn lightdm_greeter_authenticate(
greeter: *mut LightDMGreeter,
username: *const c_char,
error: *mut *mut glib::GError,
) -> gboolean;
pub fn lightdm_greeter_authenticate_as_guest(
greeter: *mut LightDMGreeter,
error: *mut *mut glib::GError,
) -> gboolean;
pub fn lightdm_greeter_authenticate_autologin(
greeter: *mut LightDMGreeter,
error: *mut *mut glib::GError,
) -> gboolean;
pub fn lightdm_greeter_authenticate_remote(
greeter: *mut LightDMGreeter,
session: *const c_char,
username: *const c_char,
error: *mut *mut glib::GError,
) -> gboolean;
pub fn lightdm_greeter_cancel_authentication(
greeter: *mut LightDMGreeter,
error: *mut *mut glib::GError,
) -> gboolean;
pub fn lightdm_greeter_cancel_autologin(greeter: *mut LightDMGreeter);
pub fn lightdm_greeter_connect_sync(
greeter: *mut LightDMGreeter,
error: *mut *mut glib::GError,
) -> gboolean;
pub fn lightdm_greeter_connect_to_daemon(
greeter: *mut LightDMGreeter,
cancellable: *mut gio::GCancellable,
callback: gio::GAsyncReadyCallback,
user_data: gpointer,
);
pub fn lightdm_greeter_connect_to_daemon_finish(
greeter: *mut LightDMGreeter,
result: *mut gio::GAsyncResult,
error: *mut *mut glib::GError,
) -> gboolean;
pub fn lightdm_greeter_connect_to_daemon_sync(
greeter: *mut LightDMGreeter,
error: *mut *mut glib::GError,
) -> gboolean;
pub fn lightdm_greeter_ensure_shared_data_dir(
greeter: *mut LightDMGreeter,
username: *const c_char,
cancellable: *mut gio::GCancellable,
callback: gio::GAsyncReadyCallback,
user_data: gpointer,
);
pub fn lightdm_greeter_ensure_shared_data_dir_finish(
greeter: *mut LightDMGreeter,
result: *mut gio::GAsyncResult,
error: *mut *mut glib::GError,
) -> *mut c_char;
pub fn lightdm_greeter_ensure_shared_data_dir_sync(
greeter: *mut LightDMGreeter,
username: *const c_char,
error: *mut *mut glib::GError,
) -> *mut c_char;
pub fn lightdm_greeter_get_authentication_user(greeter: *mut LightDMGreeter) -> *const c_char;
pub fn lightdm_greeter_get_autologin_guest_hint(greeter: *mut LightDMGreeter) -> gboolean;
pub fn lightdm_greeter_get_autologin_session_hint(
greeter: *mut LightDMGreeter,
) -> *const c_char;
pub fn lightdm_greeter_get_autologin_timeout_hint(greeter: *mut LightDMGreeter) -> c_int;
pub fn lightdm_greeter_get_autologin_user_hint(greeter: *mut LightDMGreeter) -> *const c_char;
pub fn lightdm_greeter_get_default_session_hint(greeter: *mut LightDMGreeter) -> *const c_char;
pub fn lightdm_greeter_get_has_guest_account_hint(greeter: *mut LightDMGreeter) -> gboolean;
pub fn lightdm_greeter_get_hide_users_hint(greeter: *mut LightDMGreeter) -> gboolean;
pub fn lightdm_greeter_get_hint(
greeter: *mut LightDMGreeter,
name: *const c_char,
) -> *const c_char;
pub fn lightdm_greeter_get_in_authentication(greeter: *mut LightDMGreeter) -> gboolean;
pub fn lightdm_greeter_get_is_authenticated(greeter: *mut LightDMGreeter) -> gboolean;
pub fn lightdm_greeter_get_lock_hint(greeter: *mut LightDMGreeter) -> gboolean;
pub fn lightdm_greeter_get_select_guest_hint(greeter: *mut LightDMGreeter) -> gboolean;
pub fn lightdm_greeter_get_select_user_hint(greeter: *mut LightDMGreeter) -> *const c_char;
pub fn lightdm_greeter_get_show_manual_login_hint(greeter: *mut LightDMGreeter) -> gboolean;
pub fn lightdm_greeter_get_show_remote_login_hint(greeter: *mut LightDMGreeter) -> gboolean;
pub fn lightdm_greeter_respond(
greeter: *mut LightDMGreeter,
response: *const c_char,
error: *mut *mut glib::GError,
) -> gboolean;
pub fn lightdm_greeter_set_language(
greeter: *mut LightDMGreeter,
language: *const c_char,
error: *mut *mut glib::GError,
) -> gboolean;
pub fn lightdm_greeter_set_resettable(greeter: *mut LightDMGreeter, resettable: gboolean);
pub fn lightdm_greeter_start_session(
greeter: *mut LightDMGreeter,
session: *const c_char,
cancellable: *mut gio::GCancellable,
callback: gio::GAsyncReadyCallback,
user_data: gpointer,
);
pub fn lightdm_greeter_start_session_finish(
greeter: *mut LightDMGreeter,
result: *mut gio::GAsyncResult,
error: *mut *mut glib::GError,
) -> gboolean;
pub fn lightdm_greeter_start_session_sync(
greeter: *mut LightDMGreeter,
session: *const c_char,
error: *mut *mut glib::GError,
) -> gboolean;
//=========================================================================
// LightDMLanguage
//=========================================================================
pub fn lightdm_language_get_type() -> GType;
pub fn lightdm_language_get_code(language: *mut LightDMLanguage) -> *const c_char;
pub fn lightdm_language_get_name(language: *mut LightDMLanguage) -> *const c_char;
pub fn lightdm_language_get_territory(language: *mut LightDMLanguage) -> *const c_char;
pub fn lightdm_language_matches(
language: *mut LightDMLanguage,
code: *const c_char,
) -> gboolean;
//=========================================================================
// LightDMLayout
//=========================================================================
pub fn lightdm_layout_get_type() -> GType;
pub fn lightdm_layout_get_description(layout: *mut LightDMLayout) -> *const c_char;
pub fn lightdm_layout_get_name(layout: *mut LightDMLayout) -> *const c_char;
pub fn lightdm_layout_get_short_description(layout: *mut LightDMLayout) -> *const c_char;
//=========================================================================
// LightDMSession
//=========================================================================
pub fn lightdm_session_get_type() -> GType;
pub fn lightdm_session_get_comment(session: *mut LightDMSession) -> *const c_char;
pub fn lightdm_session_get_key(session: *mut LightDMSession) -> *const c_char;
pub fn lightdm_session_get_name(session: *mut LightDMSession) -> *const c_char;
pub fn lightdm_session_get_session_type(session: *mut LightDMSession) -> *const c_char;
//=========================================================================
// LightDMUser
//=========================================================================
pub fn lightdm_user_get_type() -> GType;
pub fn lightdm_user_get_background(user: *mut LightDMUser) -> *const c_char;
pub fn lightdm_user_get_display_name(user: *mut LightDMUser) -> *const c_char;
pub fn lightdm_user_get_has_messages(user: *mut LightDMUser) -> gboolean;
pub fn lightdm_user_get_home_directory(user: *mut LightDMUser) -> *const c_char;
pub fn lightdm_user_get_image(user: *mut LightDMUser) -> *const c_char;
pub fn lightdm_user_get_is_locked(user: *mut LightDMUser) -> gboolean;
pub fn lightdm_user_get_language(user: *mut LightDMUser) -> *const c_char;
pub fn lightdm_user_get_layout(user: *mut LightDMUser) -> *const c_char;
pub fn lightdm_user_get_layouts(user: *mut LightDMUser) -> *const *const c_char;
pub fn lightdm_user_get_logged_in(user: *mut LightDMUser) -> gboolean;
pub fn lightdm_user_get_name(user: *mut LightDMUser) -> *const c_char;
pub fn lightdm_user_get_real_name(user: *mut LightDMUser) -> *const c_char;
pub fn lightdm_user_get_session(user: *mut LightDMUser) -> *const c_char;
pub fn lightdm_user_get_uid(user: *mut LightDMUser) -> c_uint;
//=========================================================================
// LightDMUserList
//=========================================================================
pub fn lightdm_user_list_get_type() -> GType;
pub fn lightdm_user_list_get_instance() -> *mut LightDMUserList;
pub fn lightdm_user_list_get_length(user_list: *mut LightDMUserList) -> c_int;
pub fn lightdm_user_list_get_user_by_name(
user_list: *mut LightDMUserList,
username: *const c_char,
) -> *mut LightDMUser;
pub fn lightdm_user_list_get_users(user_list: *mut LightDMUserList) -> *mut glib::GList;
//=========================================================================
// Other functions
//=========================================================================
pub fn lightdm_get_can_hibernate() -> gboolean;
pub fn lightdm_get_can_restart() -> gboolean;
pub fn lightdm_get_can_shutdown() -> gboolean;
pub fn lightdm_get_can_suspend() -> gboolean;
pub fn lightdm_get_hostname() -> *const c_char;
pub fn lightdm_get_language() -> *mut LightDMLanguage;
pub fn lightdm_get_languages() -> *mut glib::GList;
pub fn lightdm_get_layout() -> *mut LightDMLayout;
pub fn lightdm_get_layouts() -> *mut glib::GList;
pub fn lightdm_get_motd() -> *mut c_char;
pub fn lightdm_get_os_id() -> *const c_char;
pub fn lightdm_get_os_name() -> *const c_char;
pub fn lightdm_get_os_pretty_name() -> *const c_char;
pub fn lightdm_get_os_version() -> *const c_char;
pub fn lightdm_get_os_version_id() -> *const c_char;
pub fn lightdm_get_remote_sessions() -> *mut glib::GList;
pub fn lightdm_get_sessions() -> *mut glib::GList;
pub fn lightdm_hibernate(error: *mut *mut glib::GError) -> gboolean;
pub fn lightdm_restart(error: *mut *mut glib::GError) -> gboolean;
pub fn lightdm_set_layout(layout: *mut LightDMLayout);
pub fn lightdm_shutdown(error: *mut *mut glib::GError) -> gboolean;
pub fn lightdm_suspend(error: *mut *mut glib::GError) -> gboolean;
}

388
lightdm-sys/tests/abi.rs Normal file
View File

@@ -0,0 +1,388 @@
// This file was generated by gir (https://github.com/gtk-rs/gir @ 2abca11)
// from gir-files (https://github.com/gtk-rs/gir-files @ b89185a)
// DO NOT EDIT
extern crate light_dm_sys;
extern crate shell_words;
extern crate tempfile;
use light_dm_sys::*;
use std::env;
use std::error::Error;
use std::mem::{align_of, size_of};
use std::path::Path;
use std::process::Command;
use std::str;
use tempfile::Builder;
static PACKAGES: &[&str] = &["liblightdm-gobject-1"];
#[derive(Clone, Debug)]
struct Compiler {
pub args: Vec<String>,
}
impl Compiler {
pub fn new() -> Result<Compiler, Box<dyn Error>> {
let mut args = get_var("CC", "cc")?;
args.push("-Wno-deprecated-declarations".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(Compiler { args })
}
pub fn define<'a, V: Into<Option<&'a str>>>(&mut self, var: &str, val: V) {
let arg = match val.into() {
None => format!("-D{}", var),
Some(val) => format!("-D{}={}", var, val),
};
self.args.push(arg);
}
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 {:?} failed, {}", &cmd, 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 mut cmd = Command::new("pkg-config");
cmd.arg("--cflags");
cmd.args(packages);
let out = cmd.output()?;
if !out.status.success() {
return Err(format!("command {:?} returned {}", &cmd, out.status).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,
/// Number of tests that failed to compile.
failed_to_compile: usize,
}
impl Results {
fn record_passed(&mut self) {
self.passed += 1;
}
fn record_failed(&mut self) {
self.failed += 1;
}
fn record_failed_to_compile(&mut self) {
self.failed += 1;
self.failed_to_compile += 1;
}
fn summary(&self) -> String {
format!(
"{} passed; {} failed (compilation errors: {})",
self.passed, self.failed, self.failed_to_compile
)
}
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 tmpdir = Builder::new()
.prefix("abi")
.tempdir()
.expect("temporary directory");
let cc = Compiler::new().expect("configured compiler");
assert_eq!(
"1",
get_c_value(tmpdir.path(), &cc, "1").expect("C constant"),
"failed to obtain correct constant value for 1"
);
let mut results: Results = Default::default();
for (i, &(name, rust_value)) in RUST_CONSTANTS.iter().enumerate() {
match get_c_value(tmpdir.path(), &cc, name) {
Err(e) => {
results.record_failed_to_compile();
eprintln!("{}", e);
}
Ok(ref c_value) => {
if rust_value == c_value {
results.record_passed();
} else {
results.record_failed();
eprintln!(
"Constant value mismatch for {}\nRust: {:?}\nC: {:?}",
name, rust_value, c_value
);
}
}
};
if (i + 1) % 25 == 0 {
println!("constants ... {}", results.summary());
}
}
results.expect_total_success();
}
#[test]
fn cross_validate_layout_with_c() {
let tmpdir = Builder::new()
.prefix("abi")
.tempdir()
.expect("temporary directory");
let cc = Compiler::new().expect("configured compiler");
assert_eq!(
Layout {
size: 1,
alignment: 1
},
get_c_layout(tmpdir.path(), &cc, "char").expect("C layout"),
"failed to obtain correct layout for char type"
);
let mut results: Results = Default::default();
for (i, &(name, rust_layout)) in RUST_LAYOUTS.iter().enumerate() {
match get_c_layout(tmpdir.path(), &cc, name) {
Err(e) => {
results.record_failed_to_compile();
eprintln!("{}", e);
}
Ok(c_layout) => {
if rust_layout == c_layout {
results.record_passed();
} else {
results.record_failed();
eprintln!(
"Layout mismatch for {}\nRust: {:?}\nC: {:?}",
name, rust_layout, &c_layout
);
}
}
};
if (i + 1) % 25 == 0 {
println!("layout ... {}", results.summary());
}
}
results.expect_total_success();
}
fn get_c_layout(dir: &Path, cc: &Compiler, name: &str) -> Result<Layout, Box<dyn Error>> {
let exe = dir.join("layout");
let mut cc = cc.clone();
cc.define("ABI_TYPE_NAME", name);
cc.compile(Path::new("tests/layout.c"), &exe)?;
let mut abi_cmd = Command::new(exe);
let output = abi_cmd.output()?;
if !output.status.success() {
return Err(format!("command {:?} failed, {:?}", &abi_cmd, &output).into());
}
let stdout = str::from_utf8(&output.stdout)?;
let mut words = stdout.trim().split_whitespace();
let size = words.next().unwrap().parse().unwrap();
let alignment = words.next().unwrap().parse().unwrap();
Ok(Layout { size, alignment })
}
fn get_c_value(dir: &Path, cc: &Compiler, name: &str) -> Result<String, Box<dyn Error>> {
let exe = dir.join("constant");
let mut cc = cc.clone();
cc.define("ABI_CONSTANT_NAME", name);
cc.compile(Path::new("tests/constant.c"), &exe)?;
let mut abi_cmd = Command::new(exe);
let output = abi_cmd.output()?;
if !output.status.success() {
return Err(format!("command {:?} failed, {:?}", &abi_cmd, &output).into());
}
let output = str::from_utf8(&output.stdout)?.trim();
if !output.starts_with("###gir test###") || !output.ends_with("###gir test###") {
return Err(format!(
"command {:?} return invalid output, {:?}",
&abi_cmd, &output
)
.into());
}
Ok(String::from(&output[14..(output.len() - 14)]))
}
const RUST_LAYOUTS: &[(&str, Layout)] = &[
(
"LightDMGreeter",
Layout {
size: size_of::<LightDMGreeter>(),
alignment: align_of::<LightDMGreeter>(),
},
),
(
"LightDMGreeterClass",
Layout {
size: size_of::<LightDMGreeterClass>(),
alignment: align_of::<LightDMGreeterClass>(),
},
),
(
"LightDMGreeterError",
Layout {
size: size_of::<LightDMGreeterError>(),
alignment: align_of::<LightDMGreeterError>(),
},
),
(
"LightDMLanguage",
Layout {
size: size_of::<LightDMLanguage>(),
alignment: align_of::<LightDMLanguage>(),
},
),
(
"LightDMLanguageClass",
Layout {
size: size_of::<LightDMLanguageClass>(),
alignment: align_of::<LightDMLanguageClass>(),
},
),
(
"LightDMLayout",
Layout {
size: size_of::<LightDMLayout>(),
alignment: align_of::<LightDMLayout>(),
},
),
(
"LightDMLayoutClass",
Layout {
size: size_of::<LightDMLayoutClass>(),
alignment: align_of::<LightDMLayoutClass>(),
},
),
(
"LightDMMessageType",
Layout {
size: size_of::<LightDMMessageType>(),
alignment: align_of::<LightDMMessageType>(),
},
),
(
"LightDMPromptType",
Layout {
size: size_of::<LightDMPromptType>(),
alignment: align_of::<LightDMPromptType>(),
},
),
(
"LightDMSession",
Layout {
size: size_of::<LightDMSession>(),
alignment: align_of::<LightDMSession>(),
},
),
(
"LightDMSessionClass",
Layout {
size: size_of::<LightDMSessionClass>(),
alignment: align_of::<LightDMSessionClass>(),
},
),
(
"LightDMUser",
Layout {
size: size_of::<LightDMUser>(),
alignment: align_of::<LightDMUser>(),
},
),
(
"LightDMUserClass",
Layout {
size: size_of::<LightDMUserClass>(),
alignment: align_of::<LightDMUserClass>(),
},
),
(
"LightDMUserList",
Layout {
size: size_of::<LightDMUserList>(),
alignment: align_of::<LightDMUserList>(),
},
),
(
"LightDMUserListClass",
Layout {
size: size_of::<LightDMUserListClass>(),
alignment: align_of::<LightDMUserListClass>(),
},
),
];
const RUST_CONSTANTS: &[(&str, &str)] = &[
("(gint) LIGHTDM_GREETER_ERROR_COMMUNICATION_ERROR", "0"),
("(gint) LIGHTDM_GREETER_ERROR_CONNECTION_FAILED", "1"),
("(gint) LIGHTDM_GREETER_ERROR_INVALID_USER", "4"),
("(gint) LIGHTDM_GREETER_ERROR_NO_AUTOLOGIN", "3"),
("(gint) LIGHTDM_GREETER_ERROR_SESSION_FAILED", "2"),
(
"LIGHTDM_GREETER_SIGNAL_AUTHENTICATION_COMPLETE",
"authentication-complete",
),
(
"LIGHTDM_GREETER_SIGNAL_AUTOLOGIN_TIMER_EXPIRED",
"autologin-timer-expired",
),
("LIGHTDM_GREETER_SIGNAL_IDLE", "idle"),
("LIGHTDM_GREETER_SIGNAL_RESET", "reset"),
("LIGHTDM_GREETER_SIGNAL_SHOW_MESSAGE", "show-message"),
("LIGHTDM_GREETER_SIGNAL_SHOW_PROMPT", "show-prompt"),
("(gint) LIGHTDM_MESSAGE_TYPE_ERROR", "1"),
("(gint) LIGHTDM_MESSAGE_TYPE_INFO", "0"),
("(gint) LIGHTDM_PROMPT_TYPE_QUESTION", "0"),
("(gint) LIGHTDM_PROMPT_TYPE_SECRET", "1"),
("LIGHTDM_SIGNAL_USER_CHANGED", "changed"),
("LIGHTDM_USER_LIST_SIGNAL_USER_ADDED", "user-added"),
("LIGHTDM_USER_LIST_SIGNAL_USER_CHANGED", "user-changed"),
("LIGHTDM_USER_LIST_SIGNAL_USER_REMOVED", "user-removed"),
];

View File

@@ -0,0 +1,27 @@
// This file was generated by gir (https://github.com/gtk-rs/gir @ 2abca11)
// from gir-files (https://github.com/gtk-rs/gir-files @ b89185a)
// DO NOT EDIT
#include "manual.h"
#include <stdio.h>
int main() {
printf(_Generic((ABI_CONSTANT_NAME),
char *: "###gir test###%s###gir test###\n",
const char *: "###gir test###%s###gir test###\n",
char: "###gir test###%c###gir test###\n",
signed char: "###gir test###%hhd###gir test###\n",
unsigned char: "###gir test###%hhu###gir test###\n",
short int: "###gir test###%hd###gir test###\n",
unsigned short int: "###gir test###%hu###gir test###\n",
int: "###gir test###%d###gir test###\n",
unsigned int: "###gir test###%u###gir test###\n",
long: "###gir test###%ld###gir test###\n",
unsigned long: "###gir test###%lu###gir test###\n",
long long: "###gir test###%lld###gir test###\n",
unsigned long long: "###gir test###%llu###gir test###\n",
double: "###gir test###%f###gir test###\n",
long double: "###gir test###%ld###gir test###\n"),
ABI_CONSTANT_NAME);
return 0;
}

View File

@@ -0,0 +1,12 @@
// This file was generated by gir (https://github.com/gtk-rs/gir @ 2abca11)
// from gir-files (https://github.com/gtk-rs/gir-files @ b89185a)
// DO NOT EDIT
#include "manual.h"
#include <stdalign.h>
#include <stdio.h>
int main() {
printf("%zu\n%zu", sizeof(ABI_TYPE_NAME), alignof(ABI_TYPE_NAME));
return 0;
}

View File

@@ -0,0 +1,3 @@
// Feel free to edit this file, it won't be regenerated by gir generator unless removed.
#include <lightdm.h>