ace5ba2fd202e52c9d3b3b1a4328888899ab61ba
[moonshot-ui.git] / src / moonshot-dbus-server.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         nai_out = "";
37         password_out = "";
38         certificate_out = "";
39
40         main_window.set_callback (get_identity.callback);
41         yield;
42
43         var id_card = this.main_window.selected_id_card_widget.id_card;
44
45         foreach (string id_card_service in id_card.services)
46         {
47             if (id_card_service == service)
48                 has_service = true;
49         }
50
51         if (has_service)
52         {
53             nai_out = id_card.nai;
54             password_out = id_card.password;
55             certificate_out = "certificate";
56
57             return true;
58         }
59
60         return false;
61     }
62 }