1 namespace WebProvisioning
6 check_stack (SList<string> stack, string[] reference)
8 if (stack.length () < reference.length)
11 for (int i = 0; i<reference.length; i++)
13 if (stack.nth_data(i) != reference[i])
21 server_cert_handler (SList<string> stack)
23 string[] server_cert_path = {"server-cert", "trust-anchor", "identity", "identities"};
25 return check_stack (stack, server_cert_path);
29 subject_alt_handler (SList<string> stack)
31 string[] subject_alt_path = {"subject-alt", "trust-anchor", "identity", "identities"};
33 return check_stack (stack, subject_alt_path);
37 subject_handler (SList<string> stack)
39 string[] subject_path = {"subject", "trust-anchor", "identity", "identities"};
41 return check_stack (stack, subject_path);
45 ca_cert_handler (SList<string> stack)
47 string[] ca_path = {"ca-cert", "trust-anchor", "identity", "identities"};
49 return check_stack (stack, ca_path);
53 realm_handler (SList<string> stack)
55 string[] realm_path = {"realm", "identity", "identities"};
57 return check_stack (stack, realm_path);
61 password_handler (SList<string> stack)
63 string[] password_path = {"password", "identity", "identities"};
65 return check_stack (stack, password_path);
69 user_handler (SList<string> stack)
71 string[] user_path = {"user", "identity", "identities"};
73 return check_stack (stack, user_path);
77 display_name_handler (SList<string> stack)
79 string[] display_name_path = {"display-name", "identity", "identities"};
81 return check_stack (stack, display_name_path);
84 public void text_element_func (MarkupParseContext context,
86 size_t text_len) throws MarkupError
88 unowned SList<string> stack = context.get_element_stack ();
93 if (stack.nth_data(0) == "display-name" && display_name_handler (stack))
95 card.display_name = text;
97 else if (stack.nth_data(0) == "user" && user_handler (stack))
101 else if (stack.nth_data(0) == "password" && password_handler (stack))
103 card.password = text;
105 else if (stack.nth_data(0) == "realm" && realm_handler (stack))
109 else if (stack.nth_data(0) == "service")
111 string[] services = card.services;
112 card.services = new string[services.length + 1];
113 for (int i = 0; i<services.length; i++)
115 card.services[i] = services[i];
117 card.services[services.length] = text;
120 else if (stack.nth_data(0) == "pattern")
123 else if (stack.nth_data(0) == "always_confirm")
128 else if (stack.nth_data(0) == "ca-cert" && ca_cert_handler (stack))
130 card.trust_anchor.ca_cert = text;
132 else if (stack.nth_data(0) == "subject" && subject_handler (stack))
134 card.trust_anchor.subject = text;
136 else if (stack.nth_data(0) == "subject-alt" && subject_alt_handler (stack))
138 card.trust_anchor.subject_alt = text;
140 else if (stack.nth_data(0) == "server-cert" && server_cert_handler (stack))
142 card.trust_anchor.server_cert = text;
146 class WebProvisionParser
148 public WebProvisionParser (string path)
151 var file = File.new_for_path (path);
155 var dis = new DataInputStream (file.read ());
157 while ((line = dis.read_line (null)) != null)
162 error ("Could not retreive file size");
165 MarkupParser parser = {null, null, text_element_func, null, null};
167 var ctx = new MarkupParseContext(parser, 0, null, null);
171 ctx.parse (text, text.length);
175 error ("Could not parse %s, invalid content", path);
180 public static int main (string[] args)
184 error ("Usage %s [-a] WEB_PROVISIONING_FILE", args[0]);
187 if (!FileUtils.test (args[1], FileTest.EXISTS | FileTest.IS_REGULAR))
189 error ("%s does not exist", args[1]);
194 var webp = new WebProvisionParser (args[1]);
196 debug ("'%s' '%s' '%s' '%s'", card.display_name, card.username, card.password, card.issuer);
198 foreach (string srv in card.services)
200 debug ("service: %s", srv);