1 namespace WebProvisioning
7 check_stack (SList<string> stack, string[] reference)
9 if (stack.length () < reference.length)
12 for (int i = 0; i<reference.length; i++)
14 if (stack.nth_data(i) != reference[i])
22 server_cert_handler (SList<string> stack)
24 string[] server_cert_path = {"server-cert", "trust-anchor", "identity", "identities"};
26 return check_stack (stack, server_cert_path);
30 subject_alt_handler (SList<string> stack)
32 string[] subject_alt_path = {"subject-alt", "trust-anchor", "identity", "identities"};
34 return check_stack (stack, subject_alt_path);
38 subject_handler (SList<string> stack)
40 string[] subject_path = {"subject", "trust-anchor", "identity", "identities"};
42 return check_stack (stack, subject_path);
46 ca_cert_handler (SList<string> stack)
48 string[] ca_path = {"ca-cert", "trust-anchor", "identity", "identities"};
50 return check_stack (stack, ca_path);
54 realm_handler (SList<string> stack)
56 string[] realm_path = {"realm", "identity", "identities"};
58 return check_stack (stack, realm_path);
62 password_handler (SList<string> stack)
64 string[] password_path = {"password", "identity", "identities"};
66 return check_stack (stack, password_path);
70 user_handler (SList<string> stack)
72 string[] user_path = {"user", "identity", "identities"};
74 return check_stack (stack, user_path);
78 display_name_handler (SList<string> stack)
80 string[] display_name_path = {"display-name", "identity", "identities"};
82 return check_stack (stack, display_name_path);
86 start_element_func (MarkupParseContext context,
88 string[] attribute_names,
89 string[] attribute_values) throws MarkupError
91 debug ("START %s", element_name);
95 text_element_func (MarkupParseContext context,
97 size_t text_len) throws MarkupError
99 unowned SList<string> stack = context.get_element_stack ();
104 if (stack.nth_data(0) == "display-name" && display_name_handler (stack))
106 card.display_name = text;
108 else if (stack.nth_data(0) == "user" && user_handler (stack))
110 card.username = text;
112 else if (stack.nth_data(0) == "password" && password_handler (stack))
114 card.password = text;
116 else if (stack.nth_data(0) == "realm" && realm_handler (stack))
120 else if (stack.nth_data(0) == "service")
122 string[] services = card.services;
123 card.services = new string[services.length + 1];
124 for (int i = 0; i<services.length; i++)
126 card.services[i] = services[i];
128 card.services[services.length] = text;
131 else if (stack.nth_data(0) == "pattern")
134 else if (stack.nth_data(0) == "always_confirm")
139 else if (stack.nth_data(0) == "ca-cert" && ca_cert_handler (stack))
141 card.trust_anchor.ca_cert = text;
143 else if (stack.nth_data(0) == "subject" && subject_handler (stack))
145 card.trust_anchor.subject = text;
147 else if (stack.nth_data(0) == "subject-alt" && subject_alt_handler (stack))
149 card.trust_anchor.subject_alt = text;
151 else if (stack.nth_data(0) == "server-cert" && server_cert_handler (stack))
153 card.trust_anchor.server_cert = text;
159 private MarkupParser parser;
162 public Parser (string path)
167 var file = File.new_for_path (path);
171 var dis = new DataInputStream (file.read ());
173 while ((line = dis.read_line (null)) != null)
178 error ("Could not retreive file size");
181 parser = {start_element_func, null, text_element_func, null, null};
189 var ctx = new MarkupParseContext(parser, 0, null, null);
193 ctx.parse (text, text.length);
197 error ("Could not parse %s, invalid content", path);
202 public static int main (string[] args)
206 error ("Usage %s [-a] WEB_PROVISIONING_FILE", args[0]);
209 if (!FileUtils.test (args[1], FileTest.EXISTS | FileTest.IS_REGULAR))
211 error ("%s does not exist", args[1]);
214 var webp = new Parser (args[1]);
217 debug ("'%s' '%s' '%s' '%s'", card.display_name, card.username, card.password, card.issuer);
219 foreach (string srv in card.services)
221 debug ("service: %s", srv);