More fixes for Centos vala array property bug
[moonshot-ui.git] / src / moonshot-webp-parser.vala
1 using Moonshot;
2
3 namespace WebProvisioning
4
5
6
7   public static int main (string[] args)
8   {
9     int arg_index = -1;
10     int force_flat_file_store = 0;
11     bool bad_switch = false;
12     for (arg_index = 1; arg_index < args.length; arg_index++) {
13       string arg = args[arg_index];
14       unichar c = arg.get_char();
15       if (c=='-') {
16           arg = arg.next_char();
17           c = arg.get_char();
18           switch (c) {
19             case 'f':
20               force_flat_file_store = 1;
21               break;
22             default:
23               bad_switch = true;
24               break;
25           }
26       } else {
27         break; // arg is not a switch; presume it's the file
28       }
29     }
30     if (bad_switch || (arg_index != args.length - 1))
31     {
32       stdout.printf (_("Usage %s [-f] WEB_PROVISIONING_FILE\n -f: add identities to flat file store.\n"), args[0]);
33       return -1;
34     }
35     string webp_file = args[arg_index];
36     
37     if (!FileUtils.test (webp_file, FileTest.EXISTS | FileTest.IS_REGULAR))
38     {
39       stdout.printf (_("%s does not exist\n"), webp_file);
40       return -1;
41     }
42     
43     var webp = new Parser (webp_file);
44     webp.parse();
45     
46     foreach (IdCard card in cards)
47     {
48       Moonshot.Error error;
49       string[] rules_patterns = {};
50       string[] rules_always_confirm = {};
51         
52       /* use temp arrays to workaround centos array property bug */
53       var rules = card.rules;
54       var services = card.services;
55       if (rules.length > 0)
56       {
57         int i = 0;
58         rules_patterns = new string[rules.length];
59         rules_always_confirm = new string[rules.length];
60         foreach (Rule r in rules)
61         {
62           rules_patterns[i] = r.pattern;
63           rules_always_confirm[i] = r.always_confirm;
64           i++;
65         }
66       }
67
68       Moonshot.install_id_card (card.display_name,
69                                 card.username,
70                                 card.password,
71                                 card.issuer,
72                                 rules_patterns,
73                                 rules_always_confirm,
74                                 services,
75                                 card.trust_anchor.ca_cert,
76                                 card.trust_anchor.subject,
77                                 card.trust_anchor.subject_alt,
78                                 card.trust_anchor.server_cert,
79                                 force_flat_file_store,
80                                 out error);
81
82       if (error != null)
83       {
84         stderr.printf ("Error: %s", error.message);
85         continue;
86       }
87     }
88     
89     return 0;
90   }
91 }