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;
13 public async bool get_identity (string nai,
17 out string password_out,
18 out string server_certificate_hash,
19 out string ca_certificate,
20 out string subject_name_constraint,
21 out string subject_alt_name_constraint)
23 var request = new IdentityRequest (main_window,
27 request.set_callback ((IdentityRequest) => get_identity.callback());
33 server_certificate_hash = "";
35 subject_name_constraint = "";
36 subject_alt_name_constraint = "";
38 var id_card = request.id_card;
40 if (id_card != null) {
41 nai_out = id_card.nai;
42 password_out = id_card.password;
44 server_certificate_hash = "certificate";
46 // User should have been prompted if there was no p/w.
47 return_if_fail (nai_out != null);
48 return_if_fail (password_out != null);
56 public async bool get_default_identity (out string nai_out,
57 out string password_out)
59 var request = new IdentityRequest.default (main_window);
60 request.set_callback ((IdentityRequest) => get_default_identity.callback());
67 if (request.id_card != null)
69 nai_out = request.id_card.nai;
70 password_out = request.id_card.password;
72 // User should have been prompted if there was no p/w.
73 return_val_if_fail (nai_out != null, false);
74 return_val_if_fail (password_out != null, false);
86 using MoonshotRpcInterface;
88 /* This class must be a singleton, because we use a global RPC
89 * binding handle. I cannot picture a situation where more than
90 * one instance of the same interface would be needed so this
91 * shouldn't be a problem.
93 * Shutdown is automatically done by the RPC runtime when the
96 public class MoonshotServer : Object {
97 private static MainWindow main_window;
99 private static MoonshotServer instance = null;
101 public static void start (Gtk.Window window)
103 main_window = (MainWindow) window;
104 Rpc.server_start (MoonshotRpcInterface.spec, "/org/janet/Moonshot", Rpc.Flags.PER_USER);
107 public static MoonshotServer get_instance ()
109 if (instance == null)
110 instance = new MoonshotServer ();
114 [CCode (cname = "moonshot_get_identity_rpc")]
115 public static void get_identity (Rpc.AsyncCall call,
120 ref string password_out,
121 ref string server_certificate_hash,
122 ref string ca_certificate,
123 ref string subject_name_constraint,
124 ref string subject_alt_name_constraint)
128 var request = new IdentityRequest (main_window,
133 // Pass execution to the main loop and block the RPC thread
134 request.mutex = new Mutex ();
135 request.cond = new Cond ();
136 request.set_callback (return_identity_cb);
138 request.mutex.lock ();
139 Idle.add (request.execute);
141 while (request.complete == false)
142 request.cond.wait (request.mutex);
146 server_certificate_hash = "";
148 subject_name_constraint = "";
149 subject_alt_name_constraint = "";
151 var id_card = request.id_card;
153 if (id_card == null) {
154 // The strings are freed by the RPC runtime
155 nai_out = id_card.nai;
156 password_out = id_card.password;
157 server_certificate_hash = "certificate";
159 return_if_fail (nai_out != null);
160 return_if_fail (password_out != null);
165 // The outputs must be set before this function is called. For this
166 // reason they are 'ref' not 'out' parameters - Vala assigns to the
167 // 'out' parameters only at the end of the function, which is too
169 call.return (&result);
171 request.cond.signal ();
172 request.mutex.unlock ();
175 [CCode (cname = "moonshot_get_default_identity_rpc")]
176 public static void get_default_identity (Rpc.AsyncCall call,
178 ref string password_out)
182 var request = new IdentityRequest.default (main_window);
183 request.mutex = new Mutex ();
184 request.cond = new Cond ();
185 request.set_callback (return_identity_cb);
187 request.mutex.lock ();
188 Idle.add (request.execute);
190 while (request.complete == false)
191 request.cond.wait (request.mutex);
196 if (request.id_card != null)
198 nai_out = request.id_card.nai;
199 password_out = request.id_card.password;
201 return_if_fail (nai_out != null);
202 return_if_fail (password_out != null);
211 call.return (&result);
213 request.cond.signal ();
214 request.mutex.unlock ();
217 // Called from the main loop thread when an identity has
219 static void return_identity_cb (IdentityRequest request) {
220 // Notify the RPC thread that the request is complete
221 request.mutex.lock ();
222 request.cond.signal ();
224 // Block the main loop until the RPC call has returned
225 // to avoid any races
226 request.cond.wait (request.mutex);
227 request.mutex.unlock ();