Esempio n. 1
0
        public static void CreateNode(XMPPClient connection, string strNode, string strParentNode, PubSubConfigForm nodeform)
        {
            IQ pubsub = new IQ();

            pubsub.Type = IQType.set.ToString();
            pubsub.From = connection.JID;
            pubsub.To   = new JID(string.Format("pubsub.{0}", connection.Domain));


            string strXML = CreateNodeXML.Replace("#NODE#", strNode);

            /// Get inner xml
            ///
            string strForm = nodeform.BuildAskingForm(nodeform);

            strXML          = strXML.Replace("#x#", strForm);
            pubsub.InnerXML = strXML;

            IQ IQResponse = connection.SendRecieveIQ(pubsub, 10000);

            if (IQResponse == null)
            {
                return;
            }
            if (IQResponse.Type == IQType.error.ToString())
            {
                return;
            }
        }
Esempio n. 2
0
        public static string[] GetRootNodes(XMPPClient connection)
        {
            List <string> SubNodeList = new List <string>();
            string        strXML      = FetchChildNodesRoot;
            IQ            IQRequest   = new IQ();

            IQRequest.From     = connection.JID;
            IQRequest.To       = string.Format("pubsub.{0}", connection.Domain);
            IQRequest.Type     = IQType.get.ToString();
            IQRequest.InnerXML = strXML;

            IQ IQResponse = connection.SendRecieveIQ(IQRequest, 10000);

            if (IQResponse == null)
            {
                return(null);
            }

            if (IQResponse.Type == IQType.error.ToString())
            {
                return(SubNodeList.ToArray());
            }

            var nodes = IQResponse.InitalXMLElement.Descendants("{http://jabber.org/protocol/disco#items}item");

            foreach (XElement elem in nodes)
            {
                XAttribute attrnode = elem.Attribute("node");
                SubNodeList.Add(attrnode.Value);
            }


            return(SubNodeList.ToArray());
        }
Esempio n. 3
0
        void StartAuthentication()
        {
            if ((AuthMethodsSupported & AuthMethod.MD5) == AuthMethod.MD5)
            {
                AuthMethodUsed = AuthMethod.MD5;
                XMPPClient.SendRawXML(MD5Auth);
            }
            else if (((AuthMethodsSupported & AuthMethod.Plain) == AuthMethod.Plain) && (XMPPClient.UseTLS == true))
            {
                AuthMethodUsed = AuthMethod.Plain;

                byte[] bUserName = System.Text.UTF8Encoding.UTF8.GetBytes(XMPPClient.UserName);
                byte[] bPassword = System.Text.UTF8Encoding.UTF8.GetBytes(XMPPClient.Password);
                byte[] bText     = new byte[2 + bUserName.Length + bPassword.Length];
                bText[0] = 0;
                Array.Copy(bUserName, 0, bText, 1, bUserName.Length);
                bText[bUserName.Length + 1] = 0;
                Array.Copy(bPassword, 0, bText, 1 + bUserName.Length + 1, bPassword.Length);

                string strBase64Text   = Convert.ToBase64String(bText);
                string ResponseMessage = PlainAuth.Replace("##RESPONSE##", strBase64Text);
                XMPPClient.SendRawXML(ResponseMessage);
            }
            // Needs some type of google token retrieved from http or something
            //else if (((AuthMethodsSupported & AuthMethod.googletoken) == AuthMethod.googletoken) && (XMPPClient.UseTLS == true))
            //{
            //    AuthMethodUsed = AuthMethod.googletoken;

            //    string strText = string.Format("\0{0}@{1}\0{2}", XMPPClient.UserName, XMPPClient.Domain, XMPPClient.Password);
            //    byte[] bText = System.Text.UTF8Encoding.UTF8.GetBytes(strText);
            //    string strBase64Text = Convert.ToBase64String(bText);
            //    string ResponseMessage = PlainAuth.Replace("##RESPONSE##", strBase64Text);
            //    XMPPClient.SendRawXML(ResponseMessage);
            //}
        }
