internal static void UpdatePublicSharediFolder(GaimBuddy[] buddies) { if (ShouldMaintainPublicSharediFolder()) { string iFolderName = BuildPublicSharediFolderName(); if (iFolderName == null) { log.Debug("BuildPublicSharediFolderName() returned null so we can't update the public shared iFolder"); return; } string userDesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string iFolderPath; if (MyEnvironment.Windows) { iFolderPath = string.Format("{0}\\{1}", userDesktopPath, iFolderName); } else { iFolderPath = string.Format("{0}/{1}", userDesktopPath, iFolderName); } log.Debug("Updating Public Shared iFolder: {0}", iFolderPath); Simias.Storage.Collection col = SharedCollection.GetCollectionByPath(iFolderPath); if(col == null) { try { if (!Directory.Exists(iFolderPath)) { Directory.CreateDirectory(iFolderPath); log.Debug("Created a new directory: {0}", iFolderPath); } } catch(DirectoryNotFoundException dnfe) { log.Debug(dnfe.Message); return; } catch(Exception e) { log.Debug(e.Message); return; } try { col = SharedCollection.CreateLocalSharedCollection( iFolderPath, Simias.Gaim.GaimDomain.ID, "iFolder"); log.Debug("Created a new iFolder: {0}", iFolderPath); } catch(Exception e) { log.Debug("Error creating the Public Shared iFolder: {0}", e.Message); return; } } UpdatePublicSharediFolderMembers(col, buddies); } }
internal static void UpdatePublicSharediFolderMembers(Simias.Storage.Collection col, GaimBuddy[] buddies) { Simias.Storage.Domain domain = GaimDomain.GetDomain(); if (domain == null) return; Hashtable subscribedUserIDs = new Hashtable(); Store store = Store.GetStore(); Simias.POBox.POBox poBox = Simias.POBox.POBox.FindPOBox(store, domain.ID, store.GetUserIDFromDomainID(domain.ID)); ICSList poList = poBox.Search( Simias.POBox.Subscription.SubscriptionCollectionIDProperty, col.ID, SearchOp.Equal); foreach(Simias.Storage.ShallowNode sNode in poList) { Simias.POBox.Subscription sub = new Simias.POBox.Subscription(poBox, sNode); if (sub.SubscriptionState == Simias.POBox.SubscriptionStates.Ready) { if (poBox.StoreReference.GetCollectionByID( sub.SubscriptionCollectionID) != null) { continue; } } subscribedUserIDs[sub.ToIdentity] = sub.ToIdentity; log.Debug("Added {0} to subscribedUserIDs", sub.ToName); } foreach (GaimBuddy buddy in buddies) { string[] machineNames = buddy.MachineNames; foreach (string machineName in machineNames) { Member member = FindBuddyInDomain(domain, buddy, machineName); if (member != null) { if (subscribedUserIDs[member.UserID] == null) { InviteUser(poBox, col, member); } } else { string memberName = buddy.GetSimiasMemberName(machineName); string memberUserID = buddy.GetSimiasUserID(machineName); if (memberName != null && memberUserID != null) { member = new Simias.Storage.Member( memberName, memberUserID, Simias.Storage.Access.Rights.ReadOnly ); string alias = buddy.Alias; if (alias != null) { member.FN = string.Format("{0} ({1})", alias, machineName); } domain.Commit( member ); log.Debug("Added new Gaim Domain Member in Simias: {0} ({1})", buddy.Name, machineName); InviteUser(poBox, col, member); } } } } }
internal static void UpdateMember(Simias.Storage.Domain domain, Member member, GaimBuddy buddy) { string[] machineNames = buddy.MachineNames; for (int i = 0; i < machineNames.Length; i++) { UpdateMember(domain, member, buddy, machineNames[i]); } }
internal static void UpdateMember(Simias.Storage.Domain domain, Member member, GaimBuddy buddy, string machineName) { Simias.Storage.PropertyList pList = member.Properties; Simias.Storage.Property p; string simiasURL = buddy.GetSimiasURL(machineName); if (simiasURL != null && simiasURL.Length > 0) { if (pList.HasProperty("Gaim:SimiasURL")) { Property oldProp = pList.GetSingleProperty("Gaim:SimiasURL"); if (!simiasURL.Equals((string)oldProp.Value)) { pList.ModifyProperty("Gaim:SimiasURL", simiasURL); } } else { p = new Property("Gaim:SimiasURL", simiasURL); p.LocalProperty = true; member.Properties.AddProperty(p); } } string alias = buddy.Alias; if (alias != null && alias.Length > 0) { if (pList.HasProperty("Gaim:Alias")) { Property oldProp = pList.GetSingleProperty("Gaim:Alias"); if (!alias.Equals((string)oldProp.Value)) { pList.ModifyProperty("Gaim:Alias", alias); } } else { p = new Property("Gaim:Alias", alias); p.LocalProperty = true; member.Properties.AddProperty(p); } string fullName = string.Format("{0} ({1})", alias, machineName); if (member.FN == null || !member.FN.Equals(fullName)) { member.FN = fullName; } } domain.Commit(member); }
internal static bool IsMemberInBuddyList(Member member, GaimBuddy[] buddies) { foreach (GaimBuddy buddy in buddies) { Simias.Storage.PropertyList pList = member.Properties; Simias.Storage.Property p = pList.GetSingleProperty("Gaim:MungedID"); if (p != null && ((string) p.Value) == buddy.MungedID) { return true; } } return false; }
internal static void PruneOldMembers(Simias.Storage.Domain domain, GaimBuddy[] buddies) { ICSList memberList = domain.GetMemberList(); foreach(ShallowNode sNode in memberList) { Simias.Storage.Member member = new Simias.Storage.Member(domain, sNode); if (member.IsOwner) continue; if (!IsMemberInBuddyList(member, buddies)) { domain.Commit(domain.Delete(member)); } } }
internal static GaimBuddy[] GetBuddies() { ArrayList buddies = new ArrayList(); XmlDocument blistDoc = new XmlDocument(); try { blistDoc.Load(GetGaimConfigDir() + "/blist.xml"); } catch { return (GaimBuddy[])buddies.ToArray(typeof(Simias.Gaim.GaimBuddy)); } XmlElement gaimElement = blistDoc.DocumentElement; XmlNodeList buddyNodes = gaimElement.SelectNodes("//buddy[setting[starts-with(@name, 'simias-url:')]]"); if (buddyNodes == null) return (GaimBuddy[])buddies.ToArray(typeof(Simias.Gaim.GaimBuddy)); foreach (XmlNode buddyNode in buddyNodes) { try { GaimBuddy buddy = new GaimBuddy(buddyNode); buddies.Add(buddy); } catch { } } return (GaimBuddy[])buddies.ToArray(typeof(Simias.Gaim.GaimBuddy)); }
internal static Member FindBuddyInDomain(Simias.Storage.Domain domain, GaimBuddy buddy, string machineName) { Member member = null; string simiasUserID = buddy.GetSimiasUserID(machineName); if (simiasUserID != null) { member = domain.GetMemberByID(simiasUserID); } return member; }
public static void UpdateMember(string AccountName, string AccountProtocolID, string BuddyName, string MachineName) { Simias.Storage.Domain domain = GaimDomain.GetDomain(); if (domain == null) return; XmlDocument blistDoc = new XmlDocument(); try { blistDoc.Load(GetGaimConfigDir() + "/blist.xml"); } catch { return; } XmlElement gaimElement = blistDoc.DocumentElement; string xPathQuery = string.Format("//buddy[@account='{0}' and @proto='{1}' and name='{2}' and setting[@name='simias-user-id:{3}']]", AccountName, AccountProtocolID, BuddyName, MachineName); XmlNode buddyNode = gaimElement.SelectSingleNode(xPathQuery); if (buddyNode != null) { try { GaimBuddy buddy = new GaimBuddy(buddyNode); Member member = FindBuddyInDomain(domain, buddy, MachineName); if (member != null) { UpdateMember(domain, member, buddy, MachineName); } } catch {} } }
public static GaimBuddy GetBuddyByUserID(string simiasUserID) { GaimBuddy buddy = null; XmlDocument blistDoc = new XmlDocument(); try { blistDoc.Load(GetGaimConfigDir() + "/blist.xml"); } catch (Exception e) { log.Debug("Couldn't load blist.xml"); log.Error(e.Message); log.Error(e.StackTrace); return null; } XmlElement gaimElement = blistDoc.DocumentElement; string xPathQuery = string.Format("//buddy[setting[starts-with(@name, 'simias-user-id:') and .='{0}']]", simiasUserID); XmlNode buddyNode = gaimElement.SelectSingleNode(xPathQuery); if (buddyNode != null) { try { buddy = new GaimBuddy(buddyNode); } catch {} } else { log.Debug("XmlElement.SelectSingleNode(\"{0}\") returned null", xPathQuery); } return buddy; }
public static Member FindBuddyInDomain(GaimBuddy buddy, string machineName) { Member member = null; Simias.Storage.Domain domain = GetDomain(); if (domain != null) { member = FindBuddyInDomain(domain, buddy, machineName); } return member; }