Beispiel #1
0
        //public const string DeleteRosterQuery = @"<query xmlns=""jabber:iq:roster""><item jid=""##JID##"" subscription=""remove"" /></query>";
        public void DeleteFromRoster(JID jid)
        {
            //<iq from='[email protected]/balcony'
             //      id='hm4hs97y'
             //      type='set'>
             //    <query xmlns='jabber:iq:roster'>
             //      <item jid='*****@*****.**'
             //            subscription='remove'/>
             //    </query>
             //  </iq>

            //string strDeleteQuery = DeleteRosterQuery.Replace("##JID##", jid.BareJID);

            RosterIQ DeleteRosterIQ = new RosterIQ();
            //DeleteRosterIQ.InnerXML = strDeleteQuery;
            DeleteRosterIQ.Type = IQType.set.ToString();
            DeleteRosterIQ.To = null;
            DeleteRosterIQ.From = XMPPClient.JID;
            //DeleteRosterIQ.xmlns = "jabber:client";

            rosteritem deleteitem = new rosteritem();
            deleteitem.JID = jid;
            deleteitem.Subscription = subscription.remove.ToString();

            DeleteRosterIQ.Query.RosterItems = new rosteritem[] { deleteitem };

            IQ IQResponse = XMPPClient.SendRecieveIQ(DeleteRosterIQ, 10000);
            if (IQResponse != null)
            {
            }
        }
Beispiel #2
0
 public RosterLogic(XMPPClient client)
     : base(client)
 {
     RosterIQ = new RosterIQ();
     RosterIQ.Type = IQType.get.ToString();
     RosterIQ.To = null;
     RosterIQ.From = null;
 }
Beispiel #3
0
        //public const string AddRosterQuery = @"<query xmlns=""jabber:iq:roster""><item jid=""##JID##"" name=""##NAME##""><group>##GROUP##</group></item></query>";
        public void AddToRoster(JID jid, string strName, string strGroup)
        {
            //<iq from='[email protected]/balcony'
             //      id='ph1xaz53'
             //      type='set'>
             //    <query xmlns='jabber:iq:roster'>
             //      <item jid='*****@*****.**'
             //            name='Nurse'>
             //        <group>Servants</group>
             //      </item>
             //    </query>
             //  </iq>

            //string strAddQuery = AddRosterQuery.Replace("##JID##", jid.BareJID);
            //strAddQuery = strAddQuery.Replace("##NAME##", strName);
            //strAddQuery = strAddQuery.Replace("##GROUP##", strGroup);

            RosterIQ AddRosterIQ = new RosterIQ();
            AddRosterIQ.Type = IQType.set.ToString();
            AddRosterIQ.To = null;
            AddRosterIQ.From = XMPPClient.JID;
            rosteritem newitem = new rosteritem();
            newitem.Name = strName;

            JID newjid = jid;
            if (newjid.User.Length <= 0)
            {
                newjid.User = newjid.Domain;
                newjid.Domain = XMPPClient.JID.Domain;
            }

            newitem.JID = newjid;
            newitem.Subscription = subscription.none.ToString();
            newitem.Groups = new string[] { strGroup };

            AddRosterIQ.Query.RosterItems = new rosteritem[] { newitem };

            IQ IQResponse = XMPPClient.SendRecieveIQ(AddRosterIQ, 10000);
            if (IQResponse != null)
            {
            }
        }
Beispiel #4
0
        public override bool NewIQ(IQ iq)
        {
            if (!(iq is RosterIQ))
            {
                return(false);
            }

            RosterIQ rostiq = iq as RosterIQ;

            if (iq.ID == RosterIQ.ID)
            {
                //<iq type="result" id="aab8a" to="[email protected]/hypnotoad">
                //<query xmlns="jabber:iq:roster">
                ///<item jid="*****@*****.**" name="BrianBonnett" subscription="both">
                ///    <group>Friends</group>
                ///</item>
                ///</query>
                ///</iq>
                ///


                this.Success = false;
                if (iq.Type == IQType.result.ToString())
                {
                    if ((rostiq.Query != null) && (rostiq.Query.RosterItems != null))
                    {
                        foreach (rosteritem item in rostiq.Query.RosterItems)
                        {
                            RosterItem ros = new RosterItem(XMPPClient, item.JID);

                            if (item.Ask == "subscribe")
                            {
                                /// Need to do subscribe to this user's presence some how
                                ///
                            }

                            /// See if we already have this roster item
                            ///
                            RosterItem existingitem = XMPPClient.FindRosterItem(ros.JID);
                            if (existingitem != null)
                            {
                                existingitem.Name         = (item.Name != null) ? item.Name : ros.JID.BareJID;
                                existingitem.Subscription = (item.Subscription != null) ? item.Subscription : "";
                                existingitem.Node         = item;
                                existingitem.Groups.Clear();
                                /// Get the group for this item
                                if (item.Groups != null)
                                {
                                    foreach (string strGroup in item.Groups)
                                    {
                                        ros.Group = strGroup;
                                        ros.Groups.Add(strGroup);
                                    }
                                }
                            }
                            else
                            {
                                ros.Name         = (item.Name != null) ? item.Name : ros.JID.BareJID;
                                ros.Subscription = (item.Subscription != null) ? item.Subscription : "";
                                ros.Node         = item;
                                XMPPClient.RosterItems.Add(ros);
                                /// Get the group for this item
                                if (item.Groups != null)
                                {
                                    foreach (string strGroup in item.Groups)
                                    {
                                        ros.Group = strGroup;
                                        if (ros.Groups.Contains(strGroup) == false)
                                        {
                                            ros.Groups.Add(strGroup);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    this.Success = true;
                    XMPPClient.FireGotRoster();
                }

                this.IsCompleted = false;

                return(true);
            }
            else if (iq.Type == "set")
            {
                //<iq type="set" id="640-356" to="[email protected]/phone"><query xmlns="jabber:iq:roster"><item jid="*****@*****.**" ask="subscribe" subscription="from"/></query></iq>

                if ((rostiq.Query != null) && (rostiq.Query.RosterItems != null))
                {
                    foreach (rosteritem item in rostiq.Query.RosterItems)
                    {
                        RosterItem ros = new RosterItem(XMPPClient, item.JID)
                        {
                            XMPPClient   = XMPPClient,
                            Name         = item.Name,
                            Subscription = item.Subscription,
                            Node         = item,
                        };

                        if (XMPPClient.FindRosterItem(ros.JID) == null)
                        {
                            XMPPClient.RosterItems.Add(ros);

                            if (item.Groups != null)
                            {
                                foreach (string strGroup in item.Groups)
                                {
                                    ros.Group = strGroup;
                                    if (ros.Groups.Contains(strGroup) == false)
                                    {
                                        ros.Groups.Add(strGroup);
                                    }
                                }
                            }

                            XMPPClient.AsyncFireListChanged();
                        }

                        if (item.Subscription == subscription.from.ToString())  /// should only have a from subscription if we've added the roster item
                        {
                            //if (XMPPClient.AutoAcceptPresenceSubscribe
                            /// subscribe to presence of this one
                            XMPPClient.PresenceLogic.SubscribeToPresence(ros.JID.BareJID);
                        }
                    }

                    iq.Type     = IQType.result.ToString();
                    iq.To       = iq.From;
                    iq.From     = XMPPClient.JID;
                    iq.InnerXML = null;
                    XMPPClient.SendXMPP(iq);

                    this.Success = true;
                    return(true);
                }
            }


            return(false);
        }