Esempio n. 4
0
        /// <summary>
        /// Purges the items in a node
        /// </summary>
        /// <param name="strNode"></param>
        /// <returns></returns>
        public static bool UnsubscribeNode(XMPPClient connection, string strNode, string strJID, string strSID, bool bWaitForResponse)
        {
            IQ pubsub = new IQ();

            pubsub.Type = IQType.set.ToString();
            pubsub.From = connection.JID;
            pubsub.To   = new JID(string.Format("pubsub.{0}", connection.Domain));

            pubsub.InnerXML = UnsubscribeNodeXML.Replace("#NODE#", strNode).Replace("#JID#", strJID).Replace("#SID#", strSID);

            if (bWaitForResponse == false)
            {
                connection.SendXMPP(pubsub);
                return(true);
            }

            IQ IQResponse = connection.SendRecieveIQ(pubsub, 10000);

            if (IQResponse.Type == IQType.error.ToString())
            {
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
        public static string[] GetNodeItems(XMPPClient connection, string strNode, out string strNodeJID)
        {
            strNodeJID = "";
            List <string> returnnodes = new List <string>();
            IQ            IQRequest   = new IQ();

            IQRequest.Type     = IQType.get.ToString();
            IQRequest.From     = connection.JID;
            IQRequest.To       = string.Format("pubsub.{0}", connection.Domain);
            IQRequest.InnerXML = GetNodeItemsXML.Replace("#NODE#", strNode);;

            IQ IQResponse = connection.SendRecieveIQ(IQRequest, 30000);

            if (IQResponse.Type == IQType.error.ToString())
            {
                return(returnnodes.ToArray());
            }

            var nodes = IQResponse.InitalXMLElement.Descendants("{http://jabber.org/protocol/pubsub}items");

            foreach (XElement elem in nodes)
            {
                strNodeJID = elem.Attribute("node").Value;
            }

            nodes = IQResponse.InitalXMLElement.Descendants("{http://jabber.org/protocol/pubsub}item");
            foreach (XElement elem in nodes)
            {
                returnnodes.Add(elem.Value);
            }
            return(returnnodes.ToArray());
        }
Esempio n. 6
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)
            {
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Deny the remote user the ability to see our presence
 /// </summary>
 /// <param name="pres"></param>
 public void DeclineUserPresence(PresenceMessage pres)
 {
     pres.PresenceStatus.PresenceType = PresenceType.unsubscribed;
     pres.Type = "unsubscribed";
     pres.To   = pres.From.BareJID;
     pres.From = null;
     XMPPClient.SendObject(pres);
 }
Esempio n. 8
0
 public RosterLogic(XMPPClient client)
     : base(client)
 {
     RosterIQ      = new RosterIQ();
     RosterIQ.Type = IQType.get.ToString();
     RosterIQ.To   = null;
     RosterIQ.From = null;
 }
Esempio n. 9
0
 public GenericIQLogic(XMPPClient client)
     : base(client)
 {
     BindIQ      = new IQ();
     BindIQ.Type = IQType.set.ToString();
     BindIQ.To   = null;
     BindIQ.From = null;
 }
Esempio n. 10
0
        public OpenStreamStanza(XMPPClient client) : base(client)
        {
            m_strXML =
                @"<?xml version=""1.0""?>
<stream:stream xmlns:stream=""http://etherx.jabber.org/streams"" version=""1.0"" xmlns=""jabber:client"" to=""##TO##"" xml:lang=""en"" xmlns:xml=""http://www.w3.org/XML/1998/namespace"" >";
//            m_strXML = m_strXML.Replace("##FROM##", client.JID.BareJID);
            m_strXML = m_strXML.Replace("##TO##", client.Domain);
        }
Esempio n. 11
0
 void JingleSessionManager_OnSessionTerminated(string strSession, System.Net.XMPP.XMPPClient client)
 {
     if ((MediaSession != null) && (MediaSession.Session == strSession))
     {
         MediaSession.StopMedia(null);
         StopCall();
     }
 }
Esempio n. 12
0
 public GenericIQLogic(XMPPClient client)
     : base(client)
 {
     BindIQ = new IQ();
     BindIQ.Type = IQType.set.ToString();
     BindIQ.To = null;
     BindIQ.From = null;
 }
Esempio n. 13
0
 public void QueryServiceItems()
 {
     IQItemRequest = new ServiceDiscoveryIQ();
     IQItemRequest.ServiceDiscoveryItemQuery = new ServiceDiscoveryItemQuery();
     IQItemRequest.From = XMPPClient.JID;
     IQItemRequest.To   = XMPPClient.Domain;
     IQItemRequest.Type = IQType.get.ToString();
     XMPPClient.SendObject(IQItemRequest);
 }
Esempio n. 14
0
 public OpenStreamStanza(XMPPClient client)
     : base(client)
 {
     m_strXML =
     @"<?xml version=""1.0""?>
     <stream:stream xmlns:stream=""http://etherx.jabber.org/streams"" version=""1.0"" xmlns=""jabber:client"" to=""##TO##"" xml:lang=""en"" xmlns:xml=""http://www.w3.org/XML/1998/namespace"" >";
     //            m_strXML = m_strXML.Replace("##FROM##", client.JID.BareJID);
     m_strXML = m_strXML.Replace("##TO##", client.Domain);
 }
Esempio n. 15
0
        /// <summary>
        ///  Allow the remote user to see our presence, we should add them to our roster as well at this poitn?
        /// </summary>
        /// <param name="pres"></param>
        public void AcceptUserPresence(PresenceMessage pres, string strNickName, string strGroup)
        {
            pres.PresenceStatus.PresenceType = PresenceType.subscribed;
            pres.Type = "subscribed";
            pres.To   = pres.From.BareJID;
            pres.From = null;

            XMPPClient.SendObject(pres);
        }
Esempio n. 16
0
        /// <summary>
        /// Constructor provides an anonymous login using our own XMPP server
        /// </summary>
        /// <param name="mainPage">The MainPage-Control. I think you can give me 'this'</param>
        public XMPPManager(MainPage mainPage)
        {
            this.client = new XMPPClient();
            this.client.JID = new JID("*****@*****.**");
            this.client.Password = String.Empty; // To be filled in!
            this.client.Resource = String.Empty;
            this.mainPage = mainPage;

            InitializeClient();
        }
Esempio n. 17
0
        public void RequestOurVCARD()
        {
            iqGetOurVCARD          = new IQ();
            iqGetOurVCARD.From     = null;
            iqGetOurVCARD.To       = XMPPClient.JID.BareJID;
            iqGetOurVCARD.Type     = IQType.get.ToString();
            iqGetOurVCARD.InnerXML = "<vCard xmlns='vcard-temp' />";

            XMPPClient.SendXMPP(iqGetOurVCARD);
        }
Esempio n. 18
0
        /// <summary>
        /// Constructor with login credentials
        /// </summary>
        /// <param name="jabberID">The JID-Object of the JabberID</param>
        /// <param name="password">The password to login to this account</param>
        /// <param name="mainPage">The MainPage-Control. I think you can give me 'this'</param>
        public XMPPManager(JID jabberID, String password, MainPage mainPage)
        {
            this.client = new XMPPClient();
            this.client.JID = jabberID;
            this.client.Password = password;
            this.client.Resource = "battleshipme";
            this.mainPage = mainPage;

            InitializeClient();
        }
Esempio n. 19
0
        public void RequestVCARD(JID jidfor)
        {
            IQ iq = new IQ();

            iq.From     = XMPPClient.JID;
            iq.To       = jidfor.BareJID;
            iq.Type     = IQType.get.ToString();
            iq.InnerXML = "<vCard xmlns='vcard-temp' />";

            XMPPClient.SendXMPP(iq);
        }
Esempio n. 20
0
        public void UdpateVCARD(vcard vcard)
        {
            IQ iq = new IQ();

            iq.From     = XMPPClient.JID;
            iq.To       = null;
            iq.Type     = IQType.set.ToString();
            iq.InnerXML = Utility.GetXMLStringFromObject(vcard);

            XMPPClient.SendXMPP(iq);
        }
Esempio n. 21
0
        // Look for subscribe message to subscribe to presence
        public override bool NewIQ(IQ iq)
        {
            //// XEP-0030
            ///<iq type='get' from='[email protected]/orchard' to='plays.shakespeare.lit' id='info1'>
            ///   <query xmlns='http://jabber.org/protocol/disco#info'/>
            ///</iq>

            if ((iq is ServiceDiscoveryIQ) && (iq.Type == IQType.get.ToString()))
            {
                ServiceDiscoveryIQ response = new ServiceDiscoveryIQ();
                response.To   = iq.From;
                response.From = XMPPClient.JID;
                response.ID   = iq.ID;
                response.Type = IQType.result.ToString();
                response.ServiceDiscoveryInfoQuery          = new ServiceDiscoveryInfoQuery();
                response.ServiceDiscoveryInfoQuery.Features = XMPPClient.OurServiceDiscoveryFeatureList.ToArray();

                XMPPClient.SendObject(response);
                return(true);
            }
            else if ((IQInfoRequest != null) && (IQInfoRequest.ID == iq.ID))
            {
                if (iq is ServiceDiscoveryIQ)
                {
                    ServiceDiscoveryIQ response = iq as ServiceDiscoveryIQ;

                    if ((response.ServiceDiscoveryInfoQuery != null) && (response.ServiceDiscoveryInfoQuery.Features != null) && (response.ServiceDiscoveryInfoQuery.Features.Length > 0))
                    {
                        XMPPClient.ServerServiceDiscoveryFeatureList.Features.Clear();
                        XMPPClient.ServerServiceDiscoveryFeatureList.Features.AddRange(response.ServiceDiscoveryInfoQuery.Features);
                    }
                    if ((response.ServiceDiscoveryInfoQuery != null) && (response.ServiceDiscoveryInfoQuery.Identities != null) && (response.ServiceDiscoveryInfoQuery.Identities.Length > 0))
                    {
                    }
                }
                return(true);
            }
            else if ((IQItemRequest != null) && (IQItemRequest.ID == iq.ID))
            {
                if (iq is ServiceDiscoveryIQ)
                {
                    ServiceDiscoveryIQ response = iq as ServiceDiscoveryIQ;

                    if ((response.ServiceDiscoveryItemQuery != null) && (response.ServiceDiscoveryItemQuery.Items != null) && (response.ServiceDiscoveryItemQuery.Items.Length > 0))
                    {
                        XMPPClient.ServerServiceDiscoveryFeatureList.Items.AddRange(response.ServiceDiscoveryItemQuery.Items);
                        System.Threading.ThreadPool.QueueUserWorkItem(QueryItemsForProxy);
                    }
                }
                return(true);
            }

            return(base.NewIQ(iq));
        }
Esempio n. 22
0
        public void UnsubscribeToPresence(JID jidto)
        {
            PresenceMessage pres = new PresenceMessage(null);

            pres.To     = jidto;
            pres.From   = null;
            pres.Type   = "unsubscribe";
            pres.Show   = null;
            pres.Status = null;
            pres.PresenceStatus.PresenceType = PresenceType.unsubscribe;
            XMPPClient.SendObject(pres);
        }
Esempio n. 23
0
        public void DownloadAvatarJabberIQMethod(JID jidfor)
        {
            IQ iq = new IQ();

            iq.From     = XMPPClient.JID;
            iq.To       = jidfor;
            iq.Type     = IQType.get.ToString();
            iq.InnerXML = "<query xmlns='jabber:iq:avatar' />";
            //iq.InnerXML = "<query xmlns='storage:client:avatar' />";

            XMPPClient.SendXMPP(iq);
        }
Esempio n. 24
0
        public bool PublishAvatarData(byte [] bImageData, int nWidth, int nHeight)
        {
            // publish avatar data node
            avatardata data = new avatardata();

            data.ImageData = bImageData;
            //string strAvatarInfo = Utility.GetXMLStringFromObject(data);

            string strHash = XMPPClient.AvatarStorage.WriteAvatar(bImageData);

            PubSubIQ iq = new PubSubIQ();

            iq.Type           = IQType.set.ToString();
            iq.To             = null; /// null for personal eventing pub sub
            iq.From           = XMPPClient.JID;
            iq.PubSub.Publish = new Publish()
            {
                Node = "urn:xmpp:avatar:data", Item = new PubSubItem()
            };
            iq.PubSub.Publish.Item.SetNodeFromObject(data);

            ListSentIQs.Add(iq.ID);
            XMPPClient.SendObject(iq);


            // publish avatar meta data node
            avatarmetadata metadata = new avatarmetadata();

            metadata.ImageInfo.ByteLength = bImageData.Length;
            metadata.ImageInfo.Width      = nWidth;
            metadata.ImageInfo.Height     = nHeight;
            //string strAvatarMetaData = Utility.GetXMLStringFromObject(metadata);

            PubSubIQ iqmeta = new PubSubIQ();

            iqmeta.Type           = IQType.set.ToString();
            iqmeta.To             = null; /// null for personal eventing pub sub
            iqmeta.From           = XMPPClient.JID;
            iqmeta.PubSub.Publish = new Publish()
            {
                Node = "urn:xmpp:avatar:metadata", Item = new PubSubItem()
                {
                    Id = strHash
                }
            };
            iqmeta.PubSub.Publish.Item.SetNodeFromObject(metadata);

            ListSentIQs.Add(iqmeta.ID);
            XMPPClient.SendObject(iqmeta);

            return(true);
        }
Esempio n. 25
0
        public void GetAllItems(string strSubId)
        {
            IQGetAll              = new PubSubIQ();
            IQGetAll.Type         = IQType.set.ToString();
            IQGetAll.To           = new JID(string.Format("pubsub.{0}", XMPPClient.Domain));
            IQGetAll.From         = XMPPClient.JID;
            IQGetAll.PubSub.Items = new PubSubItems()
            {
                Node = Node, subid = strSubId
            };


            XMPPClient.SendObject(IQGetAll);
        }
Esempio n. 26
0
        public bool SendReceive(int nTimeoutMs)
        {
            TimeoutMs = nTimeoutMs;
            if (SerializationMethod == XMPP.SerializationMethod.MessageXMLProperty)
            {
                XMPPClient.SendXMPP(SendIQ);
            }
            else
            {
                XMPPClient.SendObject(SendIQ);
            }

            Success = GotIQEvent.WaitOne(TimeoutMs);
            return(Success);
        }
Esempio n. 27
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)
            {
            }
        }
