3 [DBus (name = "org.janet.Moonshot")]
4 public class MoonshotServer : Object {
6 private MainWindow main_window;
8 public MoonshotServer (Gtk.Window window)
10 this.main_window = (MainWindow) window;
14 * This is the function used by the GSS mechanism to get the NAI,
15 * password and certificate of the ID card for the specificated service.
17 * The function will block until the user choose the ID card.
19 * @param nai NAI of the ID Card (optional)
20 * @param password Password of the ID Card (optional)
21 * @param service Service application request an ID Card for (optional)
22 * @param nai_out NAI stored in the ID Card
23 * @param password_out Password stored in the ID Card
24 * @param certificate Certificate stored in th ID Card
26 * @return true if the user choose a correct ID card for that service,
29 public async bool get_identity (string nai,
33 out string password_out,
34 out string certificate_out)
36 var request = new IdentityRequest (main_window,
40 request.set_callback ((IdentityRequest) => get_identity.callback());
48 var id_card = request.id_card;
50 if (id_card != null) {
51 nai_out = id_card.nai;
52 password_out = id_card.password;
53 certificate_out = "certificate";
55 // User should have been prompted if there was no p/w.
56 return_if_fail (nai_out != null);
57 return_if_fail (password_out != null);
66 * Returns the default identity - most recently used.
68 * @param nai_out NAI stored in the ID card
69 * @param password_out Password stored in the ID card
71 * @return true on success, false if no identities are stored
73 public async bool get_default_identity (out string nai_out,
74 out string password_out)
76 var request = new IdentityRequest.default (main_window);
77 request.set_callback ((IdentityRequest) => get_default_identity.callback());
84 if (request.id_card != null)
86 nai_out = request.id_card.nai;
87 password_out = request.id_card.password;
89 // User should have been prompted if there was no p/w.
90 return_val_if_fail (nai_out != null, false);
91 return_val_if_fail (password_out != null, false);
103 using MoonshotRpcInterface;
105 /* This class must be a singleton, because we use a global RPC
106 * binding handle. I cannot picture a situation where more than
107 * one instance of the same interface would be needed so this
108 * shouldn't be a problem.
110 * Shutdown is automatically done by the RPC runtime when the
113 public class MoonshotServer : Object {
114 private static MainWindow main_window;
116 private static MoonshotServer instance = null;
118 public static void start (Gtk.Window window)
120 main_window = (MainWindow) window;
121 Rpc.server_start (MoonshotRpcInterface.spec, "/org/janet/Moonshot", Rpc.Flags.PER_USER);
124 public static MoonshotServer get_instance ()
126 if (instance == null)
127 instance = new MoonshotServer ();
131 [CCode (cname = "moonshot_get_identity")]
132 public static void get_identity (Rpc.AsyncCall call,
137 ref string password_out,
138 ref string certificate_out)
142 var request = new IdentityRequest (main_window,
147 // Pass execution to the main loop and block the RPC thread
148 request.mutex = new Mutex ();
149 request.cond = new Cond ();
150 request.set_callback (return_identity_cb);
152 request.mutex.lock ();
153 Idle.add (request.execute);
155 while (request.complete == false)
156 request.cond.wait (request.mutex);
160 certificate_out = "";
162 var id_card = request.id_card;
164 if (id_card == null) {
165 // The strings are freed by the RPC runtime
166 nai_out = id_card.nai;
167 password_out = id_card.password;
168 certificate_out = "certificate";
170 return_if_fail (nai_out != null);
171 return_if_fail (password_out != null);
176 // The outputs must be set before this function is called. For this
177 // reason they are 'ref' not 'out' parameters - Vala assigns to the
178 // 'out' parameters only at the end of the function, which is too
180 call.return (&result);
182 request.cond.signal ();
183 request.mutex.unlock ();
186 [CCode (cname = "moonshot_get_default_identity")]
187 public static void get_default_identity (Rpc.AsyncCall call,
189 ref string password_out)
193 var request = new IdentityRequest.default (main_window);
194 request.mutex = new Mutex ();
195 request.cond = new Cond ();
196 request.set_callback (return_identity_cb);
198 request.mutex.lock ();
199 Idle.add (request.execute);
201 while (request.complete == false)
202 request.cond.wait (request.mutex);
207 if (request.id_card != null)
209 nai_out = request.id_card.nai;
210 password_out = request.id_card.password;
212 return_if_fail (nai_out != null);
213 return_if_fail (password_out != null);
222 call.return (&result);
224 request.cond.signal ();
225 request.mutex.unlock ();
228 // Called from the main loop thread when an identity has
230 static void return_identity_cb (IdentityRequest request) {
231 // Notify the RPC thread that the request is complete
232 request.mutex.lock ();
233 request.cond.signal ();
235 // Block the main loop until the RPC call has returned
236 // to avoid any races
237 request.cond.wait (request.mutex);
238 request.mutex.unlock ();