Exemple #1
0
        void DoAskUserIfTheyWantToReceiveFile(object objAskInfo)
        {
            FileTransfer trans = objAskInfo as FileTransfer;

            try
            {
                RosterItem item = XMPPClient.FindRosterItem(trans.RemoteJID);

                OnNewIncomingFileTransferRequest(trans, item);
            }
            catch (Exception)
            { }
        }
Exemple #2
0
        public override bool NewMessage(Message iq)
        {
            /// See if this is a standard text message
            ///
            if (iq is ChatMessage)
            {
                ChatMessage chatmsg = iq as ChatMessage;
                RosterItem  item    = XMPPClient.FindRosterItem(chatmsg.From);
                if (item != null)
                {
                    if (chatmsg.Body != null)
                    {
                        TextMessage txtmsg = new TextMessage();
                        txtmsg.From     = chatmsg.From;
                        txtmsg.To       = chatmsg.To;
                        txtmsg.Received = DateTime.Now;
                        if (chatmsg.Delivered.HasValue == true)
                        {
                            txtmsg.Received = chatmsg.Delivered.Value; /// May have been a server stored message
                        }
                        txtmsg.Message = chatmsg.Body;
                        txtmsg.Sent    = false;
                        item.AddRecvTextMessage(txtmsg);
                        item.HasNewMessages = true;

                        // Notify XMPPClient that a new conversation item has been added
                        XMPPClient.FireNewConversationItem(item, true, txtmsg);
                    }
                    if (chatmsg.ConversationState != ConversationState.none)// A conversation message
                    {
                        item.Conversation.ConversationState = chatmsg.ConversationState;
                        XMPPClient.FireNewConversationState(item, item.Conversation.ConversationState);
                    }
                }
                return(true);
            }

            return(false);
        }
Exemple #3
0
        public void SendChatMessage(TextMessage txtmsg)
        {
            txtmsg.Sent = true;
            ChatMessage msg = new ChatMessage(null);

            msg.From = txtmsg.From;
            msg.To   = txtmsg.To;
            msg.Type = "chat";
            msg.Body = txtmsg.Message;
            //msg.InnerXML = string.Format(@"<body>{0}</body>", txtmsg.Message);

            /// Find the roster guy for this message and add it to their conversation
            ///
            RosterItem item = XMPPClient.FindRosterItem(txtmsg.To);

            if (item != null)
            {
                item.AddSendTextMessage(txtmsg);
                // Notify XMPPClient that a new conversation item has been added
                XMPPClient.FireNewConversationItem(item, false, txtmsg);
            }

            XMPPClient.SendXMPP(msg);
        }
        public override bool NewMessage(Message iq)
        {
            /// Look for pubsub events
            ///
            if (iq is PubSubEventMessage)
            {
                PubSubEventMessage psem = iq as PubSubEventMessage;
                if (psem.Event != null)
                {
                    if ((psem.Event.Items != null) && (psem.Event.Items.Items != null) && (psem.Event.Items.Items.Length > 0))
                    {
                        PubSubItem psitem = psem.Event.Items.Items[0];
                        XElement   elem   = psitem.InnerItemXML as XElement;

                        if (psem.Event.Items.Node == "http://jabber.org/protocol/tune")
                        {
                            TuneItem item = psitem.GetObjectFromXML <TuneItem>();
                            if (item != null)
                            {
                                /// find the roster item, set the tune item
                                RosterItem rosteritem = XMPPClient.FindRosterItem(iq.From);
                                if (rosteritem != null)
                                {
                                    rosteritem.Tune = item;
                                }
                            }
                        }
                        else if (psem.Event.Items.Node == "http://jabber.org/protocol/geoloc")
                        {
                            geoloc item = psitem.GetObjectFromXML <geoloc>();
                            if (item != null)
                            {
                                /// find the roster item, set the tune item
                                RosterItem rosteritem = XMPPClient.FindRosterItem(iq.From);
                                if (rosteritem != null)
                                {
                                    rosteritem.GeoLoc = item;
                                }
                            }
                        }
                        else if (psem.Event.Items.Node == "http://jabber.org/protocol/mood")
                        {
                        }
                        else if (psem.Event.Items.Node == "urn:xmpp:avatar:metadata") /// item avatar metadata
                        {
                            /// We have update avatar info for this chap, we should then proceed to get the avatar data
                            ///
                            foreach (PubSubItem objItem in psem.Event.Items.Items)
                            {
                                avatarmetadata meta = psitem.GetObjectFromXML <avatarmetadata>();
                                if (meta != null)
                                {
                                    /// Request this node ? maybe we get it automatically?
                                    ///
                                }
                                /// Not sure why they would have more than 1 avatar item, so we'll ignore fom now
                                ///
                                break;
                            }
                        }
                        else if (psem.Event.Items.Node == "urn:xmpp:avatar:data") /// item avatar
                        {
                            /// We have update avatar info for this chap, we should then proceed to get the avatar data
                            ///
                            /// Works, but let's comment out for now to focus on more supported avatar methods
                            //foreach (PubSubItem objItem in psem.Items)
                            //{
                            //    avatardata data = Utility.ParseObjectFromXMLString(objItem.InnerItemXML, typeof(avatardata)) as avatardata;
                            //    if (data != null)
                            //    {
                            //        string strHash = XMPPClient.AvatarStorage.WriteAvatar(data.ImageData);
                            //        RosterItem item = XMPPClient.FindRosterItem(psem.From);
                            //        if (item != null)
                            //        {
                            //            item.AvatarImagePath = strHash;
                            //        }
                            //    }
                            //    /// Not sure why they would have more than 1 avatar item, so we'll ignore fom now
                            //    ///
                            //    break;
                            //}
                        }
                    }
                }
            }

            return(base.NewMessage(iq));
        }
