From 6b0f6bc13635613d8fc363652503760a05b79ea4 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Mon, 4 Jul 2011 17:43:57 +0100 Subject: [PATCH] Added more data fields to IdCard, new TrustAnchor class --- Makefile.am | 2 +- src/moonshot-id.vala | 28 +++++++++---- src/moonshot-webp-parser.vala | 95 +++++++++++++++++++------------------------ 3 files changed, 64 insertions(+), 61 deletions(-) diff --git a/Makefile.am b/Makefile.am index 475b2b7..de028e5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -101,7 +101,7 @@ endif bin_PROGRAMS += src/moonshot-webp -src_moonshot_webp_SOURCES = src/moonshot-webp-parser.vala +src_moonshot_webp_SOURCES = src/moonshot-webp-parser.vala src/moonshot-id.vala src_moonshot_webp_LDADD = $(moonshot_LIBS) if IPC_DBUS diff --git a/src/moonshot-id.vala b/src/moonshot-id.vala index 536a1a6..d82f1a6 100644 --- a/src/moonshot-id.vala +++ b/src/moonshot-id.vala @@ -1,11 +1,25 @@ +public class TrustAnchor : Object +{ + public string ca_cert {get; set; default = null;} + public string subject {get; set; default = null;} + public string subject_alt {get; set; default = null;} + public string server_cert {get; set; default = null;} +} + +public class IdCard : Object +{ + public string display_name { get; set; default = null; } + + public string username { get; set; default = null; } + public string password { get; set; default = null; } -class IdCard : Object { + public string issuer { get; set; default = null; } - public Gdk.Pixbuf pixbuf {get; set; default = null; } - public string issuer { get; set; default = null; } - public string username { get; set; default = null; } - public string password { get; set; default = null; } - public string[] services { get; set; default = null; } - public string nai { get; set; default = null; } + public TrustAnchor trust_anchor { get; set; default = new TrustAnchor (); } + + public Gdk.Pixbuf pixbuf { get; set; default = null; } + public string[] services { get; set; default = null; } + //TODO: Set the getter and remove the setter/default + public string nai { get; set; default = null; } } diff --git a/src/moonshot-webp-parser.vala b/src/moonshot-webp-parser.vala index 16ce39e..49dc5ac 100644 --- a/src/moonshot-webp-parser.vala +++ b/src/moonshot-webp-parser.vala @@ -1,42 +1,57 @@ namespace WebProvisioning -{ - class WebProvisionParser +{ + public IdCard card; + + public void text_element_func (MarkupParseContext context, + string text, + size_t text_len) throws MarkupError { - public WebProvisionParser (string path) + unowned SList stack = context.get_element_stack (); + + if (stack.nth_data(0) == "display-name") { } - } - - 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 + + class WebProvisionParser { - debug ("Text element: %s", text); - foreach (string elm in context.get_element_stack ()) + public WebProvisionParser (string path) { - stdout.printf("%s\n", elm); + string text = ""; + var file = File.new_for_path (path); + + 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 = {null, null, 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", path); + } } } - public static int main (string[] args) { - string text = ""; if (args.length < 2) { error ("Usage %s [-a] WEB_PROVISIONING_FILE", args[0]); @@ -47,34 +62,8 @@ 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 WebProvisionParser (args[1]); + return 0; } } -- 2.1.4