From 55f2f01e4dc10106bad5214ccb62d53c4ef88ac4 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 16 Feb 2013 14:34:25 +0100 Subject: [PATCH] Impostato il main.c come da standard. --- .anjuta_sym_db.db | Bin 34816 -> 39936 bytes configure.ac | 3 + docs/Makefile.am | 1 + docs/messi/Makefile.am | 1 + docs/messi/examples/Makefile.am | 6 + docs/messi/examples/messi.conf | 25 ++ src/main.c | 491 ++++++++++++++++++++++++++++++-- 7 files changed, 504 insertions(+), 23 deletions(-) create mode 100644 docs/Makefile.am create mode 100644 docs/messi/Makefile.am create mode 100644 docs/messi/examples/Makefile.am create mode 100644 docs/messi/examples/messi.conf diff --git a/.anjuta_sym_db.db b/.anjuta_sym_db.db index c8c1ba921b26ec541169bce0a2106d985fca2b6d..1dcb3cf3b89eec0404b2d76895a68969dcd51388 100644 GIT binary patch literal 39936 zcmeHQdu$xXd7sDL-tF-%>bN|SCoaXu@g!2zk&y(NRxOG;)3ha0p(ra(VO*AXE9$I! zQ1{To1>90r9!_J!L4mYD5*JMi1W1Cmseu-#Q`-fa{886!(}+kAz3%@i*46#m&ef9Yf&GB`sfcCjYi+1Z_+pDkHxK9G|%5dz(e5OMIhV_ z{I;=5+!h2UsDPtLE#PAMF9^Qg$3wtF;Pysf982iXq@I7IQr43f3&nG#H9ch{)5aOS zk}Xf{i%*X2n;459(BhMK?St=r))Zj+eFR_c<00T7@IFMKhaOVgnuHemBvR;O68&HL z1Nt5M7xa(mAJBiM&(X);hd_8)@(|cM1fZsM)<|zrXundroJ;Ddlu;@{s0<@>nT9cV zt`xGdW*?2P>*TpiKJBCb8jxrRpUGqmicm*@MsYG(&aEYjMy_zdNCy=^RdFd*STmZN zD2*stJ-=GfSB)T{J<3|K@Q9HrH)GnTREGv){QoMVuht~ZyY&$85V(yI7{oG)bSjhC zLQ2oB6(5Q3-De;Ff8ef(eRoYxit+zX5&h|HoK-LB9s(W$H-tc&1Z{$?NnrgyrJsQQ zpMDj7yp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ji*+Hr{}1;pgpmLM delta 1244 zcmZ`&U1%It6rOv(JF|DPo9-@VvuWaVXWNj!Dl`q6lF+6`&Qj zHYpM8KGm0%q~lWq3N45tS~dfs&=OR%_#!@u>qA>jG`=WA1Yd;p+|5t7PzUBPbMAK! z-*?V;E`P=^FY%=w-PSbi;Iciz?AqjYZ|BFFL{-CI_ziV@kN5C7zDCszia9(Vkm#4O zSSfcgR!rv#<#fuY!(y|Sawa5!M#hdD8ykLlwL=J31b%{Zx2GpKGB*6w*zjl@)nVAuu;m5^HsNkX{DH1^N=mk_ zv2}ch_c4#t{62qydux@C7<+EH63O+kfM$l7q|4F@n~cfnR6M=V(JK-FzPB89Nt{vP**-3-yjx%#OWI8L=1D(ACXG=4$W>VAXl0B5XkjbV7 z%Y}?{Z_)M=dPFDmAd^n}+g)!)A8_2g(r7#>2x0B$i6}kg#6m1lNL{iY1@8mF{jKo% z$fIyaIN_o@xM;IYqotX|9PvvRt=1c-w{wk#8i>S{hQIL(rtl7m_!chewaSa|dG!z# zX|_;0Yoj(l;cRFso&i^V~HE$T;PT{?`s2YY1kka-y#=( zf_)x93n`)&hjz+2ccpu%n?V~_sn~3~6nmJeQVrbJa2vnk8!B-V?GmA;R2;x5rYbzn zyD@J5PlfAQ-_@5zhvavNBfjEyaERZ-TZrSsTIDA13L7Dl9H?%$I!ro~*Um7H^X1}k zW;kmreN1=WU9r!L{f6JPB5Z!o(7R^AAtP#9(U#`5Kz7E+yNs|&d(mv?-mzMV)i;<3 zH%DC8@Gt(M4*!AQv5vc_yFvK{CIlptD$o{7W~iX6AXI<~9FXR=PmXFhiY%VNpZEc5 z_yEhbN;kqmK~f)**)J?=B5jZ1=@r&EbM7xjNbu5?P7 - #ifdef HAVE_CONFIG_H #include #endif +#include + #include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "commons.h" + +static Commons *commons; + +static ZakAudit *audit; + +static GKeyFile *config; + +static GtkWidget *w; +static GtkWidget *vbx_body; +static GtkWidget *vbx_body_child; +static GObject *gobj_child; + +static void +main_on_before_execute (gpointer instance, gpointer gda_stmt, gpointer user_data) +{ + if (gda_connection_get_transaction_status ((GdaConnection *)gdaex_get_gdaconnection (commons->gdaex)) == NULL) + { + GdaStatement *stmt = (GdaStatement *)gda_stmt; -GdaEx *gdaex; + if (gda_statement_get_statement_type (stmt) == GDA_SQL_STATEMENT_UPDATE) + { + zak_audit_action_from_gdastatement (audit, ZAK_AUDIT_ACTION_BEFORE_UPDATE, commons->utente, "opengov", stmt); + } + else if (gda_statement_get_statement_type (stmt) == GDA_SQL_STATEMENT_DELETE) + { + zak_audit_action_from_gdastatement (audit, ZAK_AUDIT_ACTION_DELETE, commons->utente, "opengov", stmt); + } + } +} -GtkBuilder *gtkbuilder; +static void +main_on_after_execute (gpointer instance, gpointer gda_stmt, gpointer user_data) +{ + if (gda_connection_get_transaction_status ((GdaConnection *)gdaex_get_gdaconnection (commons->gdaex)) == NULL) + { + GdaStatement *stmt = (GdaStatement *)gda_stmt; -GtkWidget *w; -GtkWidget *vbx_body; -GtkWidget *vbx_body_child; + if (gda_statement_get_statement_type (stmt) == GDA_SQL_STATEMENT_INSERT) + { + zak_audit_action_from_gdastatement (audit, ZAK_AUDIT_ACTION_INSERT, commons->utente, "opengov", stmt); + } + else if (gda_statement_get_statement_type (stmt) == GDA_SQL_STATEMENT_UPDATE) + { + zak_audit_action_from_gdastatement (audit, ZAK_AUDIT_ACTION_AFTER_UPDATE, commons->utente, "opengov", stmt); + } + } +} static void -main_set_vbx_body_child (GtkWidget *child) +main_set_vbx_body_child (GtkWidget *wchild, GObject *ochild) { if (GTK_IS_WIDGET (vbx_body_child)) { @@ -41,8 +91,16 @@ main_set_vbx_body_child (GtkWidget *child) gtk_widget_destroy (vbx_body_child); } - vbx_body_child = child; + if (G_IS_OBJECT (gobj_child)) + { + g_object_unref (gobj_child); + } + + vbx_body_child = wchild; + gobj_child = ochild; + gtk_box_pack_start (GTK_BOX (vbx_body), vbx_body_child, TRUE, TRUE, 0); + gtk_widget_grab_focus (wchild); } /*G_MODULE_EXPORT void @@ -66,16 +124,15 @@ on_mnu_help_about_activate (GtkMenuItem *menuitem, GtkWidget *diag; error = NULL; - gtk_builder_add_objects_from_file (gtkbuilder, GUIDIR "/messi.gui", + gtk_builder_add_objects_from_file (commons->gtkbuilder, commons->guifile, g_strsplit_set ("dlg_about", "|", -1), &error); if (error != NULL) { - g_fprintf (stderr, "Errore: %s\n", error->message); - return; + g_error ("Errore: %s.", error->message); } - diag = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "dlg_about")); + diag = GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "dlg_about")); gtk_dialog_run (GTK_DIALOG (diag)); gtk_widget_destroy (diag); @@ -86,34 +143,420 @@ main (int argc, char *argv[]) { GError *error; + GdaConnection *gdacon; + + Aute *aute; + gchar **aute_params; + gsize n_aute_params; + GSList *sl_aute_params; + + gchar *utente; + + gchar *cnc_string; + + gint i; + + AutozIResource *ires1; + +#ifdef G_OS_WIN32 + if (g_getenv ("TZ") == NULL) + { + /* per un problema delle glib che fanno riferimento a TZ e sotto win non c'è */ + g_setenv ("TZ", "+01:00", TRUE); + } + if (g_getenv ("LANG") == NULL) + { + /* sotto win non è detto che sia impostata */ + g_setenv ("LANG", "it_IT", TRUE); + } +#endif + gtk_init (&argc, &argv); gda_init (); - gdaex = gdaex_new_from_string (argv[1]); - if (gdaex == NULL) + /* leggo la configurazione dal file */ + if (argc == 1) + { + g_error ("Occorre passare a riga di comando il file di configurazione."); + } + + error = NULL; + config = g_key_file_new (); + if (!g_key_file_load_from_file (config, argv[1], G_KEY_FILE_NONE, &error)) + { + g_error ("Impossibile caricare il file di configurazione specificato: %s.", argv[1]); + } + + /* leggo i parametri per l'autenticazione */ + error = NULL; + aute_params = g_key_file_get_keys (config, "AUTE", &n_aute_params, &error); + if (aute_params == NULL) + { + g_error ("Impossibile leggere la configurazione per il sistema di autenticazione."); + } + + sl_aute_params = NULL; + for (i = 0; i < n_aute_params; i++) + { + error = NULL; + sl_aute_params = g_slist_append (sl_aute_params, g_key_file_get_string (config, "AUTE", aute_params[i], &error)); + } + + g_strfreev (aute_params); + + /* autenticazione */ + aute = aute_new (); + aute_set_config (aute, sl_aute_params); + + while (TRUE) + { + utente = aute_autentica (aute); + + if (utente == NULL) + { + g_warning ("Nome utente o password non validi."); + } + else if (g_strcmp0 (utente, "") == 0) + { + return 0; + } + else + { + break; + } + } + + /* inizializzazione commons */ + commons = g_new0 (Commons, 1); + + commons->territorio_commons = g_new0 (TerritorioCommons, 1); + commons->organigramma_commons = g_new0 (OrganigrammaCommons, 1); + commons->autozgui_commons = g_new0 (AutozGuiCommons, 1); + + commons->utente = utente; + commons->territorio_commons->utente = utente; + commons->organigramma_commons->utente = utente; + + commons->organigramma_commons->territorio_commons = commons->territorio_commons; + + if (argc == 3) + { + commons->pr_cod_prat = strtol (argv[2], NULL, 10); + } + +#ifdef G_OS_WIN32 + + gchar *moddir; + gchar *p; + + moddir = g_win32_get_package_installation_directory_of_module (NULL); + + p = g_strrstr (moddir, g_strdup_printf ("%c", G_DIR_SEPARATOR)); + if (p != NULL + && g_ascii_strcasecmp (p + 1, "src") == 0) + { + commons->guidir = g_strdup (GUIDIR); + commons->formdir = g_strdup (FORMDIR); + commons->territorio_commons->guidir = g_build_filename ("/mingw", "share", "territorio", "gui", NULL); + commons->territorio_commons->formdir = g_build_filename ("/mingw", "share", "territorio", "form", NULL); + commons->organigramma_commons->guidir = g_build_filename ("/mingw", "share", "organigramma", "gui", NULL); + commons->organigramma_commons->formdir = g_build_filename ("/mingw", "share", "organigramma", "form", NULL); + commons->autozgui_commons->guidir = g_build_filename ("/mingw", "share", "autoz-gui", "gui", NULL); + } + else + { +#undef GUIDIR +#undef FORMDIR + + commons->guidir = g_build_filename (moddir, "share", PACKAGE, "gui", NULL); + commons->formdir = g_build_filename (moddir, "share", PACKAGE, "form", NULL); + commons->territorio_commons->guidir = g_build_filename (moddir, "share", "territorio", "gui", NULL); + commons->territorio_commons->formdir = g_build_filename (moddir, "share", "territorio", "form", NULL); + commons->organigramma_commons->guidir = g_build_filename (moddir, "share", "organigramma", "gui", NULL); + commons->organigramma_commons->formdir = g_build_filename (moddir, "share", "organigramma", "form", NULL); + commons->autozgui_commons->guidir = g_build_filename (moddir, "share", "autoz-gui", "gui", NULL); + } + +#else + + commons->guidir = g_strdup (GUIDIR); + commons->formdir = g_strdup (FORMDIR); + commons->territorio_commons->guidir = g_build_filename ("/usr", "local", "share", "territorio", "gui", NULL); + commons->territorio_commons->formdir = g_build_filename ("/usr", "local", "share", "territorio", "form", NULL); + commons->organigramma_commons->guidir = g_build_filename ("/usr", "local", "share", "organigramma", "gui", NULL); + commons->organigramma_commons->formdir = g_build_filename ("/usr", "local", "share", "organigramma", "form", NULL); + commons->autozgui_commons->guidir = g_build_filename ("/usr", "local", "share", "autoz-gui", "gui", NULL); + +#endif + + commons->guifile = g_build_filename (commons->guidir, "opengov.gui", NULL); + commons->territorio_commons->guifile = g_build_filename (commons->territorio_commons->guidir, "territorio.gui", NULL); + commons->organigramma_commons->guifile = g_build_filename (commons->organigramma_commons->guidir, "organigramma.gui", NULL); + commons->autozgui_commons->guifile = g_build_filename (commons->autozgui_commons->guidir, "autoz-gui.ui", NULL); + + /* leggo la stringa di connessione al db */ + error = NULL; + cnc_string = g_key_file_get_value (config, "DB", "cnc_string", &error); + if (cnc_string == NULL) + { + if (error != NULL) + { + g_error ("Impossibile leggere la stringa di connessione dal file di configurazione: %s", error->message); + } + else + { + g_error ("Impossibile leggere la stringa di connessione dal file di configurazione."); + } + } + + commons->gdaex = gdaex_new_from_string (cnc_string); + if (commons->gdaex == NULL) + { + g_error ("Errore nella connessione al database: %s", cnc_string); + } + + /* leggo la stringa di connessione al db nativa di postgres */ + error = NULL; + cnc_string = g_key_file_get_value (config, "DB", "pg_cnc_string", &error); + if (cnc_string == NULL) + { + if (error != NULL) + { + g_error ("Impossibile leggere la stringa di connessione dal file di configurazione: %s", error->message); + } + else + { + g_error ("Impossibile leggere la stringa di connessione dal file di configurazione."); + } + } + + commons->pgcon = PQconnectdb (cnc_string); + if (commons->pgcon == NULL + || PQstatus (commons->pgcon) == CONNECTION_BAD) + { + g_error ("Errore nella connessione al database: %s", cnc_string); + } + + /* leggo i parametri per libautoz */ + error = NULL; + cnc_string = g_key_file_get_value (config, "AUTOZ", "cnc_string", &error); + if (cnc_string == NULL) + { + g_warning ("Impossibile leggere la stringa di connessione per libautoz dal file di configurazione: %s.\n", error != NULL && error->message != NULL ? error->message : "nessun dettaglio"); + return 0; + } + + error = NULL; + gdacon = gda_connection_open_from_string (NULL, cnc_string, NULL, 0, &error); + if (gdacon == NULL) + { + g_warning ("Impossibile creare la connessione al db per libautoz: %s.\n", error != NULL && error->message != NULL ? error->message : "nessun dettaglio"); + return 0; + } + + commons->autoz = autoz_new (); + if (commons->autoz == NULL) + { + g_warning ("Impossibile creare l'oggetto per libautoz."); + return 0; + } + if (!autoz_load_from_db (commons->autoz, gdacon, NULL, TRUE)) + { + g_warning ("Impossibile caricare la configurazione per libautoz dal db."); + return 0; + } + + commons->role_utente = autoz_get_role_from_id (commons->autoz, commons->utente); + if (commons->role_utente == NULL) + { + g_warning ("Utente «%s» non trovato nell configurazione di libautoz.", commons->utente); + return 0; + } + + if (!autoz_is_allowed (commons->autoz, commons->role_utente, autoz_get_resource_from_id (commons->autoz, "opengov_ro"), FALSE) + && !autoz_is_allowed (commons->autoz, commons->role_utente, autoz_get_resource_from_id (commons->autoz, "opengov_rw"), FALSE)) + { + g_critical ("Non si è autorizzati all'utilizzo di questa applicazione."); + return 0; + } + + commons->autozgui_commons->prefix = g_strdup (""); + + commons->autozgui_commons->gdacon = gdacon; + commons->autozgui_commons->gdaparser = gda_connection_create_parser (commons->autozgui_commons->gdacon); + if (!commons->autozgui_commons->gdaparser) + { + /* @cnc doe snot provide its own parser => use default one */ + commons->autozgui_commons->gdaparser = gda_sql_parser_new (); + } + + commons->gdaex_autozgui = gdaex_new_from_connection (gdacon); + + /* leggo i parametri per libaudit */ + error = NULL; + cnc_string = g_key_file_get_value (config, "AUDIT", "cnc_string", &error); + if (cnc_string == NULL) + { + g_warning ("Impossibile leggere la stringa di connessione per libaudit dal file di configurazione: %s\n", + error != NULL && error->message != NULL ? error->message : "nessun dettaglio"); + return 0; + } + + audit = zak_audit_new_from_string (cnc_string); + if (audit == NULL) { - g_fprintf (stderr, "Errore nella connessione al database: %s\n", argv[1]); + g_warning ("Errore nella creazione dell'oggetto per libaudit.\n"); return 0; } - gtkbuilder = gtk_builder_new (); + g_signal_connect (commons->gdaex, "before-execute", G_CALLBACK (main_on_before_execute), NULL); + g_signal_connect (commons->gdaex, "after-execute", G_CALLBACK (main_on_after_execute), NULL); + + /* inizializzo solipa */ + commons->solipa = solipa_new (); + + /* leggo la stringa di connessione al db territorio */ + error = NULL; + cnc_string = g_key_file_get_value (config, "DB_TERRITORIO", "cnc_string", &error); + if (cnc_string == NULL) + { + if (error != NULL) + { + g_error ("Impossibile leggere la stringa di connessione dal file di configurazione: %s", error->message); + } + else + { + g_error ("Impossibile leggere la stringa di connessione dal file di configurazione."); + } + } + + commons->territorio_commons->gdaex = gdaex_new_from_string (cnc_string); + if (commons->territorio_commons->gdaex == NULL) + { + g_error ("Errore nella connessione al database: %s", cnc_string); + } + + /* leggo i parametri per libautoz di territorio */ + error = NULL; + cnc_string = g_key_file_get_value (config, "AUTOZ_TERRITORIO", "cnc_string", &error); + if (cnc_string == NULL) + { + g_warning ("Impossibile leggere la stringa di connessione per libautoz dal file di configurazione: %s.\n", error != NULL && error->message != NULL ? error->message : "nessun dettaglio"); + return 0; + } error = NULL; - gtk_builder_add_objects_from_file (gtkbuilder, GUIDIR "/messi.gui", + gdacon = gda_connection_open_from_string (NULL, cnc_string, NULL, 0, &error); + if (gdacon == NULL) + { + g_warning ("Impossibile creare la connessione al db per libautoz di territorio: %s.\n", error != NULL && error->message != NULL ? error->message : "nessun dettaglio"); + return 0; + } + + commons->territorio_commons->autoz = autoz_new (); + if (commons->territorio_commons->autoz == NULL) + { + g_warning ("Impossibile creare l'oggetto per libautoz."); + return 0; + } + if (!autoz_load_from_db (commons->territorio_commons->autoz, gdacon, NULL, TRUE)) + { + g_warning ("Impossibile caricare la configurazione per libautoz dal db."); + return 0; + } + + commons->territorio_commons->role_utente = autoz_get_role_from_id (commons->territorio_commons->autoz, commons->territorio_commons->utente); + if (commons->territorio_commons->role_utente == NULL) + { + g_warning ("Utente \"%s\" non trovato nell configurazione di libautoz.", commons->territorio_commons->utente); + return 0; + } + + /* leggo la stringa di connessione al db organigramma */ + error = NULL; + cnc_string = g_key_file_get_value (config, "DB_ORGANIGRAMMA", "cnc_string", &error); + if (cnc_string == NULL) + { + if (error != NULL) + { + g_error ("Impossibile leggere la stringa di connessione dal file di configurazione: %s", error->message); + } + else + { + g_error ("Impossibile leggere la stringa di connessione dal file di configurazione."); + } + } + + commons->organigramma_commons->gdaex = gdaex_new_from_string (cnc_string); + if (commons->organigramma_commons->gdaex == NULL) + { + g_error ("Errore nella connessione al database: %s", cnc_string); + } + + /* leggo i parametri per libautoz di organigramma */ + error = NULL; + cnc_string = g_key_file_get_value (config, "AUTOZ_ORGANIGRAMMA", "cnc_string", &error); + if (cnc_string == NULL) + { + g_warning ("Impossibile leggere la stringa di connessione per libautoz dal file di configurazione: %s.\n", error != NULL && error->message != NULL ? error->message : "nessun dettaglio"); + return 0; + } + + error = NULL; + gdacon = gda_connection_open_from_string (NULL, cnc_string, NULL, 0, &error); + if (gdacon == NULL) + { + g_warning ("Impossibile creare la connessione al db per libautoz di organigramma: %s.\n", error != NULL && error->message != NULL ? error->message : "nessun dettaglio"); + return 0; + } + + commons->organigramma_commons->autoz = autoz_new (); + if (commons->organigramma_commons->autoz == NULL) + { + g_warning ("Impossibile creare l'oggetto per libautoz."); + return 0; + } + if (!autoz_load_from_db (commons->organigramma_commons->autoz, gdacon, NULL, TRUE)) + { + g_warning ("Impossibile caricare la configurazione per libautoz dal db."); + return 0; + } + + commons->organigramma_commons->role_utente = autoz_get_role_from_id (commons->organigramma_commons->autoz, commons->organigramma_commons->utente); + if (commons->organigramma_commons->role_utente == NULL) + { + g_warning ("Utente \"%s\" non trovato nell configurazione di libautoz.", commons->organigramma_commons->utente); + return 0; + } + + /* gtkbuilder */ + commons->gtkbuilder = gtk_builder_new (); + commons->territorio_commons->gtkbuilder = gtk_builder_new (); + commons->organigramma_commons->gtkbuilder = gtk_builder_new (); + commons->autozgui_commons->gtkbuilder = gtk_builder_new (); + + error = NULL; + gtk_builder_add_objects_from_file (commons->gtkbuilder, commons->guifile, g_strsplit_set ("w_main", "|", -1), &error); if (error != NULL) { - g_fprintf (stderr, "Errore: %s\n", error->message); - return 0; + g_error ("Errore: %s", error->message); } - gtk_builder_connect_signals (gtkbuilder, NULL); + gtk_builder_connect_signals (commons->gtkbuilder, NULL); - w = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "w_main")); + /* autorizzazioni */ + ires1 = autoz_get_resource_from_id (commons->autoz, "opengov_admin"); + if (!autoz_is_allowed (commons->autoz, commons->role_utente, ires1, FALSE)) + { + gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "menuitem4")), FALSE); + } - vbx_body = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "vbx_body")); + w = GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "w_main")); + + vbx_body = GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "vbx_body")); vbx_body_child = NULL; @@ -121,5 +564,7 @@ main (int argc, char *argv[]) gtk_main (); + g_object_unref (commons->solipa); + return 0; } -- 2.49.0