public bool PublishGeoInfo(geoloc item)
        {
            string strGeoInfo = Utility.GetXMLStringFromObject(item);

            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 = "http://jabber.org/protocol/geoloc", Item = new PubSubItem()
            };
            iq.PubSub.Publish.Item.SetNodeFromObject(item);
            iq.PubSub.Publish.Item.Id = "lastlocation";

            ListSentIQs.Add(iq.ID);
            try
            {
                XMPPClient.SendObject(iq);
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
        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);
        }
Exemple #3
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);
        }
        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);
        }
Exemple #5
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);
        }
Exemple #6
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);
        }
Exemple #7
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);
        }
        public bool PublishTuneInfo(TuneItem item)
        {
            //string strTuneXML = Utility.GetXMLStringFromObject(item);


            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 = "http://jabber.org/protocol/tune", Item = new PubSubItem()
            };
            iq.PubSub.Publish.Item.SetNodeFromObject(item);

            ListSentIQs.Add(iq.ID);

            XMPPClient.SendObject(iq);
            return(true);
        }
Exemple #9
0
        public IQ BuildIQ(XElement elem, string strXML)
        {
            /// Check out our first node
            ///

            string strType = "";

            if (elem.Attribute("type") != null)
            {
                strType = elem.Attribute("type").Value;
            }

            if ((elem.FirstNode != null) && (elem.FirstNode is XElement))
            {
                if (((XElement)elem.FirstNode).Name == "{http://jabber.org/protocol/disco#info}query")
                {
                    ServiceDiscoveryIQ query = Utility.ParseObjectFromXMLString(strXML, typeof(ServiceDiscoveryIQ)) as ServiceDiscoveryIQ;
                    return(query);
                }
                else if (((XElement)elem.FirstNode).Name == "{http://jabber.org/protocol/disco#items}query")
                {
                    ServiceDiscoveryIQ query = Utility.ParseObjectFromXMLString(strXML, typeof(ServiceDiscoveryIQ)) as ServiceDiscoveryIQ;
                    return(query);
                }
                else if (((XElement)elem.FirstNode).Name == "{jabber:iq:roster}query")
                {
                    return(new RosterIQ(strXML));
                }
                else if (((XElement)elem.FirstNode).Name == "{urn:xmpp:jingle:1}jingle")
                {
                    Jingle.JingleIQ query = Utility.ParseObjectFromXMLString(strXML, typeof(Jingle.JingleIQ)) as Jingle.JingleIQ;
                    return(query);
                }
                else if (((XElement)elem.FirstNode).Name == "{http://jabber.org/protocol/si}si")
                {
                    return(new StreamInitIQ(strXML));
                }
                else if (((XElement)elem.FirstNode).Name == "{http://jabber.org/protocol/pubsub}pubsub")
                {
                    PubSubIQ query = Utility.ParseObjectFromXMLString(strXML, typeof(PubSubIQ)) as PubSubIQ;
                    return(query);
                }
                else if (((XElement)elem.FirstNode).Name == "{http://jabber.org/protocol/bytestreams}query")
                {
                    ByteStreamQueryIQ query = Utility.ParseObjectFromXMLString(strXML, typeof(ByteStreamQueryIQ)) as ByteStreamQueryIQ;
                    return(query);
                }
            }

#if !WINDOWS_PHONE
            IQ iqret = Utility.ParseObjectFromXMLString(strXML, typeof(IQ)) as IQ;
            iqret.InitalXMLElement = elem;
            if (elem.FirstNode != null)
            {
                iqret.InnerXML = elem.FirstNode.ToString();
            }
            return(iqret);
#else
            return(new IQ(strXML));
#endif
        }
Exemple #10
0
        public override bool NewIQ(IQ iq)
        {
            PubSubIQ SendingIQ = FindSendingIQ(iq);

            if (SendingIQ != null)
            {
                //PubSub iqrequest = ListSentIQs[iq.ID];
                ListSentIQs.Remove(SendingIQ);

                /// See if this was a retract request.  If it was and is successful, remove the item
                if (SendingIQ.PubSub.Retract != null)
                {
                    if (iq.Type == IQType.result.ToString())
                    {
                        string strItemId = SendingIQ.PubSub.Retract.Items[0].Id;
                        if (ItemIdToObject.ContainsKey(strItemId) == true)
                        {
                            T obj = ItemIdToObject[strItemId];
                            Items.Remove(obj);
                            ItemIdToObject.Remove(strItemId);
                        }
                    }
                }
                //else if (SendingIQ.PubSub.Publish != null)
                //{
                //    if (iq.Type == IQType.result.ToString())
                //    {
                //        string strItemId = SendingIQ.PubSub.Retract.Item.Id;
                //        if (ItemIdToObject.ContainsKey(strItemId) == true)
                //        {
                //            T obj = ItemIdToObject[strItemId];
                //            Items.Remove(obj);
                //            ItemIdToObject.Remove(strItemId);
                //        }
                //    }
                //}


                return(true);
            }
            else if ((IQGetAll != null) && (IQGetAll.ID == iq.ID))
            {
                if (iq is PubSubIQ)
                {
                    PubSubIQ psem = iq as PubSubIQ;
                    if (psem != null)
                    {
                        if ((psem.PubSub.Items != null) && (psem.PubSub.Items.Items != null) && (psem.PubSub.Items.Items.Length > 0))
                        {
                            m_listItems.Clear();
                            ItemIdToObject.Clear();

                            if (psem.PubSub.Items.Node == Node)
                            {
                                foreach (PubSubItem psi in psem.PubSub.Items.Items)
                                {
                                    T item = psi.GetObjectFromXML <T>();
                                    if (item != null)
                                    {
                                        Items.Add(item);
                                        ItemIdToObject.Add(psi.Id, item);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(base.NewIQ(iq));
        }