From: Andrea Zagli Date: Thu, 1 Sep 2016 15:31:52 +0000 (+0200) Subject: Migration to libpeas. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=72ceefa3fa61cc0ebfcc2107aa37d161266edb2f;p=zakauthe%2Fplugins%2Fdb Migration to libpeas. --- diff --git a/configure.ac b/configure.ac index 0afd734..2719f0a 100644 --- a/configure.ac +++ b/configure.ac @@ -30,7 +30,7 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", AM_GLIB_GNU_GETTEXT # Checks for libraries. -PKG_CHECK_MODULES(LIBZAKAUTHEDB, [libzakauthe >= 0.5.0 +PKG_CHECK_MODULES(LIBZAKAUTHEDB, [libzakauthe >= 0.5.99 libzakform libzakformgtk libzakformgdaex]) diff --git a/src/Makefile.am b/src/Makefile.am index 0bf5786..a2cfbfb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ -guidir = $(datadir)/libzakauthedb/gui -formdir = $(datadir)/libzakauthedb/form +guidir = $(datadir)/$(PACKAGE)/gui +formdir = $(datadir)/$(PACKAGE)/form AM_CPPFLAGS = $(LIBZAKAUTHEDB_CFLAGS) \ $(LIBGCRYPT_CFLAGS) \ @@ -8,17 +8,17 @@ AM_CPPFLAGS = $(LIBZAKAUTHEDB_CFLAGS) \ -DGUIDIR=\""$(guidir)"\" \ -DFORMDIR=\""$(formdir)"\" -LIBS = $(LIBZAKAUTHEDB_LIBS) \ - $(LIBGCRYPT_LIBS) \ - $(GPG_ERROR_LIBS) \ - $(LIBZAKCONFI_LIBS) - -libzakauthe_pluginsdir = $(libdir)/libzakauthe/plugins +libzakauthe_pluginsdir = `pkg-config --variable=pluginsdir libzakauthe` libzakauthe_plugins_LTLIBRARIES = libzakauthedb.la +libzakauthe_plugins_DATA = zakauthedb.plugin libzakauthedb_la_SOURCES = aute_db.c \ aute_db.h \ user.c \ user.h -libzakauthedb_la_LDFLAGS = -no-undefined +libzakauthedb_la_LDFLAGS = -module -avoid-version -no-undefined +libzakauthedb_la_LIBADD = $(LIBZAKAUTHEDB_LIBS) \ + $(LIBGCRYPT_LIBS) \ + $(GPG_ERROR_LIBS) \ + $(LIBZAKCONFI_LIBS) diff --git a/src/aute_db.c b/src/aute_db.c index beee9bd..dd06410 100644 --- a/src/aute_db.c +++ b/src/aute_db.c @@ -22,14 +22,20 @@ #include #include + +#include + #include #include #include +#include + #ifdef HAVE_LIBZAKCONFI #include #endif +#include "aute_db.h" #include "user.h" static GtkBuilder *gtkbuilder; @@ -60,6 +66,30 @@ enum }; /* PRIVATE */ +static void zak_authe_pluggable_iface_init (ZakAuthePluggableInterface *iface); + +static void zak_authe_db_finalize (GObject *object); + +static gchar *zak_authe_db_authe_get_password (ZakAuthePluggable *pluggable, GSList *parameters, gchar **password); +static gchar *zak_authe_db_authe (ZakAuthePluggable *pluggable, GSList *parameters); +static gboolean zak_authe_db_authe_nogui (ZakAuthePluggable *pluggable, GSList *parameters, const gchar *username, const gchar *password, const gchar *new_password); +static GtkWidget *zak_authe_db_get_management_gui (ZakAuthePluggable *pluggable, GSList *parameters); + +#define ZAK_AUTHE_DB_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_AUTHE_TYPE_DB, ZakAutheDBPrivate)) + +typedef struct _ZakAutheDBPrivate ZakAutheDBPrivate; +struct _ZakAutheDBPrivate + { + gpointer empty; + }; + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (ZakAutheDB, + zak_authe_db, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (ZAK_AUTHE_TYPE_PLUGGABLE, + zak_authe_pluggable_iface_init)) + #ifdef G_OS_WIN32 static HMODULE backend_dll = NULL; @@ -84,6 +114,39 @@ DllMain (HINSTANCE hinstDLL, } #endif +static void +zak_authe_db_class_init (ZakAutheDBClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (ZakAutheDBPrivate)); + + object_class->finalize = zak_authe_db_finalize; +} + +static void +zak_authe_pluggable_iface_init (ZakAuthePluggableInterface *iface) +{ + iface->authe = zak_authe_db_authe; + iface->authe_get_password = zak_authe_db_authe_get_password; + iface->authe_nogui = zak_authe_db_authe_nogui; + iface->get_management_gui = zak_authe_db_get_management_gui; +} + +static void +zak_authe_db_init (ZakAutheDB *plugin) +{ + ZakAutheDBPrivate *priv = ZAK_AUTHE_DB_GET_PRIVATE (plugin); +} + +static void +zak_authe_db_finalize (GObject *object) +{ + ZakAutheDB *plugin = ZAK_AUTHE_DB (object); + + G_OBJECT_CLASS (zak_authe_db_parent_class)->finalize (object); +} + #ifdef HAVE_LIBZAKCONFI static gboolean get_connection_parameters_from_confi (ZakConfi *confi, gchar **cnc_string) @@ -413,15 +476,14 @@ autedb_on_btn_find_clicked (GtkButton *button, { } -/* PUBLIC */ -gchar -*zak_authe_plg_authe (GSList *parameters) +static gchar +*zak_authe_db_authe_get_password (ZakAuthePluggable *pluggable, GSList *parameters, gchar **password) { GError *error; gchar *ret = NULL; gchar *utente; - gchar *password; + gchar *_password; gchar *new_password; error = NULL; @@ -494,7 +556,7 @@ gchar { case GTK_RESPONSE_OK: /* controllo dell'utente e della password */ - password = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password)))); + _password = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password)))); utente = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_utente)))); new_password = NULL; if (gtk_expander_get_expanded (GTK_EXPANDER (exp_cambio))) @@ -508,7 +570,7 @@ gchar new_password = NULL; } } - ret = controllo (utente, password, new_password); + ret = controllo (utente, _password, new_password); break; case GTK_RESPONSE_CANCEL: @@ -521,22 +583,39 @@ gchar break; } + if (ret != NULL && g_strcmp0 (ret, "") != 0 && password != NULL && *password == NULL) + { + if (g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (txt_password_conferma)), "") != 0) + { + *password = g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password_conferma))); + } + else + { + *password = g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password))); + } + } + gtk_widget_destroy (diag); g_object_unref (gtkbuilder); return ret; } +static gchar +*zak_authe_db_authe (ZakAuthePluggable *pluggable, GSList *parameters) +{ + return zak_authe_db_authe_get_password (pluggable, parameters, NULL); +} /** - * zak_authe_plg_authe_nogui: + * zak_authe_db_authe_nogui: * @parameters: * @username: * @password: * @new_password: * */ -gboolean -zak_authe_plg_authe_nogui (GSList *parameters, const gchar *username, const gchar *password, const gchar *new_password) +static gboolean +zak_authe_db_authe_nogui (ZakAuthePluggable *pluggable, GSList *parameters, const gchar *username, const gchar *password, const gchar *new_password) { gboolean ret; @@ -570,8 +649,8 @@ zak_authe_plg_authe_nogui (GSList *parameters, const gchar *username, const gcha * @parameters: * */ -GtkWidget -*zak_authe_plg_get_management_gui (GSList *parameters) +static GtkWidget +*zak_authe_db_get_management_gui (ZakAuthePluggable *pluggable, GSList *parameters) { GError *error; @@ -622,3 +701,18 @@ GtkWidget return w_users; } + +static void +zak_authe_db_class_finalize (ZakAutheDBClass *klass) +{ +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + zak_authe_db_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + ZAK_AUTHE_TYPE_PLUGGABLE, + ZAK_AUTHE_TYPE_DB); +} diff --git a/src/aute_db.h b/src/aute_db.h index 50a2e70..7db9270 100644 --- a/src/aute_db.h +++ b/src/aute_db.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 Andrea Zagli + * Copyright (C) 2010-2016 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -20,9 +20,35 @@ #ifndef __ZAKAUTHEDB_H__ #define __ZAKAUTHEDB_H__ + +#include + + G_BEGIN_DECLS +#define ZAK_AUTHE_TYPE_DB (zak_authe_db_get_type ()) +#define ZAK_AUTHE_DB(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), ZAK_AUTHE_TYPE_DB, ZakAutheDB)) +#define ZAK_AUTHE_DB_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), ZAK_AUTHE_TYPE_DB, ZakAutheDB)) +#define ZAK_AUTHE_IS_DB(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), ZAK_AUTHE_TYPE_DB)) +#define ZAK_AUTHE_IS_DB_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), ZAK_AUTHE_TYPE_DB)) +#define ZAK_AUTHE_DB_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), ZAK_AUTHE_TYPE_DB, ZakAutheDBClass)) + +typedef struct _ZakAutheDB ZakAutheDB; +typedef struct _ZakAutheDBClass ZakAutheDBClass; + +struct _ZakAutheDB { + PeasExtensionBase parent_instance; +}; + +struct _ZakAutheDBClass { + PeasExtensionBaseClass parent_class; +}; + +GType zak_authe_db_get_type (void) G_GNUC_CONST; +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); + + gchar *zak_authe_db_encrypt_password (const gchar *password); diff --git a/src/zakauthedb.plugin b/src/zakauthedb.plugin new file mode 100644 index 0000000..b097224 --- /dev/null +++ b/src/zakauthedb.plugin @@ -0,0 +1,8 @@ +[Plugin] +Module=zakauthedb +Name=ZakAutheDB +Description=Read users from database (via libgdaex). +Authors=Andrea Zagli +Copyright=Copyright © 2016 Andrea Zagli +Website=http://saetta.ns0.it/ +Help=http://saetta.ns0.it/ diff --git a/tests/Makefile.am b/tests/Makefile.am index e3c4da2..49b928a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -8,8 +8,6 @@ LIBS = $(GTK_LIBS) \ $(LIBZAKAUTHEDB_LIBS) \ $(LIBZAKCONFI_LIBS) -LDADD = ../src/libzakauthedb.la - noinst_PROGRAMS = test \ test_confi \ test_nogui diff --git a/tests/test.c b/tests/test.c index 9a7ca61..1e94f8b 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 Andrea Zagli + * Copyright (C) 2010-2016 Andrea Zagli * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ #include -#include +#include int main (int argc, char **argv) @@ -32,7 +32,7 @@ main (int argc, char **argv) params = NULL; - /* the libaute module to use */ + /* the libzakauthe module to use */ params = g_slist_append (params, argv[1]); /* the libgda connection string */ params = g_slist_append (params, argv[2]); diff --git a/tests/test_confi.c b/tests/test_confi.c index a90a356..a56ad14 100644 --- a/tests/test_confi.c +++ b/tests/test_confi.c @@ -20,7 +20,7 @@ #include -#include +#include int main (int argc, char **argv) diff --git a/tests/test_confi.conf b/tests/test_confi.conf index 3fe6263..bd76f17 100644 --- a/tests/test_confi.conf +++ b/tests/test_confi.conf @@ -1,5 +1,5 @@ [libzakauthe] -plugin=/usr/local/lib/libzakauthe/plugins/libzakauthedb.so +plugin=zakauthedb [libzakauthe/libzakauthedb/db] -cnc_string=PostgreSql://postgres:postgres@HOST=localhost;DB_NAME=autedb \ No newline at end of file +cnc_string=PostgreSql://postgres:postgres@HOST=localhost;DB_NAME=autedb diff --git a/tests/test_nogui.c b/tests/test_nogui.c index 66a13f3..235f553 100644 --- a/tests/test_nogui.c +++ b/tests/test_nogui.c @@ -18,7 +18,7 @@ #include -#include +#include int main (int argc, char **argv)