X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=src%2Fmoonshot-id.vala;h=2dc9ac2ce8e1a5a28f6fd0b0e91298ddd31084b2;hb=d10c51fc6a91a0e074d792a9013226e8ba959240;hp=2e0af57af34986f9871a7abe1e75af26644927f0;hpb=5b68b364f2c62fa43111b5a53c7040d34205ba20;p=moonshot-ui.git diff --git a/src/moonshot-id.vala b/src/moonshot-id.vala index 2e0af57..2dc9ac2 100644 --- a/src/moonshot-id.vala +++ b/src/moonshot-id.vala @@ -31,143 +31,174 @@ */ public class TrustAnchor : Object { - public string ca_cert {get; set; default = "";} - public string subject {get; set; default = "";} - public string subject_alt {get; set; default = "";} - public string server_cert {get; set; default = "";} - public int Compare(TrustAnchor other) - { - if (this.ca_cert != other.ca_cert) - return 1; - if (this.subject != other.subject) - return 1; - if (this.subject_alt != other.subject_alt) - return 1; - if (this.server_cert != other.server_cert) - return 1; - return 0; - } + public string ca_cert {get; set; default = "";} + public string subject {get; set; default = "";} + public string subject_alt {get; set; default = "";} + public string server_cert {get; set; default = "";} + public int Compare(TrustAnchor other) + { + if (this.ca_cert != other.ca_cert) + return 1; + if (this.subject != other.subject) + return 1; + if (this.subject_alt != other.subject_alt) + return 1; + if (this.server_cert != other.server_cert) + return 1; + return 0; + } } public struct Rule { - public string pattern; - public string always_confirm; - public int Compare(Rule other) { - if (this.pattern != other.pattern) - return 1; - if (this.always_confirm != other.always_confirm) - return 1; - return 0; - } + public string pattern; + public string always_confirm; + public int Compare(Rule other) { + if (this.pattern != other.pattern) + return 1; + if (this.always_confirm != other.always_confirm) + return 1; + return 0; + } } public class IdCard : Object { - public const string NO_IDENTITY = "No Identity"; + public const string NO_IDENTITY = "No Identity"; - private string _nai; + private string _nai; - public string display_name { get; set; default = ""; } + public string display_name { get; set; default = ""; } - public string username { get; set; default = ""; } + public string username { get; set; default = ""; } #if GNOME_KEYRING - private unowned string _password; - public string password { - get { - return (_password!=null) ? _password : ""; - } - set { - if (_password != null) { - GnomeKeyring.memory_free((void *)_password); - _password = null; - } - if (value != null) - _password = GnomeKeyring.memory_strdup(value); - } - } + private unowned string _password; + public string password { + get { + return (_password!=null) ? _password : ""; + } + set { + if (_password != null) { + GnomeKeyring.memory_free((void *)_password); + _password = null; + } + if (value != null) + _password = GnomeKeyring.memory_strdup(value); + } + } #else - public string password { get; set; default = null; } + public string password { get; set; default = null; } #endif - public string issuer { get; set; default = ""; } + public string issuer { get; set; default = ""; } - public Rule[] rules {get; set; default = {};} - public string[] services { get; set; default = {}; } - public bool temporary {get; set; default = false; } + private Rule[] _rules = {}; + public Rule[] rules { + get {return _rules;} + internal set {_rules = value ?? {};} + } + + private string[] _services = {}; + public string[] services { + get {return _services;} + internal set {_services = value ?? {};} + } - public TrustAnchor trust_anchor { get; set; default = new TrustAnchor (); } + public bool temporary {get; set; default = false; } + + public TrustAnchor trust_anchor { get; set; default = new TrustAnchor (); } - public unowned string nai { get { _nai = username + "@" + issuer; return _nai;}} - - public bool store_password { get; set; default = false; } - - public bool IsNoIdentity() - { - return (display_name == NO_IDENTITY); - } - - public enum DiffFlags { - DISPLAY_NAME, - USERNAME, - PASSWORD, - ISSUER, - RULES, - SERVICES, - TRUST_ANCHOR; - } - - public int Compare(IdCard other) - { - int diff = 0; - if (this.display_name != other.display_name) - diff |= 1 << DiffFlags.DISPLAY_NAME; - if (this.username != other.username) - diff |= 1 << DiffFlags.USERNAME; - if (this.password != other.password) - diff |= 1 << DiffFlags.PASSWORD; - if (this.issuer != other.issuer) - diff |= 1 << DiffFlags.ISSUER; - if (CompareRules(this.rules, other.rules)!=0) - diff |= 1 << DiffFlags.RULES; - if (CompareStringArray(this.services, other.services)!=0) - diff |= 1 << DiffFlags.SERVICES; - if (this.trust_anchor.Compare(other.trust_anchor)!=0) - diff |= 1 << DiffFlags.TRUST_ANCHOR; - stdout.printf("Diff Flags: %x\n", diff); - return diff; - } - - public static IdCard NewNoIdentity() - { - IdCard card = new IdCard(); - card.display_name = NO_IDENTITY; - return card; - } - - ~IdCard() { - password = null; - } + public unowned string nai { get { _nai = username + "@" + issuer; return _nai;}} + + public bool store_password { get; set; default = false; } + + public bool IsNoIdentity() + { + return (display_name == NO_IDENTITY); + } + + public enum DiffFlags { + DISPLAY_NAME, + USERNAME, + PASSWORD, + ISSUER, + RULES, + SERVICES, + TRUST_ANCHOR; + } + + public int Compare(IdCard other) + { + int diff = 0; + if (this.display_name != other.display_name) + diff |= 1 << DiffFlags.DISPLAY_NAME; + + if (this.username != other.username) + diff |= 1 << DiffFlags.USERNAME; + + if (this.password != other.password) + diff |= 1 << DiffFlags.PASSWORD; + + if (this.issuer != other.issuer) + diff |= 1 << DiffFlags.ISSUER; + + if (CompareRules(this.rules, other.rules)!=0) + diff |= 1 << DiffFlags.RULES; + + if (CompareStringArray(this.services, other.services)!=0) + diff |= 1 << DiffFlags.SERVICES; + + if (this.trust_anchor.Compare(other.trust_anchor)!=0) + diff |= 1 << DiffFlags.TRUST_ANCHOR; + + // stdout.printf("Diff Flags: %x\n", diff); + return diff; + } + + public static IdCard NewNoIdentity() + { + IdCard card = new IdCard(); + card.display_name = NO_IDENTITY; + return card; + } + + ~IdCard() { + password = null; + } + + internal void add_rule(Rule rule) { + _rules += rule; + } + + internal void add_service(string service) { + _services += service; + } } public int CompareRules(Rule[] a, Rule[] b) { - if (a.length != b.length) - return 1; - for (int i=0; i