Merge branch 'master' of http://www.project-moonshot.org/git/moonshot-ui
[moonshot-ui.git] / src / moonshot-server.vala
index abae433..539dbc3 100644 (file)
@@ -3,11 +3,11 @@
 [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 async bool get_identity (string nai,
@@ -20,7 +20,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,7 +37,7 @@ 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;
 
@@ -72,7 +72,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;
@@ -115,15 +115,15 @@ public class MoonshotServer : Object {
 
     public bool install_id_card (string   display_name,
                                  string   user_name,
-                                 string   password,
-                                 string   realm,
-                                 string[] rules_patterns,
-                                 string[] rules_always_confirm,
-                                 string[] services,
-                                 string   ca_cert,
-                                 string   subject,
-                                 string   subject_alt,
-                                 string   server_cert)
+                                 string   ?password,
+                                 string   ?realm,
+                                 string[] ?rules_patterns,
+                                 string[] ?rules_always_confirm,
+                                 string[] ?services,
+                                 string   ?ca_cert,
+                                 string   ?subject,
+                                 string   ?subject_alt,
+                                 string   ?server_cert)
     {
       IdCard idcard = new IdCard ();
 
@@ -148,10 +148,55 @@ public class MoonshotServer : Object {
         }
       }
 
-      return this.main_window.add_identity (idcard);
+      return parent_app.add_identity (idcard);
     }
+
+
+    public int install_from_file (string file_name)
+    {
+    var webp = new WebProvisioning.Parser (file_name);
+
+    webp.parse();
+    bool result = false;
+    int installed_cards = 0;
+    foreach (IdCard card in WebProvisioning.cards)
+    {
+      string[] rules_patterns = {};
+      string[] rules_always_confirm = {};
+        
+      if (card.rules.length > 0)
+      {
+        int i = 0;
+        rules_patterns = new string[card.rules.length];
+        rules_always_confirm = new string[card.rules.length];
+        foreach (Rule r in card.rules)
+        {
+          rules_patterns[i] = r.pattern;
+          rules_always_confirm[i] = r.always_confirm;
+          i++;
+        }
+      } 
+
+      result = install_id_card (card.display_name,
+                                card.username,
+                                card.password,
+                                card.issuer,
+                                rules_patterns,
+                                rules_always_confirm,
+                                card.services,
+                                card.trust_anchor.ca_cert,
+                                card.trust_anchor.subject,
+                                card.trust_anchor.subject_alt,
+                                card.trust_anchor.server_cert);
+      if (result) {
+        installed_cards++;
+      }
+    }
+    return installed_cards;
+  }
 }
 
+
 #elif IPC_MSRPC
 
 using Rpc;
@@ -222,7 +267,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;
@@ -371,6 +416,8 @@ public class MoonshotServer : Object {
 
         return success;
     }
+
 }
 
+
 #endif