From: Sam Thursfield Date: Tue, 5 Jul 2011 11:59:41 +0000 (+0100) Subject: Fix Windows build; tidy up examples X-Git-Tag: 0.7.1~215 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=moonshot-ui.git;a=commitdiff_plain;h=a003d592983efdf50d07d2c00fe6a0e963964b98 Fix Windows build; tidy up examples --- diff --git a/Makefile.am b/Makefile.am index 5e7886d..e5454a5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,6 +8,7 @@ lib_LTLIBRARIES = libmoonshot/libmoonshot.la bin_PROGRAMS = src/moonshot + AM_CFLAGS = AM_CPPFLAGS = \ @@ -91,15 +92,6 @@ src_moonshot_SOURCES += \ nodist_src_moonshot_SOURCES = \ libmoonshot/moonshot-msrpc_s.c -bin_PROGRAMS += src/msrpc-client - -nodist_src_msrpc_client_SOURCES = \ - src/msrpc-client.vala \ - src/moonshot-msrpc.vapi \ - libmoonshot/moonshot-msrpc_c.c - -src_msrpc_client_LDADD = $(moonshot_LIBS) - endif if IPC_DBUS @@ -119,12 +111,6 @@ AM_VALAFLAGS += \ libmoonshot_libmoonshot_la_SOURCES += libmoonshot/libmoonshot-dbus.c -bin_PROGRAMS += src/dbus-client - -src_dbus_client_SOURCES = src/dbus-client.vala -src_dbus_client_CPPFLAGS = $(moonshot_CFLAGS) $(AM_CPPFLAGS) -src_dbus_client_LDADD = $(moonshot_LIBS) - CLEANFILES = $(dbusservice_DATA) EXTRA_DIST = $(dbusservice_in_files) @@ -142,11 +128,17 @@ moonshot_webp_CFLAGS = -mwindows endif -noinst_PROGRAMS = tests/basic +noinst_PROGRAMS = \ + examples/client \ + tests/basic + +examples_client_SOURCES = examples/client.c +examples_client_CPPFLAGS = $(libmoonshot_CFLAGS) $(AM_CPPFLAGS) +examples_client_LDADD = ${top_builddir}/libmoonshot/libmoonshot.la tests_basic_SOURCES = tests/basic.c tests_basic_CPPFLAGS = $(libmoonshot_CFLAGS) $(AM_CPPFLAGS) -tests_basic_LDADD = ${top_builddir}/libmoonshot/libmoonshot.la +tests_basic_LDADD = ${top_builddir}/libmoonshot/libmoonshot.la $(moonshot_LIBS) if OS_WIN32 diff --git a/examples/client.c b/examples/client.c new file mode 100644 index 0000000..3cbfa0f --- /dev/null +++ b/examples/client.c @@ -0,0 +1,33 @@ +#include + +#include + +int main (int argc, + char **argv[]) +{ + MoonshotError *error = NULL; + int success; + + char *nai, + *password, + *server_certificate_hash, + *ca_certificate, + *subject_name_constraint, + *subject_alt_name_constraint; + + success = moonshot_get_default_identity (&nai, + &password, + &server_certificate_hash, + &ca_certificate, + &subject_name_constraint, + &subject_alt_name_constraint, + &error); + + if (success) { + printf ("Got identity: %s %s %s\n", nai, password, server_certificate_hash); + return 0; + } else { + printf ("Error: %s\n", error->message); + return 1; + } +} diff --git a/libmoonshot/libmoonshot-msrpc.c b/libmoonshot/libmoonshot-msrpc.c index b2f7f85..73185d4 100644 --- a/libmoonshot/libmoonshot-msrpc.c +++ b/libmoonshot/libmoonshot-msrpc.c @@ -60,9 +60,9 @@ static void launch_server (MoonshotError **error) { &key); if (status != 0) { - *error = _moonshot_error_new (MOONSHOT_ERROR_OS_ERROR, - "Unable to read registry key HKLM\\%s", - MOONSHOT_INSTALL_PATH_KEY); + *error = moonshot_error_new (MOONSHOT_ERROR_OS_ERROR, + "Unable to read registry key HKLM\\%s", + MOONSHOT_INSTALL_PATH_KEY); return; } @@ -70,19 +70,19 @@ static void launch_server (MoonshotError **error) { status = RegQueryValueEx (key, NULL, NULL, &value_type, exe_path, &length); if (value_type != REG_SZ) { - *error = _moonshot_error_new (MOONSHOT_ERROR_OS_ERROR, - "Value of registry key HKLM\\%s is invalid. " - "Please set it to point to the location of " - "moonshot.exe", - MOONSHOT_INSTALL_PATH_KEY); + *error = moonshot_error_new (MOONSHOT_ERROR_OS_ERROR, + "Value of registry key HKLM\\%s is invalid. " + "Please set it to point to the location of " + "moonshot.exe", + MOONSHOT_INSTALL_PATH_KEY); return; } if (status != 0) { - *error = _moonshot_error_new (MOONSHOT_ERROR_OS_ERROR, - "Unable to read value of registry key HKLM\\%s", - MOONSHOT_INSTALL_PATH_KEY); + *error = moonshot_error_new (MOONSHOT_ERROR_OS_ERROR, + "Unable to read value of registry key HKLM\\%s", + MOONSHOT_INSTALL_PATH_KEY); return; } @@ -95,9 +95,9 @@ static void launch_server (MoonshotError **error) { &startup_info, &process_info); if (status != 0) { - *error = _moonshot_error_new (MOONSHOT_ERROR_UNABLE_TO_START_SERVICE, - "Unable to spawn the moonshot server at '%s'", - exe_path); + *error = moonshot_error_new (MOONSHOT_ERROR_UNABLE_TO_START_SERVICE, + "Unable to spawn the moonshot server at '%s'", + exe_path); return; } } @@ -233,11 +233,19 @@ int moonshot_get_identity (const char *nai, }*/ - /** - * Returns the default identity - most recently used. - * - * @param nai_out NAI stored in the ID card - * @param password_out Password stored in the ID card - * - * @return true on success, false if no identities are stored - */ +int moonshot_get_default_identity (char **nai_out, + char **password_out, + char **server_certificate_hash_out, + char **ca_certificate_out, + char **subject_name_constraint_out, + char **subject_alt_name_constraint_out, + MoonshotError **error) +{ + int status; + + status = rpc_client_bind (&moonshot_binding_handle, + MOONSHOT_ENDPOINT_NAME, + RPC_PER_USER); + + printf ("RPC status: %i\n", status); +}; diff --git a/src/dbus-client.vala b/src/dbus-client.vala deleted file mode 100644 index 3844eef..0000000 --- a/src/dbus-client.vala +++ /dev/null @@ -1,55 +0,0 @@ -[DBus (name = "org.janet.Moonshot")] -interface Moonshot : Object { - public abstract bool get_identity (string nai, string password, string service, - out string nai_out, out string password_out, - out string server_certificate_hash, out string ca_certificate, out string subject_name_constraint, out string subject_alt_name_constraint) throws DBus.Error; - public abstract bool get_default_identity (out string nai_out, out string password_out, - out string server_certificate_hash, out string ca_certificate, out string subject_name_constraint, out string subject_alt_name_constraint) throws DBus.Error; -} - -void main () { - try { - string nai_out, password_out, certificate_out; - string a, b, c; - - var conn = DBus.Bus.get (DBus.BusType.SESSION); - var demo = (Moonshot) conn.get_object ("org.janet.Moonshot", - "/org/janet/moonshot"); - - - if (demo.get_default_identity (out nai_out, - out password_out, - out certificate_out, - out a, - out b, - out c)) - { - stdout.printf ("default identity: %s %s\n", nai_out, password_out); - } - else - { - stdout.printf ("Unable to get default identity.\n"); - } - - - if (demo.get_identity ("username@issuer", - "pass", - "", - out nai_out, - out password_out, - out certificate_out, - out a, - out b, - out c)) - { - stdout.printf ("%s %s %s\n", nai_out, password_out, certificate_out); - } - else - { - stdout.printf ("The nai, password or service doesnt match the selected id_card\n"); - } - - } catch (DBus.Error e) { - stderr.printf ("%s\n", e.message); - } -} diff --git a/src/msrpc-client.vala b/src/msrpc-client.vala deleted file mode 100644 index bd57b24..0000000 --- a/src/msrpc-client.vala +++ /dev/null @@ -1,43 +0,0 @@ -using Rpc; -using MoonshotRpcInterface; - -void main () { - Rpc.client_bind (ref MoonshotRpcInterface.binding_handle, - "/org/janet/Moonshot", - Rpc.Flags.PER_USER); - - string nai = null, password = null, certificate = null; - string a = null, b = null, c = null; - bool result = false; - - /* Get default identity */ - Rpc.AsyncCall call = Rpc.AsyncCall(); - get_default_identity (call, ref nai, ref password); - result = call.complete_bool (); - - if (result == false) - error ("Unable to get default identity"); - else - stdout.printf ("default: %s %s\n", nai, password); - - /* Prompt for identity */ - call = Rpc.AsyncCall(); - get_identity (call, - "username@issuer", - "pass", - "service", - ref nai, - ref password, - ref certificate, - ref a, - ref b, - ref c); - result = call.complete_bool (); - - if (result == false) - error ("The nai, password or service does not match the selected identity\n"); - else - stdout.printf ("%s %s %s\n", nai, password, certificate); - - Rpc.client_unbind (ref MoonshotRpcInterface.binding_handle); -}