Esempio n. 28
0
        public void SetPresence(PresenceStatus status, Capabilities caps, string strImageHash)
        {
            PresenceMessage pres = new PresenceMessage(null);

            pres.From           = XMPPClient.JID;
            pres.To             = null;
            pres.PresenceStatus = status;
            pres.Capabilities   = caps;

            if ((strImageHash != null) && (strImageHash.Length > 0))
            {
                pres.VCardUpdate           = new VCardUpdate();
                pres.VCardUpdate.PhotoHash = strImageHash;
            }

            XMPPClient.SendObject(pres);
        }
Esempio n. 29
0
        void QueryItemType(item item)
        {
            if (item.ItemType == ItemType.NotQueried)
            {
                ServiceDiscoveryIQ iqqueryproxy = new ServiceDiscoveryIQ();
                iqqueryproxy.From = XMPPClient.JID;
                iqqueryproxy.To   = item.JID;
                iqqueryproxy.ServiceDiscoveryInfoQuery = new ServiceDiscoveryInfoQuery();
                iqqueryproxy.Type = IQType.get.ToString();


                IQ iqret = XMPPClient.SendRecieveIQ(iqqueryproxy, 15000, SerializationMethod.XMLSerializeObject);
                if ((iqret != null) && (iqret is ServiceDiscoveryIQ))
                {
                    ServiceDiscoveryIQ response = iqret as ServiceDiscoveryIQ;
                    if ((response.ServiceDiscoveryInfoQuery != null) && (response.ServiceDiscoveryInfoQuery.Identities != null) && (response.ServiceDiscoveryInfoQuery.Identities.Length > 0))
                    {
                        if ((response.ServiceDiscoveryInfoQuery.Identities[0].Category == "proxy") &&
                            (response.ServiceDiscoveryInfoQuery.Identities[0].Type == "bytestreams"))
                        {
                            item.ItemType = ItemType.SOCKS5ByteStream;
                            return;
                        }
                        if (response.ServiceDiscoveryInfoQuery.Identities[0].Category == "pubsub")
                        {
                            item.ItemType = ItemType.PubSub;
                            return;
                        }
                        if (response.ServiceDiscoveryInfoQuery.Identities[0].Category == "directory")
                        {
                            item.ItemType = ItemType.Directory;
                            return;
                        }
                        if (response.ServiceDiscoveryInfoQuery.Identities[0].Category == "conference")
                        {
                            item.ItemType = ItemType.Conference;
                            return;
                        }
                    }
                }


                item.ItemType = ItemType.Unknown;
            }
        }