Exemple #5
0
        // Look for subscribe message to subscribe to presence
        public override bool NewIQ(IQ iq)
        {
            if ((iqGetOurVCARD != null) && (iq.ID == iqGetOurVCARD.ID))
            {
                foreach (XElement vcard in iq.InitalXMLElement.Descendants("{vcard-temp}vCard"))
                {
                    vcard card = Utility.ParseObjectFromXMLString(vcard.ToString(), typeof(vcard)) as vcard;
                    if (card != null)
                    {
                        XMPPClient.vCard = card;
                    }
                }
                return(true);
            }

            if (iq.InitalXMLElement != null)
            {
                foreach (XElement vcard in iq.InitalXMLElement.Descendants("{vcard-temp}vCard"))
                {
                    vcard card = Utility.ParseObjectFromXMLString(vcard.ToString(), typeof(vcard)) as vcard;
                    if (card != null)
                    {
                        RosterItem item = XMPPClient.FindRosterItem(iq.From);
                        if (item != null)
                        {
                            item.vCard = card;
                        }
                        else if (iq.From.BareJID == XMPPClient.JID.BareJID)
                        {
                            XMPPClient.vCard = card;
                        }
                    }

                    return(true);
                }

                foreach (XElement avaelem in iq.InitalXMLElement.Descendants("{jabber:iq:avatar}query"))
                {
                    IQAvatarQuery ava = Utility.ParseObjectFromXMLString(avaelem.ToString(), typeof(IQAvatarQuery)) as IQAvatarQuery;
                    if (ava != null)
                    {
                        /// Found a new avatar using this 3rd method, tell the client
                    }

                    return(true);
                }
            }

            /// We'll handle vcards here
            ///


            //US: <iq id='b89c5r7ib574'
            //        to='[email protected]/foo'
            //        type='set'>
            //      <query xmlns='jabber:iq:roster'>
            //        <item ask='subscribe'
            //              jid='*****@*****.**'
            //              subscription='none'/>
            //      </query>
            //    </iq>

            //US: <iq id='b89c5r7ib575'
            //        to='[email protected]/bar'
            //        type='set'>
            //      <query xmlns='jabber:iq:roster'>
            //        <item ask='subscribe'
            //              jid='*****@*****.**'
            //              subscription='none'/>
            //      </query>
            //    </iq>


            return(base.NewIQ(iq));
        }
