Modify identity selection logic / fix bugs
[moonshot-ui.git] / src / moonshot-server.vala
index c581860..6b2f864 100644 (file)
@@ -3,11 +3,21 @@
 [DBus (name = "org.janet.Moonshot")]
 public class MoonshotServer : Object {
 
-    private IdentityManagerView main_window;
+    private IdentityManagerApp parent_app;
 
-    public MoonshotServer (Gtk.Window window)
+    public MoonshotServer (IdentityManagerApp app)
     {
-        this.main_window = (IdentityManagerView) window;
+        this.parent_app = app;
+    }
+
+    public bool show_ui()
+    {
+        if (parent_app.view == null) {
+            return false;
+        }
+        parent_app.show();
+        parent_app.explicitly_launched = true;
+        return true;
     }
 
     public async bool get_identity (string nai,
@@ -20,7 +30,7 @@ public class MoonshotServer : Object {
                                     out string subject_name_constraint,
                                     out string subject_alt_name_constraint)
     {
-        var request = new IdentityRequest (main_window,
+        var request = new IdentityRequest (parent_app,
                                            nai,
                                            password,
                                            service);
@@ -37,9 +47,12 @@ public class MoonshotServer : Object {
 
         var id_card = request.id_card;
 
-        if (id_card != null) {
+        if ((id_card != null) && (id_card.display_name != IdCard.NO_IDENTITY)) {
             nai_out = id_card.nai;
-            password_out = id_card.password;
+            if ((request.password!=null) && (request.password != ""))
+                password_out = request.password;
+            else
+                password_out = id_card.password;
 
             server_certificate_hash = id_card.trust_anchor.server_cert;
             ca_certificate = id_card.trust_anchor.ca_cert;
@@ -72,7 +85,7 @@ public class MoonshotServer : Object {
                                             out string subject_name_constraint,
                                             out string subject_alt_name_constraint)
     {
-        var request = new IdentityRequest.default (main_window);
+        var request = new IdentityRequest.default (parent_app);
         request.set_callback ((IdentityRequest) => get_default_identity.callback());
         request.execute ();
         yield;
@@ -123,13 +136,16 @@ 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 ();
 
       idcard.display_name = display_name;
       idcard.username = user_name;
       idcard.password = password;
+      if ((password != null) && (password != ""))
+        idcard.store_password = true;
       idcard.issuer = realm;
       idcard.services = services;
       idcard.trust_anchor.ca_cert = ca_cert;
@@ -148,7 +164,7 @@ public class MoonshotServer : Object {
         }
       }
 
-      return main_window.add_identity (idcard);
+      return parent_app.add_identity (idcard, force_flat_file_store!=0);
     }
 
 
@@ -187,7 +203,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++;
       }
@@ -211,13 +228,13 @@ using MoonshotRpcInterface;
  * process ends
  */
 public class MoonshotServer : Object {
-    private static IdentityManagerView main_window;
+    private static IdentityManagerApp parent_app;
 
     private static MoonshotServer instance = null;
 
-    public static void start (Gtk.Window window)
+    public static void start (IdentityManagerApp app)
     {
-        main_window = (IdentityManagerView) window;
+        parent_app = app;
         Rpc.server_start (MoonshotRpcInterface.spec, "/org/janet/Moonshot", Rpc.Flags.PER_USER);
     }
 
@@ -242,7 +259,7 @@ public class MoonshotServer : Object {
     {
         bool result = false;
 
-        var request = new IdentityRequest (main_window,
+        var request = new IdentityRequest (parent_app,
                                            nai,
                                            password,
                                            service);
@@ -267,7 +284,7 @@ public class MoonshotServer : Object {
 
         var id_card = request.id_card;
 
-        if (id_card == null) {
+        if (id_card != null) {
             // The strings are freed by the RPC runtime
             nai_out = id_card.nai;
             password_out = id_card.password;
@@ -304,7 +321,7 @@ public class MoonshotServer : Object {
     {
         bool result;
 
-        var request = new IdentityRequest.default (main_window);
+        var request = new IdentityRequest.default (parent_app);
         request.mutex = new Mutex ();
         request.cond = new Cond ();
         request.set_callback (return_identity_cb);
@@ -372,7 +389,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;
@@ -405,7 +423,7 @@ public class MoonshotServer : Object {
         // Defer addition to the main loop thread.
         Idle.add (() => {
             mutex.lock ();
-            success = main_window.add_identity (idcard);
+            success = parent_app.add_identity (idcard, force_flat_file_store);
             cond.signal ();
             mutex.unlock ();
             return false;