Esempio n. 30
0
        public void DownloadDataNode(JID jidto, string strNodeName, string strItem)
        {
            PubSubIQ iq = new PubSubIQ();

            iq.Type           = IQType.set.ToString();
            iq.To             = null; /// null for personal eventing pub sub
            iq.From           = XMPPClient.JID;
            iq.PubSub.Publish = new Publish()
            {
                Node = strNodeName, Item = new PubSubItem()
                {
                    Id = strNodeName
                }
            };

            ListSentIQs.Add(iq.ID);
            XMPPClient.SendObject(iq);
        }
Esempio n. 31
0
        public void DeleteItem(string strItemId, T item)
        {
            PubSubIQ iq = new PubSubIQ();

            iq.Type                 = IQType.set.ToString();
            iq.To                   = new JID(string.Format("pubsub.{0}", XMPPClient.Domain));
            iq.From                 = XMPPClient.JID;
            iq.PubSub.Retract       = new Retract();
            iq.PubSub.Retract.Node  = Node;
            iq.PubSub.Retract.Items = new PubSubItem[] { new PubSubItem()
                                                         {
                                                             Id = strItemId
                                                         } };

            ListSentIQs.Add(iq);

            XMPPClient.SendObject(iq);
        }
Esempio n. 32
0
        public static bool DeleteNode(XMPPClient connection, string strNode)
        {
            string strXML    = DeleteNodeXML.Replace("#NODE#", strNode);
            IQ     IQRequest = new IQ();

            IQRequest.Type     = IQType.set.ToString();
            IQRequest.From     = connection.JID;
            IQRequest.To       = string.Format("pubsub.{0}", connection.Domain);
            IQRequest.InnerXML = strXML;

            IQ IQResponse = connection.SendRecieveIQ(IQRequest, 10000);

            if (IQResponse.Type == IQType.error.ToString())
            {
                return(false);
            }

            return(true);
        }
