attempt DBUS_GLIB fix
[moonshot-ui.git] / src / moonshot-webp-parser.vala
index e7bda5b..5d9775f 100644 (file)
@@ -1,42 +1,11 @@
+using Moonshot;
+
 namespace WebProvisioning
-{
-  class WebProvisionParser
-  {
-    public WebProvisionParser (string path)
-    {
-      
-    }
-  }
-  
-  public void start_element_func (MarkupParseContext context,
-                             string             element_name,
-                             string[]           attribute_names,
-                             string[]           attribute_values) throws MarkupError
-  {
-    debug ("Start: %s", element_name);
-  }
+{ 
 
-  public void end_element_func (MarkupParseContext context,
-                           string             element_name) throws MarkupError
-  {
-    debug ("End: %s", element_name);
-  }
-  
-  public void text_element_func (MarkupParseContext context,
-                            string text,
-                            size_t text_len) throws MarkupError
-  {
-    debug ("Text element: %s", text); 
-/*    for (string i in context.get_element_stack ())
-    {
-      stdout.printf("%s\n", i);
-    }*/
-  }
-  
 
   public static int main (string[] args)
   {
-    string text = "";
     if (args.length < 2)
     {
       error ("Usage %s [-a] WEB_PROVISIONING_FILE", args[0]);
@@ -47,34 +16,48 @@ namespace WebProvisioning
       error ("%s does not exist", args[1]);
     }
     
-    var file = File.new_for_path (args[1]);
-    
-    try
-    {
-      var dis = new DataInputStream (file.read ());
-      string line;
-      while ((line = dis.read_line (null)) != null)
-        text += line;
-    }
-    catch (Error e)
-    {
-      error ("Could not retreive file size");
-    }
-    
-    MarkupParser parser = {start_element_func, end_element_func, text_element_func, null, null};
-    
-    var ctx = new MarkupParseContext(parser, 0, null, null);
-    
-    try
-    {
-      ctx.parse (text, text.length);
-    }
-    catch (Error e)
-    {
-      error ("Could not parse %s, invalid content", args[1]);
+    var webp = new Parser (args[1]);
+    webp.parse();
+    
+    foreach (IdCard card in cards)
+    {
+      Moonshot.Error error;
+      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++;
+        }
+      }
+
+      Moonshot.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,
+                                out error);
+
+      if (error != null)
+      {
+        stderr.printf ("Error: %s", error.message);
+        continue;
+      }
     }
     
-    
     return 0;
   }
 }