- IdCard identity = null;
-
- this.request_queue.push_tail (request);
-
- if (custom_vbox.current_idcard != null &&
- custom_vbox.current_idcard.send_button != null)
- custom_vbox.current_idcard.send_button.set_sensitive (true);
-
- if (request.select_default)
- {
- identity = default_id_card;
- }
-
- if (identity == null)
- {
- bool has_nai = request.nai != null && request.nai != "";
- bool has_srv = request.service != null && request.service != "";
- bool confirm = false;
- IdCard nai_provided = null;
-
- foreach (IdCard id in identities_manager.get_card_list())
- {
- /* If NAI matches we add id card to the candidate list */
- if (has_nai && request.nai == id.nai)
- {
- nai_provided = id;
- add_candidate (id);
- continue;
- }
-
- /* If any service matches we add id card to the candidate list */
- if (has_srv)
- {
- foreach (string srv in id.services)
- {
- if (request.service == srv)
- {
- add_candidate (id);
- continue;
- }
- }
- }
- }
-
- /* If more than one candidate we dissasociate service from all ids */
- if (has_srv && candidates.length() > 1)
- {
- foreach (IdCard id in candidates)
- {
- int i = 0;
- SList<string> services_list = null;
- bool has_service = false;
-
- foreach (string srv in id.services)
- {
- if (srv == request.service)
- {
- has_service = true;
- continue;
- }
- services_list.append (srv);
- }
-
- if (!has_service)
- continue;
-
- if (services_list.length () == 0)
- {
- id.services = {};
- continue;
- }
-
- string[] services = new string[services_list.length ()];
- foreach (string srv in services_list)
- {
- services[i] = srv;
- i++;
- }
-
- id.services = services;
- }
- }
-
-// identities_manager.store_id_cards ();
-
- /* If there are no candidates we use the service matching rules */
- if (candidates.length () == 0)
- {
- foreach (IdCard id in identities_manager.get_card_list())
- {
- foreach (Rule rule in id.rules)
- {
- if (!match_service_pattern (request.service, rule.pattern))
- continue;
-
- candidates.append (id);
-
- if (rule.always_confirm == "true")
- confirm = true;
- }
- }
- }
-
- if (candidates.length () > 1)
- {
- if (has_nai && nai_provided != null)
- {
- identity = nai_provided;
- confirm = false;
- }
- else
- confirm = true;
- }
- else
- identity = candidates.nth_data (0);
-
- /* TODO: If candidate list empty return fail */
-
- if (confirm)
- {
- filter.refilter();
- redraw_id_card_widgets ();
- show ();
- return;
- }
- }
- // Send back the identity (we can't directly run the
- // callback because we may be being called from a 'yield')
- Idle.add (() => { send_identity_cb (identity); return false; });
- return;
- }
-
- private bool match_service_pattern (string service, string pattern)
- {
- var pspec = new PatternSpec (pattern);
- return pspec.match_string (service);