Esempio n. 33
0
        public void UpdateItem(string strItemId, T item)
        {
            PubSubIQ iq = new PubSubIQ();

            iq.Type                = IQType.set.ToString();
            iq.To                  = new JID(string.Format("pubsub.{0}", XMPPClient.Domain));
            iq.From                = XMPPClient.JID;
            iq.PubSub.Publish      = new Publish();
            iq.PubSub.Publish.Node = Node;
            iq.PubSub.Publish.Item = new PubSubItem()
            {
                Id = strItemId
            };
            iq.PubSub.Publish.Item.SetNodeFromObject(item);

            ListSentIQs.Add(iq);

            XMPPClient.SendObject(iq);
        }
Esempio n. 34
0
        public override bool NewIQ(IQ iq)
        {
            try
            {
                if (iq.ID == BindIQ.ID)
                {
                    /// Extract our jid incase it changed
                    /// <iq type="result" id="bind_1" to="ninethumbs.com/7b5005e1"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>[email protected]/hypnotoad</jid></bind></iq>
                    ///
                    if (iq.Type == IQType.result.ToString())
                    {
                        /// bound, now do toher things
                        ///
                        XElement elembind = XElement.Parse(iq.InnerXML);
                        XElement nodejid  = elembind.FirstNode as XElement;
                        if ((nodejid != null) && (nodejid.Name == "{urn:ietf:params:xml:ns:xmpp-bind}jid"))
                        {
                            XMPPClient.JID = nodejid.Value;
                        }
                        XMPPClient.XMPPState = XMPPState.Bound;
                    }
                    return(true);
                }

                if ((iq.InnerXML != null) && (iq.InnerXML.Length > 0))
                {
                    XElement elem = XElement.Parse(iq.InnerXML);
                    if (elem.Name == "{urn:xmpp:ping}ping")
                    {
                        iq.Type     = IQType.result.ToString();
                        iq.To       = iq.From;
                        iq.From     = XMPPClient.JID.BareJID;
                        iq.InnerXML = "";
                        XMPPClient.SendXMPP(iq);
                    }
                }
            }
            catch (Exception)
            {
            }
            return(false);
        }
Esempio n. 35
0
        public static void CreateNode(XMPPClient connection, string strNode, string strParentNode, PubSubConfigForm nodeform)
        {
            IQ pubsub = new IQ();
            pubsub.Type = IQType.set.ToString();
            pubsub.From = connection.JID;
            pubsub.To = new JID(string.Format("pubsub.{0}", connection.Domain));

            string strXML = CreateNodeXML.Replace("#NODE#", strNode);

            /// Get inner xml
            ///
            string strForm = nodeform.BuildAskingForm(nodeform);

            strXML = strXML.Replace("#x#", strForm);
            pubsub.InnerXML = strXML;

            IQ IQResponse = connection.SendRecieveIQ(pubsub, 10000);
            if (IQResponse == null)
                return;
            if (IQResponse.Type == IQType.error.ToString())
            {
                return;
            }
        }
