From 0e8e93eb82c55d2e8efa1edc21f4f142036e0be4 Mon Sep 17 00:00:00 2001 From: Kevin Wasserman Date: Mon, 16 Sep 2013 16:12:01 -0400 Subject: [PATCH] Add option to force use of flat file store to moonshot-webp '-f' is the switch. Fixed usage statement. --- libmoonshot/libmoonshot-dbus.c | 2 ++ libmoonshot/libmoonshot.h | 1 + libmoonshot/libmoonshot.vapi | 1 + src/moonshot-identities-manager.vala | 7 ++++++- src/moonshot-identity-management-view.vala | 6 +++--- src/moonshot-identity-manager-app.vala | 6 +++--- src/moonshot-server.vala | 13 +++++++----- src/moonshot-webp-parser.vala | 33 +++++++++++++++++++++++++----- 8 files changed, 52 insertions(+), 17 deletions(-) diff --git a/libmoonshot/libmoonshot-dbus.c b/libmoonshot/libmoonshot-dbus.c index 3dffeba..97dba1e 100644 --- a/libmoonshot/libmoonshot-dbus.c +++ b/libmoonshot/libmoonshot-dbus.c @@ -351,6 +351,7 @@ int moonshot_install_id_card (const char *display_name, const char *subject, const char *subject_alt, const char *server_cert, + int force_flat_file_store, MoonshotError **error) { GError *g_error = NULL; @@ -400,6 +401,7 @@ int moonshot_install_id_card (const char *display_name, G_TYPE_STRING, subject, G_TYPE_STRING, subject_alt, G_TYPE_STRING, server_cert, + G_TYPE_INT, force_flat_file_store, G_TYPE_INVALID, G_TYPE_BOOLEAN, &success, G_TYPE_INVALID); diff --git a/libmoonshot/libmoonshot.h b/libmoonshot/libmoonshot.h index 670dd87..d7830c2 100644 --- a/libmoonshot/libmoonshot.h +++ b/libmoonshot/libmoonshot.h @@ -184,6 +184,7 @@ int moonshot_install_id_card (const char *display_name, const char *subject, const char *subject_alt, const char *server_cert, + int force_flat_file_store, MoonshotError **error); #endif diff --git a/libmoonshot/libmoonshot.vapi b/libmoonshot/libmoonshot.vapi index d927663..8662596 100644 --- a/libmoonshot/libmoonshot.vapi +++ b/libmoonshot/libmoonshot.vapi @@ -49,5 +49,6 @@ namespace Moonshot { string? subject, string? subject_alt, string? server_cert, + int force_flat_file_store, out Moonshot.Error error); } diff --git a/src/moonshot-identities-manager.vala b/src/moonshot-identities-manager.vala index c6def5f..51f9d64 100644 --- a/src/moonshot-identities-manager.vala +++ b/src/moonshot-identities-manager.vala @@ -49,8 +49,12 @@ public class IdentityManagerModel : Object { return true; } - public void add_card(IdCard card) { + public void add_card(IdCard card, bool force_flat_file_store) { string candidate; + IIdentityCardStore.StoreType saved_store_type = get_store_type(); + + if (force_flat_file_store) + set_store_type(IIdentityCardStore.StoreType.FLAT_FILE); if (!display_name_is_valid (card.display_name, out candidate)) { @@ -58,6 +62,7 @@ public class IdentityManagerModel : Object { } store.add_card(card); + set_store_type(saved_store_type); card_list_changed(); } diff --git a/src/moonshot-identity-management-view.vala b/src/moonshot-identity-management-view.vala index adcf8b4..1a89cf2 100644 --- a/src/moonshot-identity-management-view.vala +++ b/src/moonshot-identity-management-view.vala @@ -306,7 +306,7 @@ public class IdentityManagerView : Window { id_card_widget.expanded.connect (fill_details); } - public bool add_identity (IdCard id_card) + public bool add_identity (IdCard id_card, bool force_flat_file_store) { #if OS_MACOS /* @@ -329,7 +329,7 @@ public class IdentityManagerView : Window { if (ret == Gtk.ResponseType.YES) { id_card.set_data ("pixbuf", find_icon ("avatar-default", 48)); - this.identities_manager.add_card (id_card); + this.identities_manager.add_card (id_card, force_flat_file_store); return true; } @@ -343,7 +343,7 @@ public class IdentityManagerView : Window { switch (result) { case ResponseType.OK: - this.identities_manager.add_card (get_id_card_data (dialog)); + this.identities_manager.add_card (get_id_card_data (dialog), false); break; default: break; diff --git a/src/moonshot-identity-manager-app.vala b/src/moonshot-identity-manager-app.vala index 4237319..681d811 100644 --- a/src/moonshot-identity-manager-app.vala +++ b/src/moonshot-identity-manager-app.vala @@ -76,9 +76,9 @@ public class IdentityManagerApp { #endif } - public bool add_identity (IdCard id) { - if (view != null) return view.add_identity(id); - model.add_card(id); + public bool add_identity (IdCard id, bool force_flat_file_store) { + if (view != null) return view.add_identity(id, force_flat_file_store); + model.add_card(id, force_flat_file_store); return true; } diff --git a/src/moonshot-server.vala b/src/moonshot-server.vala index c415086..eb881d2 100644 --- a/src/moonshot-server.vala +++ b/src/moonshot-server.vala @@ -133,7 +133,8 @@ public class MoonshotServer : Object { string ?ca_cert, string ?subject, string ?subject_alt, - string ?server_cert) + string ?server_cert, + int force_flat_file_store) { IdCard idcard = new IdCard (); @@ -158,7 +159,7 @@ public class MoonshotServer : Object { } } - return parent_app.add_identity (idcard); + return parent_app.add_identity (idcard, force_flat_file_store!=0); } @@ -197,7 +198,8 @@ public class MoonshotServer : Object { card.trust_anchor.ca_cert, card.trust_anchor.subject, card.trust_anchor.subject_alt, - card.trust_anchor.server_cert); + card.trust_anchor.server_cert, + 0); if (result) { installed_cards++; } @@ -382,7 +384,8 @@ public class MoonshotServer : Object { string ca_cert, string subject, string subject_alt, - string server_cert) + string server_cert, + bool force_flat_file_store) { IdCard idcard = new IdCard (); bool success = false; @@ -415,7 +418,7 @@ public class MoonshotServer : Object { // Defer addition to the main loop thread. Idle.add (() => { mutex.lock (); - success = parent_app.add_identity (idcard); + success = parent_app.add_identity (idcard, force_flat_file_store); cond.signal (); mutex.unlock (); return false; diff --git a/src/moonshot-webp-parser.vala b/src/moonshot-webp-parser.vala index 5d9775f..701042e 100644 --- a/src/moonshot-webp-parser.vala +++ b/src/moonshot-webp-parser.vala @@ -6,17 +6,39 @@ namespace WebProvisioning public static int main (string[] args) { - if (args.length < 2) + int arg_index = -1; + int force_flat_file_store = 0; + bool bad_switch = false; + for (arg_index = 1; arg_index < args.length; arg_index++) { + int index = 0; + unichar c = 0; + string arg = args[arg_index]; + if (arg.get_next_char(ref index, out c)) { + if ((c=='-') && arg.get_next_char(ref index, out c)) { + switch (c) { + case 'f': + force_flat_file_store = 1; + break; + default: + bad_switch = true; + break; + } + } else + break; // arg is not a switch; presume it's the file + } + } + if (bad_switch || (arg_index != args.length - 1)) { - error ("Usage %s [-a] WEB_PROVISIONING_FILE", args[0]); + error ("Usage %s [-f] WEB_PROVISIONING_FILE\n -f: add identities to flat file store", args[0]); } + string webp_file = args[arg_index]; - if (!FileUtils.test (args[1], FileTest.EXISTS | FileTest.IS_REGULAR)) + if (!FileUtils.test (webp_file, FileTest.EXISTS | FileTest.IS_REGULAR)) { - error ("%s does not exist", args[1]); + error ("%s does not exist", webp_file); } - var webp = new Parser (args[1]); + var webp = new Parser (webp_file); webp.parse(); foreach (IdCard card in cards) @@ -49,6 +71,7 @@ namespace WebProvisioning card.trust_anchor.subject, card.trust_anchor.subject_alt, card.trust_anchor.server_cert, + force_flat_file_store, out error); if (error != null) -- 2.1.4