Exemple #6
0
        /// <presence id="AWAQt-31" from="[email protected]/calculon" to="[email protected]/phone"><status>Away</status><priority>0</priority><show>away</show></presence>

        public override bool NewPresence(PresenceMessage pres)
        {
            if ((pres.Type == "") || (pres.Type == "unavailable"))
            {
                /// Means avialbe
                ///
                RosterItem item = XMPPClient.FindRosterItem(pres.From);
                if (item != null)
                {
                    item.SetPresence(pres);
                }
            }
            //<presence from="[email protected]/calculon" to="*****@*****.**" type="subscribe"/>
            else if (pres.Type == "subscribe")
            {
                Answer answer = XMPPClient.ShouldSubscribeUser(pres);

                if (answer == Answer.Yes)
                {
                    AcceptUserPresence(pres, "", "");
                }
                else if (answer == Answer.No) /// reject if the user has responded
                {
                    DeclineUserPresence(pres);
                }
            }
            else if (pres.Type == "subscribed")
            {
            }
            else
            {
                RosterItem item = XMPPClient.FindRosterItem(pres.From);
                if (item != null)
                {
                    item.SetPresence(pres);
                    //item.Presence = pres.PresenceStatus;

                    /// Commented out because no one seems to support this method
                    //if (pres.AvatarHash != null)
                    //{
                    //    if (pres.AvatarHash.Hash != null)
                    //    {
                    //        /// May have a new avatar, check against our current file system
                    //        ///
                    //        if (XMPPClient.AvatarStorage.AvatarExist(pres.AvatarHash.Hash) == false)
                    //           DownloadAvatarJabberIQMethod(pres.From);
                    //    }
                    //}

                    if (pres.VCardUpdate != null)
                    {
                        if (pres.VCardUpdate.PhotoHash != null)
                        {
                            //byte [] bURL = Convert.FromBase64String(pres.VCardUpdate.PhotoHash);
                            //string strURL = System.Text.UTF8Encoding.UTF8.GetString(bURL, 0, bURL.Length);
                            //item.AvatarImagePath = strURL;



                            /// XEP-153 - vcard-based avatars... sha1 hash of the current avatar
                            if ((XMPPClient.AvatarStorage.AvatarExist(pres.VCardUpdate.PhotoHash) == false) && (XMPPClient.AutomaticallyDownloadAvatars == true))
                            {
                                RequestVCARD(pres.From);
                            }
                            else
                            {
                                item.AvatarImagePath = pres.VCardUpdate.PhotoHash;
                            }


                            //RequestVCARD(pres.From);


                            /// or XEP-0008 IQ based avatars
                            ///


                            /// or XEP- jaber fldlkjsl
                            //string strRelativeImage = string.Format("Avatars/{0}", pres.VCardUpdate.PhotoHash);
                            ///// See if this file exists, if it doesn't, download the file
                            /////
                            //if (System.IO.File.Exists(strRelativeImage) == true)
                            //    item.AvatarImagePath = strRelativeImage;
                            //else
                            //    //XMPPClient.PersonalEventingLogic.DownloadDataNode(jidfrom, "urn:xmpp:avatar:data", strItem);
                            //    XMPPClient.DownloadAvatar(pres.From, pres.VCardUpdate.PhotoHash);
                        }
                    }


                    System.Diagnostics.Debug.WriteLine(item.ToString());
                    XMPPClient.FireListChanged(1);
                }
            }

            return(true);
        }
Exemple #7
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);
        }