Esempio n. 36
0
        public static item[] GetSubNodeItems(XMPPClient connection, string strNode)
        {
            List<item> SubNodeList = new List<item>();
            ServiceDiscoveryIQ IQRequest = new ServiceDiscoveryIQ();
            IQRequest.ServiceDiscoveryItemQuery = new ServiceDiscoveryItemQuery();
            IQRequest.From = connection.JID;
            IQRequest.To = string.Format("pubsub.{0}", connection.Domain);
            IQRequest.Type = IQType.get.ToString();
            IQRequest.ServiceDiscoveryItemQuery.Node = strNode;

            IQ IQResponse = connection.SendRecieveIQ(IQRequest, 10000, SerializationMethod.XMLSerializeObject);

            if (IQResponse == null)
                return null;

            if (IQResponse.Type == IQType.error.ToString())
            {
                return SubNodeList.ToArray();
            }

            if (IQResponse is ServiceDiscoveryIQ)
            {
                ServiceDiscoveryIQ sdiq = IQResponse as ServiceDiscoveryIQ;
                if ((sdiq.ServiceDiscoveryItemQuery != null) && (sdiq.ServiceDiscoveryItemQuery.Items != null))
                {
                    foreach (item it in sdiq.ServiceDiscoveryItemQuery.Items)
                    {
                        SubNodeList.Add(it);
                    }
                }
            }

            return SubNodeList.ToArray();
        }
Esempio n. 37
0
        public static string[] GetSubNodes(XMPPClient connection, string strNode)
        {
            List<string> SubNodeList = new List<string>();
            string strXML = FetchChildNodes.Replace("#NODE#", strNode);

            ServiceDiscoveryIQ IQRequest = new ServiceDiscoveryIQ();
            IQRequest.ServiceDiscoveryItemQuery = new ServiceDiscoveryItemQuery();
            IQRequest.From = connection.JID;
            IQRequest.To = string.Format("pubsub.{0}", connection.Domain);
            IQRequest.Type = IQType.get.ToString();
            IQRequest.ServiceDiscoveryItemQuery.Node = strNode;

            IQ IQResponse = connection.SendRecieveIQ(IQRequest, 10000, SerializationMethod.XMLSerializeObject);

            if (IQResponse == null)
                return null;

            if (IQResponse.Type == IQType.error.ToString())
            {
                return SubNodeList.ToArray();
            }

            if (IQResponse is ServiceDiscoveryIQ)
            {
                ServiceDiscoveryIQ sdiq = IQResponse as ServiceDiscoveryIQ;
                if ((sdiq.ServiceDiscoveryItemQuery != null) && (sdiq.ServiceDiscoveryItemQuery.Items != null) )
                {
                    foreach (item it in sdiq.ServiceDiscoveryItemQuery.Items)
                    {
                        SubNodeList.Add(it.Node);
                    }
                }
            }

            //var nodes = IQResponse.InitalXMLElement.Descendants("{http://jabber.org/protocol/disco#items}item");
            //foreach (XElement elem in nodes)
            //{
            //    XAttribute attrnode = elem.Attribute("node");
            //    if (attrnode != null)
            //       SubNodeList.Add(attrnode.Value);
            //}

            return SubNodeList.ToArray();
        }
Esempio n. 38
0
        /// <summary>
        /// Checks to see if a given node exists
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="strNode"></param>
        /// <returns></returns>
        public static bool NodeExists(XMPPClient connection, string strNode)
        {
            string strXML = QueryNodeXML.Replace("#NODE#", strNode);
            IQ IQRequest = new IQ();
            IQRequest.From = connection.JID;
            IQRequest.To = string.Format("pubsub.{0}", connection.Domain);
            IQRequest.InnerXML = strXML;
            IQ IQResponse = connection.SendRecieveIQ(IQRequest, 10000);

            if (IQResponse == null)
                return false;
            if (IQResponse.Type == IQType.error.ToString()) // && (IQResponse.Error.Code >= 0))
            {
                return false;
            }

            return true;
        }
Esempio n. 39
0
        public static IQ RequestItem(XMPPClient connection, string strNode, string strItemName)
        {
            IQ pubsub = new IQ();
            pubsub.Type = IQType.get.ToString();
            pubsub.From = connection.JID;
            pubsub.To = new JID(string.Format("pubsub.{0}", connection.Domain));

            string strXML = RequestItemXML.Replace("#NODE#", strNode);
            strXML = strXML.Replace("#ITEM#", strItemName);
            pubsub.InnerXML = strXML;

            IQ IQResponse = connection.SendRecieveIQ(pubsub, 15000);

            if (IQResponse.Type == IQType.error.ToString())
            {
                return null;
            }
            return IQResponse;
        }
 public SOCKS5ByteStreamLogic(XMPPClient client, FileTransfer trans)
     : base(client, trans)
 {
 }
