-I$(top_srcdir)/libmoonshot \
-I$(top_builddir)/libmoonshot
+
+if LOG4VALA
+MOONSHOT_LOG_PKG= --pkg log4vala-0.1 -X -llog4vala-0.1 --define=USE_LOG4VALA
+MOONSHOT_LOG_LIBS= -llog4vala-0.1
+else
+MOONSHOT_LOG_PKG=
+MOONSHOT_LOG_LIBS=
+endif
+
+
AM_VALAFLAGS = -g \
config.vapi \
- --vapidir=$(top_srcdir)/vapi \
- --pkg gio-2.0
-
+ --vapidir=$(top_srcdir)/vapi \
+ --pkg gio-2.0 \
+ $(MOONSHOT_LOG_PKG)
libmoonshot_libmoonshot_la_CPPFLAGS = \
$(libmoonshot_CFLAGS) \
src/moonshot-password-dialog.vala \
src/moonshot-provisioning-common.vala \
src/moonshot-utils.vala \
- src/moonshot-futils.c
+ src/moonshot-futils.c \
+ src/moonshot-logger.vala
src_moonshot_webp_SOURCES = \
src/moonshot-webp-parser.vala \
src/moonshot-provisioning-common.vala \
src/moonshot-id.vala
-src_moonshot_VALAFLAGS = --pkg gdk-2.0 --pkg gtk+-2.0 --pkg gee-1.0 $(AM_VALAFLAGS)
+src_moonshot_VALAFLAGS = --pkg gdk-2.0 --pkg gtk+-2.0 --pkg gee-1.0 $(AM_VALAFLAGS)
src_moonshot_CPPFLAGS = $(moonshot_CFLAGS) $(AM_CPPFLAGS)
-src_moonshot_LDADD = $(moonshot_LIBS)
-src_moonshot_LDFLAGS = -g -O0
+src_moonshot_LDADD = $(moonshot_LIBS)
+src_moonshot_LDFLAGS = -g -O0 $(MOONSHOT_LOG_LIBS)
src_moonshot_webp_VALAFLAGS = --vapidir=$(top_srcdir)/libmoonshot --pkg gtk+-2.0 --pkg gdk-2.0 --pkg libmoonshot $(AM_VALAFLAGS)
src_moonshot_webp_CPPFLAGS = $(moonshot_CFLAGS) $(AM_CPPFLAGS)
libmoonshot_libmoonshot_la_SOURCES += libmoonshot/libmoonshot-dbus.c
-CLEANFILES = $(dbusservice_DATA)
+CLEANFILES = $(dbusservice_DATA) src_moonshot_vala.stamp src_moonshot_vala.stamp-t
if IPC_DBUS_GLIB
AM_VALAFLAGS += \
;;
esac
+#enable the optional use of Log4Vala (Must have the package installed!)
+AC_ARG_ENABLE([log4vala],
+[ --enable-log4vala Enable use of log4vala for logging],
+[case "${enableval}" in
+ yes) log4vala=true ;;
+ no) log4vala=false ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-log4vala]) ;;
+esac],[log4vala=false])
+AM_CONDITIONAL([LOG4VALA], [test x$log4vala = xtrue])
+
+
AM_CONDITIONAL([OS_LINUX], [test "$linux" = "yes"])
AM_CONDITIONAL([OS_WIN32], [test "$win32" = "yes"])
AM_CONDITIONAL([OS_MACOS], [test "$macos" = "yes"])
public string display_name { get; set; default = ""; }
public string username { get; set; default = ""; }
- #if GNOME_KEYRING
- private unowned string _password;
+#if GNOME_KEYRING
+ private unowned string _password;
public string password {
get {
return (_password!=null) ? _password : "";
_password = GnomeKeyring.memory_strdup(value);
}
}
- #else
- public string password { get; set; default = null; }
- #endif
+#else
+ public string password { get; set; default = null; }
+#endif
- public string issuer { get; set; default = ""; }
+ public string issuer { get; set; default = ""; }
public Rule[] rules {get; set; default = {};}
public string[] services { get; set; default = {}; }
using Gtk;
public class IdentityManagerView : Window {
+ static MoonshotLogger logger = get_logger("IdentityManagerView");
+
private const int WINDOW_WIDTH = 400;
private const int WINDOW_HEIGHT = 500;
protected IdentityManagerApp parent_app;
{
var label = new Label(service);
label.set_alignment(0, (float) 0.5);
- #if VALA_0_12
- var remove_button = new Button.from_stock(Stock.REMOVE);
- #else
- var remove_button = new Button.from_stock(STOCK_REMOVE);
- #endif
+#if VALA_0_12
+ var remove_button = new Button.from_stock(Stock.REMOVE);
+#else
+ var remove_button = new Button.from_stock(STOCK_REMOVE);
+#endif
service_button_map.insert(remove_button, service);
catch (Error e)
{
stderr.printf("%s\n", e.message);
+ logger.error("create_ui_manager: Caught error: " + e.message);
}
ui_manager.ensure_update();
}
osxApp.set_use_quartz_accelerators(true);
osxApp.sync_menu_bar();
osxApp.ready();
- #else
+#else
var menubar = this.ui_manager.get_widget("/MenuBar");
main_vbox.pack_start(menubar, false, false, 0);
- #endif
+#endif
main_vbox.pack_start(hbox, true, true, 0);
add(main_vbox);
main_vbox.show_all();
atk_widget.add_relationship(relationship, atk_target_widget);
}
}
-
-
}
#endif
+
public class IdentityManagerApp {
+ public static MoonshotLogger logger = get_logger("IdentityManagerApp");
+
public IdentityManagerModel model;
public IdCard default_id_card;
public bool explicitly_launched;
private bool name_is_owned;
private bool show_requested;
- #if OS_MACOS
+#if OS_MACOS
public OSXApplication osxApp;
// the signal handler function.
int added_cards = id_manager_app_instance.ipc_server.install_from_file(file_name);
return true;
}
- #endif
+#endif
private const int WINDOW_WIDTH = 400;
private const int WINDOW_HEIGHT = 500;
- /** If we're successfully registered with DBus, then show the UI. Otherwise, wait until we're registered. */
+ /** If we're successfully registered with DBus, then show the UI. Otherwise, wait until we're registered. */
public void show() {
if (name_is_owned) {
if (view != null) {
show_requested = true;
}
}
+
+#if LOG4VALA
+ // Call this from main() to ensure that the logger is initialized
+ internal IdentityManagerApp.dummy() {}
+#endif
public IdentityManagerApp(bool headless, bool use_flat_file_store) {
use_flat_file_store |= UserForcesFlatFileStore();
- #if GNOME_KEYRING
- bool keyring_available = (!use_flat_file_store) && GnomeKeyring.is_available();
- #else
- bool keyring_available = false;
- #endif
+#if GNOME_KEYRING
+ bool keyring_available = (!use_flat_file_store) && GnomeKeyring.is_available();
+#else
+ bool keyring_available = false;
+#endif
IIdentityCardStore.StoreType store_type;
if (headless || use_flat_file_store || !keyring_available)
init_ipc_server();
- #if OS_MACOS
+#if OS_MACOS
osxApp = OSXApplication.get_instance();
// The 'correct' way of connecting won't work in Mac OS with Vala 0.12; e.g.
// osxApp.ns_application_open_file.connect(install_from_file);
// so we have to use this old way
Signal.connect(osxApp, "NSApplicationOpenFile", (GLib.Callback)(on_osx_open_files), this);
- #endif
+#endif
}
public bool add_identity(IdCard id, bool force_flat_file_store) {
}
public void select_identity(IdentityRequest request) {
+ logger.trace("select_identity");
IdCard identity = null;
}
if (identity == null) {
if (request.candidates.length() != 1) {
+ logger.trace("select_identity: Have %u candidates; user must make selection.".printf(request.candidates.length()));
confirm = true;
} else {
identity = request.candidates.nth_data(0);
GLib.Idle.add(
() => {
if (view != null) {
+ logger.trace("select_identity (Idle handler): calling check_add_password");
identity = view.check_add_password(identity, request, model);
}
request.return_identity(identity);
return;
}
- private bool match_service_pattern(string service, string pattern)
- {
- var pspec = new PatternSpec(pattern);
- return pspec.match_string(service);
- }
+ private bool match_service_pattern(string service, string pattern) {
+ var pspec = new PatternSpec(pattern);
+ return pspec.match_string(service);
+ }
- #if IPC_MSRPC
+#if IPC_MSRPC
private void init_ipc_server() {
// Errors will currently be sent via g_log - ie. to an
// obtrusive message box, on Windows
this.ipc_server = MoonshotServer.get_instance();
MoonshotServer.start(this);
}
- #elif IPC_DBUS_GLIB
+#elif IPC_DBUS_GLIB
private void init_ipc_server() {
try {
var conn = DBus.Bus.get(DBus.BusType.SESSION);
if (reply == DBus.RequestNameReply.PRIMARY_OWNER)
{
this.ipc_server = new MoonshotServer(this);
+ logger.trace("init_ipc_server(IPC_DBUS_GLIB) : Constructed new MoonshotServer");
conn.register_object("/org/janet/moonshot", ipc_server);
} else {
+ logger.trace("init_ipc_server: reply != PRIMARY_OWNER");
bool shown = false;
GLib.Error e;
DBus.Object manager_proxy = conn.get_object("org.janet.Moonshot",
}
catch (DBus.Error e)
{
- stderr.printf("%s\n", e.message);
+ logger.trace("bus_acquired_cb");
+ try {
+ conn.register_object ("/org/janet/moonshot", ipc_server);
+ }
+ catch (Error e)
+ {
+ stderr.printf ("%s\n", e.message);
+ logger.error("bus_acquired_cb: Caught error: " + e.message);
+ }
}
}
- #else
+#else
private void bus_acquired_cb(DBusConnection conn) {
+ logger.trace("bus_acquired_cb");
try {
conn.register_object("/org/janet/moonshot", ipc_server);
}
catch (Error e)
{
- stderr.printf("%s\n", e.message);
+ this.ipc_server = new MoonshotServer (this);
+ logger.trace("init_ipc_server: Constructed new MoonshotServer");
+ GLib.Bus.own_name (GLib.BusType.SESSION,
+ "org.janet.Moonshot",
+ GLib.BusNameOwnerFlags.NONE,
+ bus_acquired_cb,
+ (conn, name) => {logger.trace("init_ipc_server: name_acquired_closure");},
+ (conn, name) => {
+ logger.trace("init_ipc_server: name_lost_closure");
+ bool shown=false;
+ try {
+ IIdentityManager manager = Bus.get_proxy_sync (BusType.SESSION, name, "/org/janet/moonshot");
+ shown = manager.show_ui();
+ } catch (IOError e) {
+ logger.error("init_ipc_server.name_lost_closure: Caught error: ");
+ }
+ if (!shown) {
+ GLib.error ("Couldn't own name %s on dbus or show previously launched identity manager.", name);
+ logger.error("init_ipc_server.name_lost_closure: Couldn't own name %s on dbus or show previously launched identity manager".printf(name));
+ } else {
+ logger.trace("init_ipc_server.name_lost_closure: Showed previously launched identity manager.");
+ stdout.printf("Showed previously launched identity manager.\n");
+ GLib.Process.exit(0);
+ }
+ });
}
}
// Name acquired callback:
(conn, name) => {
+ logger.trace(@"init_ipc_server: name_acquired_closure; show_requested=$show_requested");
name_is_owned = true;
// Name lost callback:
(conn, name) => {
+ logger.trace("init_ipc_server: name_lost_closure");
// This callback usually means that another moonshot is already running.
// But it *might* mean that we lost the name for some other reason
shown = manager.show_ui();
}
} catch (IOError e) {
+ logger.error("init_ipc_server.name_lost_closure: Caught IOError: " + e.message);
}
if (!shown) {
+ logger.error("init_ipc_server.name_lost_closure: Couldn't own name %s on dbus or show previously launched identity manager".printf(name));
GLib.error("Couldn't own name %s on dbus or show previously launched identity manager.", name);
} else {
+ logger.trace("init_ipc_server.name_lost_closure: Showed previously launched identity manager.");
stdout.printf("Showed previously launched identity manager.\n");
GLib.Process.exit(0);
}
});
}
- #endif
+#endif
}
static bool explicitly_launched = true;
public static int main(string[] args) {
- #if IPC_MSRPC
- bool headless = false;
- #else
- bool headless = (GLib.Environment.get_variable("DISPLAY") == null);
- #endif
+
+#if LOG4VALA
+ new IdentityManagerApp.dummy();
+#endif
+
+#if IPC_MSRPC
+ bool headless = false;
+#else
+ bool headless = GLib.Environment.get_variable("DISPLAY") == null;
+#endif
if (headless) {
try {
gtk_available = true;
}
- #if OS_WIN32
+#if OS_WIN32
// Force specific theme settings on Windows without requiring a gtkrc file
Gtk.Settings settings = Gtk.Settings.get_default();
settings.set_string_property("gtk-theme-name", "ms-windows", "moonshot");
settings.set_long_property("gtk-menu-images", 0, "moonshot");
- #endif
+#endif
Intl.bindtextdomain(Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
Intl.bind_textdomain_codeset(Config.GETTEXT_PACKAGE, "UTF-8");
Intl.textdomain(Config.GETTEXT_PACKAGE);
+
var app = new IdentityManagerApp(headless, use_flat_file_store);
+ IdentityManagerApp.logger.trace("Hi again from main()!");
app.explicitly_launched = explicitly_launched;
+ IdentityManagerApp.logger.trace(@"main: explicitly_launched=$explicitly_launched");
if (app.explicitly_launched) {
app.show();
}
if (headless) {
- #if !IPC_MSRPC
+#if !IPC_MSRPC
MainLoop loop = new MainLoop();
loop.run();
- #endif
+#endif
}
else {
Gtk.main();
--- /dev/null
+/*
+ * Copyright (c) 2011-2014, JANET(UK)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of JANET(UK) nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+
+public MoonshotLogger get_logger(string name) {
+ return new MoonshotLogger(name);
+}
+
+
+#if USE_LOG4VALA
+
+/** Logger class that wraps the Log4Vala logger */
+public class MoonshotLogger : Object {
+ static bool logger_is_initialized = false;
+
+ private Log4Vala.Logger logger;
+
+ public MoonshotLogger(string name) {
+ if (!logger_is_initialized) {
+ //!! TODO: Don't hard-code the pathname.
+ Log4Vala.init("/home/dbreslau/log4vala.conf");
+ logger_is_initialized = true;
+ }
+
+ logger = Log4Vala.Logger.get_logger(name);
+ }
+
+ /**
+ * Log a trace message.
+ * @param message log message
+ * @param e optional Error to be logged
+ */
+ public void trace(string message, Error? e = null) {
+ logger.trace(message, e);
+ }
+
+
+ /**
+ * Log a debug message.
+ * @param message log message
+ * @param e optional Error to be logged
+ */
+ public void debug(string message, Error? e = null) {
+ logger.debug(message, e);
+ }
+
+
+ /**
+ * Log an info message.
+ * @param e optional Error to be logged
+ */
+ public void info(string message, Error? e = null) {
+ logger.info(message, e);
+ }
+
+ /**
+ * Log a warning message.
+ * @param message log message
+ * @param e optional Error to be logged
+ */
+ public void warn(string message, Error? e = null) {
+ logger.warn(message, e);
+ }
+
+ /**
+ * Log an error message.
+ * @param message log message
+ * @param e optional Error to be logged
+ */
+ public void error(string message, Error? e = null) {
+ logger.error(message, e);
+ }
+
+ /**
+ * Log a fatal message.
+ * @param message log message
+ * @param e optional Error to be logged
+ */
+ public void fatal(string message, Error? e = null) {
+ logger.fatal(message, e);
+ }
+}
+
+
+#else
+
+/** Logger that currently does nothing, but may eventually write to stdout or a file if enabled */
+public class MoonshotLogger : Object {
+
+ internal MoonshotLogger(string name) {
+ }
+
+ /**
+ * Log a trace message.
+ * @param message log message
+ * @param e optional Error to be logged
+ */
+ public void trace(string message, Error? e = null) {
+ }
+
+
+ /**
+ * Log a debug message.
+ * @param message log message
+ * @param e optional Error to be logged
+ */
+ public void debug(string message, Error? e = null) {
+ }
+
+
+ /**
+ * Log an info message.
+ * @param e optional Error to be logged
+ */
+ public void info(string message, Error? e = null) {
+ }
+
+ /**
+ * Log a warning message.
+ * @param message log message
+ * @param e optional Error to be logged
+ */
+ public void warn(string message, Error? e = null) {
+ }
+
+ /**
+ * Log an error message.
+ * @param message log message
+ * @param e optional Error to be logged
+ */
+ public void error(string message, Error? e = null) {
+ }
+
+ /**
+ * Log a fatal message.
+ * @param message log message
+ * @param e optional Error to be logged
+ */
+ public void fatal(string message, Error? e = null) {
+ }
+}
+
+#endif
[DBus (name = "org.janet.Moonshot")]
public class MoonshotServer : Object {
+ static MoonshotLogger logger = get_logger("MoonshotServer");
+
+ private string app_name = "Moonshot";
+
private IdentityManagerApp parent_app;
public MoonshotServer(IdentityManagerApp app)
{
+ logger.trace("MoonshotServer.<constructor>; app=" + (app == null ? "null" : "non-null"));
this.parent_app = app;
}
public bool show_ui()
{
+ logger.trace("MoonshotServer.show_ui");
+
if (parent_app.view == null) {
+ stderr.printf(app_name, "show_ui: parent_app.view is null!\n");
+ logger.warn("show_ui: parent_app.view is null!");
return false;
}
parent_app.show();
parent_app.explicitly_launched = true;
+ logger.trace("MoonshotServer.show_ui: returning true");
return true;
}
out string subject_name_constraint,
out string subject_alt_name_constraint)
{
+ logger.trace(@"MoonshotServer.get_identity: nai='$nai'; service='$service'");
var request = new IdentityRequest(parent_app,
nai,
password,
service);
+ logger.trace(@"MoonshotServer.get_identity: Calling request.execute()");
request.set_callback((IdentityRequest) => get_identity.callback());
request.execute();
+ logger.trace(@"MoonshotServer.get_identity: Back from request.execute()");
yield;
+ logger.trace(@"MoonshotServer.get_identity: back from yield");
nai_out = "";
password_out = "";
if (subject_alt_name_constraint == null)
subject_alt_name_constraint = "";
+ logger.trace("MoonshotServer.get_identity: returning true");
+
return true;
}
+ logger.trace("MoonshotServer.get_identity: returning false");
return false;
}
out string subject_name_constraint,
out string subject_alt_name_constraint)
{
+ logger.trace("MoonshotServer.get_default_identity");
var request = new IdentityRequest.default(parent_app);
request.set_callback((IdentityRequest) => get_default_identity.callback());
request.execute();
if (subject_alt_name_constraint == null)
subject_alt_name_constraint = "";
+ logger.trace("MoonshotServer.get_default_identity: returning true");
return true;
}
ref string subject_name_constraint,
ref string subject_alt_name_constraint)
{
+ logger.trace("(static) get_identity");
+
bool result = false;
var request = new IdentityRequest(parent_app,
ref string subject_name_constraint,
ref string subject_alt_name_constraint)
{
+ logger.trace("(static) get_default_identity");
+
bool result;
var request = new IdentityRequest.default(parent_app);
string server_cert,
bool force_flat_file_store)
{
+ logger.trace("(static) install_id_card");
IdCard idcard = new IdCard();
+
bool success = false;
Mutex mutex = new Mutex();
Cond cond = new Cond();