Merge branch 'master' of ssh://69.25.196.28:822/srv/git/moonshot-ui
authorSam Thursfield <samthursfield@codethink.co.uk>
Wed, 6 Jul 2011 15:30:00 +0000 (16:30 +0100)
committerSam Thursfield <samthursfield@codethink.co.uk>
Wed, 6 Jul 2011 15:49:24 +0000 (16:49 +0100)
Makefile.am
example/sample.xml [new file with mode: 0644]
src/moonshot-id.vala
src/moonshot-webp-parser.vala

index 57ea154..99e3392 100644 (file)
@@ -142,7 +142,7 @@ examples_client_CPPFLAGS = $(libmoonshot_CFLAGS) $(AM_CPPFLAGS)
 examples_client_LDADD = ${top_builddir}/libmoonshot/libmoonshot.la
 
 tests_basic_SOURCES = tests/basic.c
-tests_basic_CPPFLAGS = $(libmoonshot_CFLAGS) $(AM_CPPFLAGS)
+tests_basic_CPPFLAGS = $(moonshot_CFLAGS) $(AM_CPPFLAGS)
 tests_basic_LDADD = ${top_builddir}/libmoonshot/libmoonshot.la $(moonshot_LIBS)
 
 
diff --git a/example/sample.xml b/example/sample.xml
new file mode 100644 (file)
index 0000000..d9b324f
--- /dev/null
@@ -0,0 +1,33 @@
+<identities>
+  <identity>
+    <display-name>Unique Name</display-name>
+    <user>username</user>
+    <password>ENCRYPTEDPW</password>
+    <realm>issuer name</realm>
+    <services>
+      <service>xmpp@jabber.project-moonshot.org</service>
+      <service>email@project-moonshot.org</service>
+    </services>
+    <selection-rules>
+      <rule>
+        <pattern>PATTERN</pattern>
+        <always_confirm>true</always_confirm>
+      </rule>
+      <rule>
+        <pattern>ANOTHER_PATTERN</pattern>
+        <always_confirm>false</always_confirm>
+      </rule>
+    </selection-rules>
+    <trust-anchor>
+      <ca-cert>ABCDEFGHIJKLMNOPQRSTUVWXYZ123455678910</ca-cert>
+      <subject>Foo</subject>
+      <subject-alt>Bar</subject-alt>
+      <!-- Or alternatively -->
+      <server-cert>ABCDEFGHIJKLMNOPQRSTUVWXYZ123455678910</server-cert>
+    </trust-anchor>
+  </identity>
+  <identity>
+    <display-name>ASD</display-name>
+    <username>ASD</username>
+  </identity>
+</identities> 
index d82f1a6..9496970 100644 (file)
@@ -6,6 +6,12 @@ public class TrustAnchor : Object
   public string server_cert  {get; set; default = null;}
 }
 