Esempio n. 41
0
        public static bool DeleteNode(XMPPClient connection, string strNode)
        {
            string strXML = DeleteNodeXML.Replace("#NODE#", strNode);
            IQ IQRequest = new IQ();
            IQRequest.Type = IQType.set.ToString();
            IQRequest.From = connection.JID;
            IQRequest.To = string.Format("pubsub.{0}", connection.Domain);
            IQRequest.InnerXML = strXML;

            IQ IQResponse = connection.SendRecieveIQ(IQRequest, 10000);

            if (IQResponse.Type == IQType.error.ToString())
            {
                return false;
            }

            return true;
        }
 public ByteStreamStreamLogic(XMPPClient client, FileTransfer trans)
     : base(client)
 {
     FileTransfer = trans;
 }
Esempio n. 43
0
 public StreamNegotiationLogic(XMPPClient client)
     : base(client)
 {
 }
Esempio n. 44
0
 public SendRecvIQLogic(XMPPClient client, IQ iq)
     : base(client)
 {
     SendIQ = iq;
 }
Esempio n. 45
0
 public XMPPConnection(XMPPClient client, SocketServer.ILogInterface loginterface)
     : base(loginterface, "")
 {
     XMPPClient = client;
 }
Esempio n. 46
0
 void XmppClient_OnXMLSent(XMPPClient client, string strXML)
 {
 }
Esempio n. 47
0
        /// <summary>
        /// Purges the items in a node
        /// </summary>
        /// <param name="strNode"></param>
        /// <returns></returns>
        public static string SubscribeNode(XMPPClient connection, string strNode, string strJID, bool bWaitForResponse)
        {
            IQ pubsub = new IQ();
            pubsub.Type = IQType.set.ToString();
            pubsub.From = connection.JID;
            pubsub.To = new JID(string.Format("pubsub.{0}", connection.Domain));

            pubsub.InnerXML = SubscribeNodeXML.Replace("#NODE#", strNode).Replace("#JID#", strJID);

            if (bWaitForResponse == false)
            {
                connection.SendXMPP(pubsub);
                return null;
            }

            IQ IQResponse = connection.SendRecieveIQ(pubsub, 10000);

            if ( (IQResponse == null) || (IQResponse.Type == IQType.error.ToString()) )
            {
                return null;
            }

            ///<iq type="result" id="9933bb36-7685-460f-8d7f-e9e5ad80f780" from="pubsub.ninethumbs.com" to="[email protected]/9047e898-aed2-4f58-b3e2-a5f671758544">
            ///     <pubsub xmlns="http://jabber.org/protocol/pubsub">
            ///         <subscription node="GroceryList" jid="[email protected]/9047e898-aed2-4f58-b3e2-a5f671758544" subid="tU98QlKDYuEhTiKO443Vs2AWi2Y07i4Pf2l1wc8W" subscription="subscribed">
            ///         <subscribe-options/></subscription>
            ///     </pubsub>
            /// </iq>
            ///

            if (IQResponse is PubSubIQ)
            {
                PubSubIQ psiq = IQResponse as PubSubIQ;
                if ( (psiq.PubSub != null) && (psiq.PubSub.Subscription != null) )
                    return psiq.PubSub.Subscription.subid;
            }

            return null;
        }
Esempio n. 48
0
        /// <summary>
        /// Purges the items in a node
        /// </summary>
        /// <param name="strNode"></param>
        /// <returns></returns>
        public static bool UnsubscribeNode(XMPPClient connection, string strNode, string strJID, string strSID, bool bWaitForResponse)
        {
            IQ pubsub = new IQ();
            pubsub.Type = IQType.set.ToString();
            pubsub.From = connection.JID;
            pubsub.To = new JID(string.Format("pubsub.{0}", connection.Domain));

            pubsub.InnerXML = UnsubscribeNodeXML.Replace("#NODE#", strNode).Replace("#JID#", strJID).Replace("#SID#", strSID);

            if (bWaitForResponse == false)
            {
                connection.SendXMPP(pubsub);
                return true;
            }

            IQ IQResponse = connection.SendRecieveIQ(pubsub, 10000);

            if (IQResponse.Type == IQType.error.ToString())
            {
                return false;
            }

            return true;
        }
 public InbandByteStreamLogic(XMPPClient client, FileTransfer trans)
     : base(client, trans)
 {
 }
Esempio n. 50
0
 public Logic(XMPPClient client)
 {
     XMPPClient = client;
 }
