(Rename sources for RPC servers)
[moonshot-ui.git] / src / moonshot-server-dbus.vala
1 [DBus (name = "org.janet.Moonshot")]
2 public class MoonshotServer : Object {
3
4     private MainWindow main_window;
5
6     public MoonshotServer (Gtk.Window window)
7     {
8         this.main_window = (MainWindow) window;
9     }
10
11     /**
12      * This is the function used by the GSS mechanism to get the NAI,
13      * password and certificate of the ID card for the specificated service.
14      *
15      * The function will block until the user choose the ID card.
16      *
17      * @param nai NAI of the ID Card (optional)
18      * @param password Password of the ID Card (optional)
19      * @param service Service application request an ID Card for
20      * @param nai_out NAI stored in the ID Card
21      * @param password_out Password stored in the ID Card
22      * @param certificate Certificate stored in th ID Card
23      *
24      * @return true if the user choose a correct ID card for that service,
25      *         false otherwise.
26      */
27     public async bool get_identity (string nai,
28                                     string password,
29                                     string service,
30                                     out string nai_out,
31                                     out string password_out,
32                                     out string certificate_out)
33     {
34         bool has_service = false;
35
36         var request = new IdentityRequest (main_window,
37                                            nai,
38                                            password,
39                                            service);
40         request.set_callback ((IdentityRequest) => get_identity.callback());
41         request.execute ();
42         yield;
43
44         nai_out = "";
45         password_out = "";
46         certificate_out = "";
47
48         var id_card = request.id_card;
49
50         if (id_card != null) {
51             foreach (string id_card_service in id_card.services)
52             {
53                 if (id_card_service == service)
54                     has_service = true;
55             }
56
57             if (has_service)
58             {
59                 nai_out = id_card.nai;
60                 password_out = id_card.password;
61                 certificate_out = "certificate";
62
63                 return true;
64             }
65         }
66
67         return false;
68     }
69 }