Add option to force use of flat file store to moonshot-webp
authorKevin Wasserman <krwasserman@hotmail.com>
Mon, 16 Sep 2013 20:12:01 +0000 (16:12 -0400)
committerKevin Wasserman <krwasserman@hotmail.com>
Mon, 16 Sep 2013 20:12:01 +0000 (16:12 -0400)
'-f' is the switch. Fixed usage statement.

libmoonshot/libmoonshot-dbus.c
libmoonshot/libmoonshot.h
libmoonshot/libmoonshot.vapi
src/moonshot-identities-manager.vala
src/moonshot-identity-management-view.vala
src/moonshot-identity-manager-app.vala
src/moonshot-server.vala
src/moonshot-webp-parser.vala

index 3dffeba..97dba1e 100644 (file)
@@ -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);
index 670dd87..d7830c2 100644 (file)
@@ -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
index d927663..8662596 100644 (file)
@@ -49,5 +49,6 @@ namespace Moonshot {
                                  string? subject,
                                  string? subject_alt,
                                  string? server_cert,
+                                 int force_flat_file_store,
                                  out Moonshot.Error error);
 }
index c6def5f..51f9d64 100644 (file)
@@ -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();
      }
 
index adcf8b4..1a89cf2 100644 (file)
@@ -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;
index 4237319..681d811 100644 (file)
@@ -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;
     }
 
index c415086..eb881d2 100644 (file)
@@ -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;
index 5d9775f..701042e 100644 (file)
@@ -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)