Esempio n. 51
0
        void XmppClient_OnXMLReceived(XMPPClient client, string strXML)
        {
            BattleshipMessage bMessage = XMLManager.GetBattleshipMessage(strXML);
            if (bMessage != null)
            {
                if (bMessage is QueuingMessage)
                {
                    Match m = null;
                    System.Windows.Media.SolidColorBrush brush = null;
                    QueuingMessage qMessage = (QueuingMessage)bMessage;
                    String s = "";
                    if (qMessage.Action== Enum.QueueingAction.success)
                    {

                        s = "Searching partner. Please wait...";
                        this.queueID = qMessage.ID;
                        brush = AppCache.cYellow;

                    }
                    else if (qMessage.Action == Enum.QueueingAction.ping)
                    {
                        OnIncomingQueuingPing(new MessageEventArgs(qMessage));
                    }
                    else if (qMessage.Action == Enum.QueueingAction.assign)
                    {
                        if (QueuingProcess) {
                            QueuingProcess = false;
                            Matchmaker.Assigned(this, qMessage.JID, qMessage.MatchID);
                            m = new Match(qMessage.MatchID, this.OwnID, qMessage.JID);
                        }
                        s = "Assigned with partner!";
                        brush = AppCache.cGreen;

                    }
                        mainPage.Dispatcher.BeginInvoke(delegate
                    {
                        if (!String.IsNullOrEmpty(s))
                        {
                            mainPage.lblSearchState.Text = s;
                        }
                        if (m != null)
                            mainPage.StartGame(m);

                        if (brush != null)
                            mainPage.ledWaitingState.Fill = brush;
                    });
                }
                else if (bMessage is MatchMessage)
                {
                    MatchMessage mMessage = (MatchMessage)bMessage;
                    switch (mMessage.Action)
                    {
                        case Enum.MatchAction.Diceroll:
                            if (AppCache.CurrentMatch != null)
                            {
                                this.OnIncomingDiceroll(new RollingDiceEventArgs(mMessage.Dice));
                            }
                            break;
                        case Enum.MatchAction.Shot:
                            if (AppCache.CurrentMatch != null)
                            {
                                this.OnIncomingShot(new ShootEventArgs(mMessage.X, mMessage.Y));
                            }
                            break;
                        case Enum.MatchAction.Shotresult:
                            if (AppCache.CurrentMatch != null)
                            {
                                if (mMessage.ShipInfo != null)
                                {
                                    this.OnIncomingShotResult(new ShootEventArgs(mMessage.X, mMessage.Y, mMessage.Result, mMessage.ShipInfo));
                                }
                                else
                                {
                                    this.OnIncomingShotResult(new ShootEventArgs(mMessage.X, mMessage.Y, mMessage.Result));
                                }
                            }
                            break;
                        case Enum.MatchAction.Ping:
                            if (AppCache.CurrentMatch != null)
                            {
                                this.OnIncomingMatchPing(new MessageEventArgs(mMessage));
                            }
                            break;
                        case Enum.MatchAction.Gamestate:
                            if (AppCache.CurrentMatch != null)
                            {
                                this.OnIncomingGamestate(new MessageEventArgs(mMessage));
                            }
                            break;
                    }
                }
            }
        }
Esempio n. 52
0
 public WaitableLogic(XMPPClient client)
     : base(client)
 {
 }
        public static StreamInitIQ BuildDefaultStreamInitOffer(XMPPClient client, FileTransfer trans)
        {
            StreamInitIQ q = new StreamInitIQ(StreamInitIQType.Offer);
            q.mimetype = trans.MimeType;
            q.filename = trans.FileName;
            q.sid = trans.sid;
            q.filesize = trans.BytesTotal;
            q.FileTransferObject = trans;

            q.StreamOptions = XMPP.StreamOptions.ibb;

            /// Don't offer byte streams if the server doesn't support a SOCKS 5 proxy, since windows phone can't listen for connections
            item filetransfer = client.ServerServiceDiscoveryFeatureList.GetItemByType(ItemType.SOCKS5ByteStream);

            if ((FileTransferManager.SOCKS5Proxy != null) && (FileTransferManager.SOCKS5Proxy.Length > 0))
                filetransfer = new item(); /// User has supplied a socks5 proxy, so we don't need our xmpp server to supply one to use bytestreams

            if ((filetransfer != null) && (FileTransferManager.UseIBBOnly == false))
            {
                q.StreamOptions |= StreamOptions.bytestreams;
            }

            return q;
        }
Esempio n. 54
0
 public XMPPStanza(XMPPClient client)
 {
 }
Esempio n. 55
0
 public XMPPConnection(XMPPClient client)
     : base()
 {
     XMPPClient = client;
 }
Esempio n. 56
0
        /// <summary>
        /// Retracts an item on the pubsub node.  This client must be the owner
        /// </summary>
        /// <param name="strNode"></param>
        /// <param name="strItem"></param>
        /// <param name="nTimeoutMs"></param>
        /// <returns></returns>
        public static bool RetractItem(XMPPClient connection, string strNode, string strItem)
        {
            IQ pubsub = new IQ();
            pubsub.Type = IQType.set.ToString();
            pubsub.From = connection.JID;
            pubsub.To = new JID(string.Format("pubsub.{0}", connection.Domain));

            string strXML = RetractNodeXML.Replace("#NODE#", strNode);
            strXML = strXML.Replace("#ITEM#", strItem);
            pubsub.InnerXML = strXML;

            IQ IQResponse = connection.SendRecieveIQ(pubsub, 10000);

            if (IQResponse.Type == IQType.error.ToString())
            {
                return false;
            }

            return true;
        }
Esempio n. 57
0
 public PresenceLogic(XMPPClient client)
     : base(client)
 {
 }
Esempio n. 58
0
 public FeatureLogic(XMPPClient client)
     : base(client)
 {
 }
 public StreamInitiationAndTransferLogic(XMPPClient client)
     : base(client)
 {
 }
Esempio n. 60
0
 public RosterLogic(XMPPClient client)
     : base(client)
 {
     RosterIQ = new RosterIQ();
     RosterIQ.Type = IQType.get.ToString();
     RosterIQ.To = null;
     RosterIQ.From = null;
 }