+public struct Rule
+{
+  public string pattern;
+  public string always_confirm;
+}
+
 public class IdCard : Object
 {
   public string display_name { get; set; default = null; }
@@ -14,11 +20,13 @@ public class IdCard : Object
   public string password { get; set; default = null; }
 
   public string issuer { get; set; default = null; }
+  
+  public Rule[] rules {get; set; default = {};}
 
   public TrustAnchor trust_anchor  { get; set; default = new TrustAnchor (); }
   
   public Gdk.Pixbuf pixbuf { get; set; default = null; }    
-  public string[] services { get; set; default = null; }
+  public string[] services { get; set; default = {}; }
 
   //TODO: Set the getter and remove the setter/default
   public string nai { get; set; default = null; }
index 49dc5ac..44231af 100644 (file)
 namespace WebProvisioning
 { 
-  public IdCard card;
+  IdCard card;
+  IdCard[] cards;
 
-  public void text_element_func (MarkupParseContext context,
-                                 string text,
-                                 size_t text_len) throws MarkupError
+  bool
+  check_stack (SList<string> stack, string[] reference)
   {
-    unowned SList<string> stack = context.get_element_stack ();
+    if (stack.length () < reference.length)
+      return false;
     
-    if (stack.nth_data(0) == "display-name")
+    for (int i = 0; i<reference.length; i++)
+    {
+      if (stack.nth_data(i) != reference[i])
+        return false;
+    }
+
+    return true;
+  }
+
+  bool
+  server_cert_handler (SList<string> stack)
+  {
+    string[] server_cert_path = {"server-cert", "trust-anchor", "identity", "identities"};
+    
+    return check_stack (stack, server_cert_path);
+  }
+
+  bool
+  subject_alt_handler (SList<string> stack)
+  {
+    string[] subject_alt_path = {"subject-alt", "trust-anchor", "identity", "identities"};
+    
+    return check_stack (stack, subject_alt_path);
+  }
+
+  bool
+  subject_handler (SList<string> stack)
+  {
+    string[] subject_path = {"subject", "trust-anchor", "identity", "identities"};
+    
+    return check_stack (stack, subject_path);
+  }
+  
+  bool
+  ca_cert_handler (SList<string> stack)
+  {
+    string[] ca_path = {"ca-cert", "trust-anchor", "identity", "identities"};
+    
+    return check_stack (stack, ca_path);
+  }
+
+  bool
+  realm_handler (SList<string> stack)
+  {
+    string[] realm_path = {"realm", "identity", "identities"};
+    
+    return check_stack (stack, realm_path);
+  }
+
+  bool
+  password_handler (SList<string> stack)
+  {
+    string[] password_path = {"password", "identity", "identities"};
+    
+    return check_stack (stack, password_path);
+  }
+
+  bool
+  user_handler (SList<string> stack)
+  {
+    string[] user_path = {"user", "identity", "identities"};
+    
+    return check_stack (stack, user_path);
+  }
+
+  bool
+  display_name_handler (SList<string> stack)
+  {
+    string[] display_name_path = {"display-name", "identity", "identities"};
+    
+    return check_stack (stack, display_name_path);
+  }
+  
+  public void
+  start_element_func (MarkupParseContext context,
+                      string element_name,
+                      string[] attribute_names,
+                      string[] attribute_values) throws MarkupError
+  {
+    if (element_name == "identity")
+    {
+      IdCard[] tmp_cards = cards;
+
+      cards = new IdCard[tmp_cards.length + 1];
+      for (int i = 0; i<tmp_cards.length; i++)
+      {
+        cards[i] = tmp_cards[i];
+      }
+      card = new IdCard();
+      cards[tmp_cards.length] = card;
+    }
+    else if (element_name == "rule")
     {
-      
     }
+  }
 
+  public void
+  text_element_func (MarkupParseContext context,
+                     string             text,
+                     size_t             text_len) throws MarkupError
+  {
+    unowned SList<string> stack = context.get_element_stack ();
+    
+    if (text_len < 1)
+      return;
+    
+    if (stack.nth_data(0) == "display-name" && display_name_handler (stack))
+    {
+      card.display_name = text;
+    }
+    else if (stack.nth_data(0) == "user" && user_handler (stack))
+    {
+      card.username = text;
+    }
+    else if (stack.nth_data(0) == "password" && password_handler (stack))
+    {
+      card.password = text;
+    }
+    else if (stack.nth_data(0) == "realm" && realm_handler (stack))
+    {
+      card.issuer = text;
+    }
+    else if (stack.nth_data(0) == "service")
+    {
+      string[] services = card.services;
+      card.services = new string[services.length + 1];
+      for (int i = 0; i<services.length; i++)
+      {
+        card.services[i] = services[i];
+      }
+      card.services[services.length] = text;
+    }
+    /* Rules */
+    else if (stack.nth_data(0) == "pattern")
+    {
+    }
+    else if (stack.nth_data(0) == "always_confirm")
+    {
+    }
     
+    /*Trust anchor*/
+    else if (stack.nth_data(0) == "ca-cert" && ca_cert_handler (stack))
+    {
+      card.trust_anchor.ca_cert = text;
+    }
+    else if (stack.nth_data(0) == "subject" && subject_handler (stack))
+    {
+      card.trust_anchor.subject = text;
+    }
+    else if (stack.nth_data(0) == "subject-alt" && subject_alt_handler (stack))
+    {
+      card.trust_anchor.subject_alt = text;
+    }
+    else if (stack.nth_data(0) == "server-cert" && server_cert_handler (stack))
+    {
+      card.trust_anchor.server_cert = text;
+    }
   }
 
-  class WebProvisionParser
+  class Parser
   {
-    public WebProvisionParser (string path)
+    private MarkupParser parser;
+    private string       text;
+    private string       path;
+    public Parser (string path)
     {
-      string text = "";
+      text = "";
+      this.path = path;
+
       var file = File.new_for_path (path);
     
       try
@@ -35,8 +192,12 @@ namespace WebProvisioning
         error ("Could not retreive file size");
       }
       
-      MarkupParser parser = {null, null, text_element_func, null, null};
-      
+      parser = {start_element_func, null, text_element_func, null, null};
+    }
+    
+    public void
+    parse ()
+    {
       var ctx = new MarkupParseContext(parser, 0, null, null);
       
       try
@@ -62,8 +223,20 @@ namespace WebProvisioning
       error ("%s does not exist", args[1]);
     }
     
-    var webp = new WebProvisionParser (args[1]);
-
+    var webp = new Parser (args[1]);
+    webp.parse();
+    
+    foreach (IdCard card in cards)
+    {
+    
+      debug ("IDCARD: '%s' '%s' '%s' '%s'", card.display_name, card.username, card.password, card.issuer);
+    
+      foreach (string srv in card.services)
+      {
+        debug ("service: %s", srv);
+      }
+    }
+    
     return 0;
   }
 }