示例#1
0
文件: frmMain.cs 项目: don59/agsXmpp
		/// <summary>
		/// We received a message
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="msg"></param>
		private void XmppCon_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
		{
			if (InvokeRequired)
			{	
				// Windows Forms are not Thread Safe, we need to invoke this :(
				// We're not in the UI thread, so we need to call BeginInvoke				
				BeginInvoke(new OnMessageDelegate(XmppCon_OnMessage), new object[]{sender, msg});
				return;
			}

			// check for xData Message
			Element e = msg.SelectSingleElement(typeof(Data));
			if (e != null)
			{	
				Data xdata = e as Data;
				if (xdata.Type == XDataFormType.form)
				{
					frmXData fXData = new frmXData(xdata);
					fXData.Text = "xData Form from " + msg.From.ToString();
					fXData.Show();
				}
			}
			else
			{
				if (!Util.Forms.ContainsKey(msg.From.Bare))
				{
					ListViewItem itm = FindRosterListViewItem(msg.From);
					string nick =  itm == null ? msg.From.Bare : itm.Text;
				
					frmChat f = new frmChat(msg.From, XmppCon, nick);
					f.Show();
					f.IncomingMessage(msg);
				}
			}
		}
示例#2
0
    static void Xmpp_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
    {
        if (msg.HasTag(typeof(AgIXML)))
        {
            AgIXML agiMsg = msg.SelectSingleElement(typeof(AgIXML)) as AgIXML;
            agiMsg newMsg = new agiMsg();
            newMsg.ID = agiMsg.ID;
            newMsg.Type = agiMsg.Type;
            newMsg.Path = agiMsg.Path;
            newMsg.SessionID = agiMsg.SessionID;
            newMsg.SessionKey = agiMsg.SessionKey;
            newMsg.Data = agiMsg.Data;
            newMsg.Flags = agiMsg.Flags;

            switch (newMsg.Type)
            {
                case "tput":
                    xmppManager.world.agi.tput(newMsg);
                    break;
                case "rput":
                    xmppManager.world.agi.rput(newMsg);
                    break;
                case "tget":
                    xmppManager.world.agi.tget(newMsg);
                    break;
                case "rget":
                    xmppManager.world.agi.rget(newMsg);
                    break;
                case "tattach":
                    xmppManager.world.agi.tattach(newMsg);
                    break;
                case "rattach":
                    xmppManager.world.agi.rattach(newMsg);
                    break;
                case "tremove":
                    xmppManager.world.agi.tremove(newMsg);
                    break;
                case "rremove":
                    xmppManager.world.agi.rremove(newMsg);
                    break;
                case "tflush":
                    xmppManager.world.agi.tflush(newMsg);
                    break;
                case "rflush":
                    xmppManager.world.agi.rflush(newMsg);
                    break;
            }
        }

        if (msg.Body != null)
        {
             messages newMsg = new messages();
            newMsg.body = msg.Body;
            newMsg.from = msg.From.User;

            int count = 0;

            while (chats.Count != 0 && count < chats.Count)
            {
                if (chats.ElementAt(count).chatWith.userID == msg.From.User)
                {
                    chats.ElementAt(count).msgChain.Add(newMsg);
                    return;
                }
                count++;
            }

            chat newchat = new chat();
            newchat.msgChain.Add(newMsg);
            newchat.chatWith.userID = msg.From.User.ToString();
            chats.Add(newchat);
            Console.WriteLine(newMsg.body.ToString());
        }
    }
示例#3
0
        /// <summary>
        /// We received a message
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="msg"></param>
        private void XmppCon_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke
                BeginInvoke(new OnMessageDelegate(XmppCon_OnMessage), new object[] { sender, msg });
                return;
            }

            // Dont handle GroupChat Messages here, they have their own callbacks in the
            // GroupChat Form
            if (msg.Type == MessageType.groupchat)
                return;

            if (msg.Type == MessageType.error)
            {
                //Handle errors here
                // we dont handle them in this example
                return;
            }

            // check for xData Message

            if (msg.HasTag(typeof(Data)))
            {
                Element e = msg.SelectSingleElement(typeof(Data));
                Data xdata = e as Data;
                if (xdata.Type == XDataFormType.form)
                {
                    frmXData fXData = new frmXData(xdata);
                    fXData.Text = "xData Form from " + msg.From.ToString();
                    fXData.Show();
                }
            }
            else if (msg.HasTag(typeof(agsXMPP.protocol.extensions.ibb.Data)))
            {
                // ignore IBB messages
                return;
            }
            else
            {
                if (msg.Body != null)
                {
                    if (!Util.ChatForms.ContainsKey(msg.From.Bare))
                    {
                        RosterNode rn = rosterControl.GetRosterItem(msg.From);
                        string nick = msg.From.Bare;
                        if (rn != null)
                            nick = rn.Text;

                        frmChat f = new frmChat(msg.From, XmppCon, nick);
                        f.Show();
                        f.IncomingMessage(msg);
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        ///  Aqui capturo todos mensajes de precence-protocol para detectar abandonos de sala e ingresos
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="pres"></param>
        /// <param name="data"></param>
        private void PresenceCallback(object sender, agsXMPP.protocol.client.Presence pres, object data)
        {
            if (InvokeRequired)
            {
		
                BeginInvoke(new PresenceCB(PresenceCallback), new object[] { sender, pres, data });
                return;
            }

            ListViewItem lvi = FindListViewItem(pres.From);
            if (lvi != null)
            {
                if (pres.Type == PresenceType.unavailable)
                {
                    lvi.Remove();
                }
                else
                {
                    int imageIdx = Util.GetRosterImageIndex(pres);
                    lvi.ImageIndex = imageIdx;
                    lvi.SubItems[1].Text = (pres.Status == null ? "" : pres.Status);
                    User u = pres.SelectSingleElement(typeof(User)) as User;
                    if (u != null)
                    {
                        lvi.SubItems[2].Text = u.Item.Affiliation.ToString();
                        lvi.SubItems[3].Text = u.Item.Role.ToString();
                    }
                }
            }
            else
            {
                int imageIdx = Util.GetRosterImageIndex(pres);
                
                ListViewItem lv = new ListViewItem(pres.From.Resource);               

                lv.Tag = pres.From.ToString();
                lv.SubItems.Add(pres.Status == null ? "" : pres.Status);
                User u = pres.SelectSingleElement(typeof(User)) as User;
                if (u != null)
                {
                    lv.SubItems.Add(u.Item.Affiliation.ToString());
                    lv.SubItems.Add(u.Item.Role.ToString());
                }
                lv.ImageIndex = imageIdx;
                lvwRoster.Items.Add(lv);
            }
        }
示例#5
0
 /// <summary>
 /// Se produit lorsqu'un message est disponible
 /// </summary>
 /// <param name="sender">Objet parent</param>
 /// <param name="message">Message en question</param>
 private void xmppOnMessage(object sender, agsXMPP.protocol.client.Message message)
 {
     if (message.From != null)
     {
         string bare = message.From.Bare;
         if (message.From.Resource != null && message.Nickname != null)
         {
             if (contacts.ContainsKey(bare) && contacts[bare].ContainsKey(message.From.Resource) && message.Nickname.ToString().Trim() != string.Empty)
             {
                 contacts[bare][message.From.Resource].identity.nickname = message.Nickname.ToString().Trim();
             }
         }
         if (message.HasTag("event"))
         {
             agsXMPP.Xml.Dom.Element evt = message.SelectSingleElement("event");
             if (evt.Namespace == "http://jabber.org/protocol/pubsub#event" && evt.HasChildElements)
             {
                 #region PubSub Events
                 // HACK: Bug serveur. Suivant la XEP c'est Items, ejabberd2.0 retourne parfois Item sans S
                 if (evt.HasTag("items") || evt.HasTag("item"))
                 {
                     agsXMPP.Xml.Dom.Element items = evt.SelectSingleElement("items");
                     if (items == null)
                     {
                         items = evt.SelectSingleElement("item");
                     }
                     if (items.HasTag("item"))
                     {
                         agsXMPP.Xml.Dom.Element item = items.SelectSingleElement("item");
                         // TODO: g�rer le User mood dans les messages chat
                         #region User mood
                         if (items.HasAttribute("node") && (items.Attributes["node"] as string) == "http://jabber.org/protocol/mood" && (item.HasTag("mood") || item.HasTag("retract")))
                         {
                             agsXMPP.Xml.Dom.Element mood = item.SelectSingleElement("mood");
                             if (mood != null)
                             {
                                 // HACK: mood.Namespace == "http://jabber.org/protocol/mood"
                                 if (mood.HasChildElements)
                                 {
                                     Enumerations.MoodType moodType = Enumerations.MoodType.none;
                                     foreach (Enumerations.MoodType mt in Enum.GetValues(typeof(Enumerations.MoodType)))
                                     {
                                         string mtn = Enum.GetName(typeof(Enumerations.MoodType), mt);
                                         if (mood.HasTag(mtn))
                                         {
                                             moodType = mt;
                                             break;
                                         }
                                     }
                                     string moodString = string.Empty;
                                     if (mood.HasTag("text") && mood.SelectSingleElement("text").Value != null)
                                     {
                                         moodString = mood.SelectSingleElement("text").Value.Trim();
                                     }
                                     if (contacts.ContainsKey(bare) && contacts[bare].Values.Count > 0)
                                     {
                                         foreach (KeyValuePair<string, Contact> r in contacts[bare])
                                         {
                                             Mood md = new Mood();
                                             md.type = moodType;
                                             md.text = moodString;
                                             r.Value.mood = md;
                                             OnMoodUpdated(r.Value, r.Value.mood);
                                         }
                                     }
                                     else
                                     {
                                         Mood md = new Mood();
                                         md.type = moodType;
                                         md.text = moodString;
                                         UserPEP up = new UserPEP();
                                         up.mood = md;
                                         if (!initialUserPEP.ContainsKey(bare))
                                         {
                                             initialUserPEP.Add(bare, up);
                                         }
                                         else
                                         {
                                             up.tune = initialUserPEP[bare].tune;
                                             up.activity = initialUserPEP[bare].activity;
                                             up.location = initialUserPEP[bare].location;
                                             initialUserPEP[bare] = up;
                                         }
                                     }
                                 }
                             }
                             else if (item.SelectSingleElement("retract") != null)
                             {
                                 if (contacts.ContainsKey(bare) && contacts[bare].Values.Count > 0)
                                 {
                                     foreach (KeyValuePair<string, Contact> r in contacts[bare])
                                     {
                                         Mood md = new Mood();
                                         md.type = Enumerations.MoodType.none;
                                         md.text = string.Empty;
                                         r.Value.mood = md;
                                         OnMoodUpdated(r.Value, r.Value.mood);
                                     }
                                 }
                                 else
                                 {
                                     Mood md = new Mood();
                                     md.type = Enumerations.MoodType.none;
                                     md.text = string.Empty;
                                     UserPEP up = new UserPEP();
                                     up.mood = md;
                                     if (!initialUserPEP.ContainsKey(bare))
                                     {
                                         initialUserPEP.Add(bare, up);
                                     }
                                     else
                                     {
                                         up.tune = initialUserPEP[bare].tune;
                                         up.activity = initialUserPEP[bare].activity;
                                         up.location = initialUserPEP[bare].location;
                                         initialUserPEP[bare] = up;
                                     }
                                 }
                             }
                         }
                         #endregion
                         #region User activity
                         if (items.HasAttribute("node") && (items.Attributes["node"] as string) == "http://jabber.org/protocol/activity" && (item.HasTag("activity") || item.HasTag("retract")))
                         {
                             agsXMPP.Xml.Dom.Element activity = item.SelectSingleElement("activity");
                             if (activity != null)
                             {
                                 // HACK: activity.Namespace == "http://jabber.org/protocol/activity"
                                 if (activity.HasChildElements)
                                 {
                                     Enumerations.ActivityType activityType = Enumerations.ActivityType.none;
                                     List<string> activityTypes = recurseActivityTags(activity, new List<string>());
                                     activityTypes.Remove("activity");
                                     if (activityTypes.Count > 0)
                                     {
                                         object o = Enum.Parse(typeof(Enumerations.ActivityType), activityTypes[0], true);
                                         if (o != null)
                                         {
                                             activityType = (Enumerations.ActivityType)o;
                                         }
                                     }
                                     string activityString = string.Empty;
                                     if (activity.HasTag("text") && activity.SelectSingleElement("text").Value != null)
                                     {
                                         activityString = activity.SelectSingleElement("text").Value.Trim();
                                     }
                                     if (contacts.ContainsKey(bare) && contacts[bare].Values.Count > 0)
                                     {
                                         foreach (KeyValuePair<string, Contact> r in contacts[bare])
                                         {
                                             Activity a = new Activity();
                                             a.type = activityType;
                                             a.text = activityString;
                                             r.Value.activity = a;
                                             OnActivityUpdated(r.Value, r.Value.activity);
                                         }
                                     }
                                     else
                                     {
                                         Activity a = new Activity();
                                         a.type = activityType;
                                         a.text = activityString;
                                         UserPEP up = new UserPEP();
                                         up.activity = a;
                                         if (!initialUserPEP.ContainsKey(bare))
                                         {
                                             initialUserPEP.Add(bare, up);
                                         }
                                         else
                                         {
                                             up.tune = initialUserPEP[bare].tune;
                                             up.mood = initialUserPEP[bare].mood;
                                             up.location = initialUserPEP[bare].location;
                                             initialUserPEP[bare] = up;
                                         }
                                     }
                                 }
                             }
                             else if (item.SelectSingleElement("retract") != null)
                             {
                                 if (contacts.ContainsKey(bare) && contacts[bare].Values.Count > 0)
                                 {
                                     foreach (KeyValuePair<string, Contact> r in contacts[bare])
                                     {
                                         Activity a = new Activity();
                                         a.type = Enumerations.ActivityType.none;
                                         a.text = string.Empty;
                                         r.Value.activity = a;
                                         OnActivityUpdated(r.Value, r.Value.activity);
                                     }
                                 }
                                 else
                                 {
                                     Activity a = new Activity();
                                     a.type = Enumerations.ActivityType.none;
                                     a.text = string.Empty;
                                     UserPEP up = new UserPEP();
                                     up.activity = a;
                                     if (!initialUserPEP.ContainsKey(bare))
                                     {
                                         initialUserPEP.Add(bare, up);
                                     }
                                     else
                                     {
                                         up.tune = initialUserPEP[bare].tune;
                                         up.mood = initialUserPEP[bare].mood;
                                         up.location = initialUserPEP[bare].location;
                                         initialUserPEP[bare] = up;
                                     }
                                 }
                             }
                         }
                         #endregion
                         #region User location
                         if (items.HasAttribute("node") && (items.Attributes["node"] as string) == "http://jabber.org/protocol/geoloc" && (item.HasTag("geoloc") || item.HasTag("retract")))
                         {
                             agsXMPP.Xml.Dom.Element geoloc = item.SelectSingleElement("geoloc");
                             if (geoloc != null)
                             {
                                 // HACK: geoloc.Namespace == "http://jabber.org/protocol/geoloc"
                                 if (geoloc.HasChildElements)
                                 {
                                     Location l = new Location();
                                     l.altitude = (geoloc.HasTag("alt") && geoloc.SelectSingleElement("alt").Value != null) ? Convert.ToDouble(geoloc.SelectSingleElement("alt").Value, System.Globalization.CultureInfo.InvariantCulture) : 0.0d;
                                     l.latitude = (geoloc.HasTag("lat") && geoloc.SelectSingleElement("lat").Value != null) ? Convert.ToDouble(geoloc.SelectSingleElement("lat").Value, System.Globalization.CultureInfo.InvariantCulture) : 0.0d;
                                     l.longitude = (geoloc.HasTag("lon") && geoloc.SelectSingleElement("lon").Value != null) ? Convert.ToDouble(geoloc.SelectSingleElement("lon").Value, System.Globalization.CultureInfo.InvariantCulture) : 0.0d;
                                     l.bearing = (geoloc.HasTag("bearing") && geoloc.SelectSingleElement("bearing").Value != null) ? Convert.ToDouble(geoloc.SelectSingleElement("bearing").Value, System.Globalization.CultureInfo.InvariantCulture) : 0.0d;
                                     l.error = (geoloc.HasTag("error") && geoloc.SelectSingleElement("error").Value != null) ? Convert.ToDouble(geoloc.SelectSingleElement("error").Value, System.Globalization.CultureInfo.InvariantCulture) : 0.0d;
                                     l.speed = (geoloc.HasTag("speed") && geoloc.SelectSingleElement("speed").Value != null) ? Convert.ToDouble(geoloc.SelectSingleElement("speed").Value, System.Globalization.CultureInfo.InvariantCulture) : 0.0d;
                                     l.area = (geoloc.HasTag("area") && geoloc.SelectSingleElement("area").Value != null) ? geoloc.SelectSingleElement("area").Value.Trim() : string.Empty;
                                     l.building = (geoloc.HasTag("building") && geoloc.SelectSingleElement("building").Value != null) ? geoloc.SelectSingleElement("building").Value.Trim() : string.Empty;
                                     l.country = (geoloc.HasTag("country") && geoloc.SelectSingleElement("country").Value != null) ? geoloc.SelectSingleElement("country").Value.Trim() : string.Empty;
                                     l.datum = (geoloc.HasTag("datum") && geoloc.SelectSingleElement("datum").Value != null) ? geoloc.SelectSingleElement("datum").Value.Trim() : string.Empty;
                                     l.description = (geoloc.HasTag("description") && geoloc.SelectSingleElement("description").Value != null) ? geoloc.SelectSingleElement("description").Value.Trim() : string.Empty;
                                     l.floor = (geoloc.HasTag("floor") && geoloc.SelectSingleElement("floor").Value != null) ? geoloc.SelectSingleElement("floor").Value.Trim() : string.Empty;
                                     l.locality = (geoloc.HasTag("locality") && geoloc.SelectSingleElement("locality").Value != null) ? geoloc.SelectSingleElement("locality").Value.Trim() : string.Empty;
                                     l.postalcode = (geoloc.HasTag("postalcode") && geoloc.SelectSingleElement("postalcode").Value != null) ? geoloc.SelectSingleElement("postalcode").Value.Trim() : string.Empty;
                                     l.region = (geoloc.HasTag("region") && geoloc.SelectSingleElement("region").Value != null) ? geoloc.SelectSingleElement("region").Value.Trim() : string.Empty;
                                     l.room = (geoloc.HasTag("room") && geoloc.SelectSingleElement("room").Value != null) ? geoloc.SelectSingleElement("room").Value.Trim() : string.Empty;
                                     l.street = (geoloc.HasTag("street") && geoloc.SelectSingleElement("street").Value != null) ? geoloc.SelectSingleElement("street").Value.Trim() : string.Empty; l.area = (geoloc.HasTag("area") && geoloc.SelectSingleElement("area").Value != null) ? geoloc.SelectSingleElement("area").Value.Trim() : string.Empty;
                                     l.text = (geoloc.HasTag("text") && geoloc.SelectSingleElement("text").Value != null) ? geoloc.SelectSingleElement("text").Value.Trim() : string.Empty;
                                     l.timestamp = (geoloc.HasTag("timestamp") && geoloc.SelectSingleElement("timestamp").Value != null) ? DateTime.Parse(geoloc.SelectSingleElement("timestamp").Value) : new DateTime();
                                     l.uri = (geoloc.HasTag("uri") && geoloc.SelectSingleElement("uri").Value != null) ? geoloc.SelectSingleElement("uri").Value.Trim() : string.Empty;
                                     if (contacts.ContainsKey(bare) && contacts[bare].Values.Count > 0)
                                     {
                                         foreach (KeyValuePair<string, Contact> r in contacts[bare])
                                         {
                                             r.Value.location = l;
                                             OnLocationUpdated(r.Value, r.Value.location);
                                         }
                                     }
                                     else
                                     {
                                         UserPEP up = new UserPEP();
                                         up.location = l;
                                         if (!initialUserPEP.ContainsKey(bare))
                                         {
                                             initialUserPEP.Add(bare, up);
                                         }
                                         else
                                         {
                                             up.tune = initialUserPEP[bare].tune;
                                             up.mood = initialUserPEP[bare].mood;
                                             up.activity = initialUserPEP[bare].activity;
                                             initialUserPEP[bare] = up;
                                         }
                                     }
                                 }
                             }
                             else if (item.SelectSingleElement("retract") != null)
                             {
                                 Location l = new Location();
                                 l.altitude = 0;
                                 l.latitude = 0;
                                 l.longitude = 0;
                                 l.bearing = 0;
                                 l.error = 0;
                                 l.speed = 0;
                                 l.area = string.Empty;
                                 l.building = string.Empty;
                                 l.country = string.Empty;
                                 l.datum = string.Empty;
                                 l.description = string.Empty;
                                 l.floor = string.Empty;
                                 l.locality = string.Empty;
                                 l.postalcode = string.Empty;
                                 l.region = string.Empty;
                                 l.room = string.Empty;
                                 l.street = string.Empty;
                                 l.text = string.Empty;
                                 l.timestamp = new DateTime();
                                 l.uri = string.Empty;
                                 if (contacts.ContainsKey(bare) && contacts[bare].Values.Count > 0)
                                 {
                                     foreach (KeyValuePair<string, Contact> r in contacts[bare])
                                     {
                                         r.Value.location = l;
                                         OnLocationUpdated(r.Value, r.Value.location);
                                     }
                                 }
                                 else
                                 {
                                     UserPEP up = new UserPEP();
                                     up.location = l;
                                     if (!initialUserPEP.ContainsKey(bare))
                                     {
                                         initialUserPEP.Add(bare, up);
                                     }
                                     else
                                     {
                                         up.tune = initialUserPEP[bare].tune;
                                         up.mood = initialUserPEP[bare].mood;
                                         up.activity = initialUserPEP[bare].activity;
                                         initialUserPEP[bare] = up;
                                     }
                                 }
                             }
                         }
                         #endregion
                         #region User tune
                         if (items.HasAttribute("node") && (items.Attributes["node"] as string) == "http://jabber.org/protocol/tune" && (item.HasTag("tune") || item.HasTag("retract")))
                         {
                             agsXMPP.Xml.Dom.Element tune = item.SelectSingleElement("tune");
                             if (tune != null)
                             {
                                 // HACK: tune.Namespace == "http://jabber.org/protocol/tune"
                                 if (tune.HasChildElements)
                                 {
                                     Tune t = new Tune();
                                     t.length = (tune.HasTag("length") && tune.SelectSingleElement("length").Value != null) ? Convert.ToInt32(tune.SelectSingleElement("length").Value, System.Globalization.CultureInfo.InvariantCulture) : 0;
                                     t.rating = (tune.HasTag("rating") && tune.SelectSingleElement("rating").Value != null) ? Convert.ToInt32(tune.SelectSingleElement("rating").Value, System.Globalization.CultureInfo.InvariantCulture) : 0;
                                     t.track = (tune.HasTag("track") && tune.SelectSingleElement("track").Value != null) ? Convert.ToInt32(tune.SelectSingleElement("track").Value, System.Globalization.CultureInfo.InvariantCulture) : 0;
                                     t.artist = (tune.HasTag("artist") && tune.SelectSingleElement("artist").Value != null) ? tune.SelectSingleElement("artist").Value.Trim() : string.Empty;
                                     t.source = (tune.HasTag("source") && tune.SelectSingleElement("source").Value != null) ? tune.SelectSingleElement("source").Value.Trim() : string.Empty;
                                     t.title = (tune.HasTag("title") && tune.SelectSingleElement("title").Value != null) ? tune.SelectSingleElement("title").Value.Trim() : string.Empty;
                                     t.uri = (tune.HasTag("uri") && tune.SelectSingleElement("uri").Value != null) ? tune.SelectSingleElement("uri").Value.Trim() : string.Empty;
                                     if (contacts.ContainsKey(bare) && contacts[bare].Values.Count > 0)
                                     {
                                         foreach (KeyValuePair<string, Contact> r in contacts[bare])
                                         {
                                             r.Value.tune = t;
                                             OnTuneUpdated(r.Value, r.Value.tune);
                                         }
                                     }
                                     else
                                     {
                                         UserPEP up = new UserPEP();
                                         up.tune = t;
                                         if (!initialUserPEP.ContainsKey(bare))
                                         {
                                             initialUserPEP.Add(bare, up);
                                         }
                                         else
                                         {
                                             up.mood = initialUserPEP[bare].mood;
                                             up.activity = initialUserPEP[bare].activity;
                                             up.location = initialUserPEP[bare].location;
                                             initialUserPEP[bare] = up;
                                         }
                                     }
                                 }
                             }
                             else if (item.SelectSingleElement("retract") != null)
                             {
                                 Tune t = new Tune();
                                 t.artist = string.Empty;
                                 t.length = 0;
                                 t.rating = 1;
                                 t.source = string.Empty;
                                 t.title = string.Empty;
                                 t.track = 0;
                                 t.uri = string.Empty;
                                 if (contacts.ContainsKey(bare) && contacts[bare].Values.Count > 0)
                                 {
                                     foreach (KeyValuePair<string, Contact> r in contacts[bare])
                                     {
                                         r.Value.tune = t;
                                         OnTuneUpdated(r.Value, r.Value.tune);
                                     }
                                 }
                                 else
                                 {
                                     UserPEP up = new UserPEP();
                                     up.tune = t;
                                     if (!initialUserPEP.ContainsKey(bare))
                                     {
                                         initialUserPEP.Add(bare, up);
                                     }
                                     else
                                     {
                                         up.mood = initialUserPEP[bare].mood;
                                         up.activity = initialUserPEP[bare].activity;
                                         up.location = initialUserPEP[bare].location;
                                         initialUserPEP[bare] = up;
                                     }
                                 }
                             }
                         }
                         #endregion
                         #region User nickname
                         if (items.HasAttribute("node") && (items.Attributes["node"] as string) == "http://jabber.org/protocol/nick" && item.HasTag("nick"))
                         {
                             agsXMPP.Xml.Dom.Element nick = item.SelectSingleElement("nick");
                             if (nick != null)
                             {
                                 // HACK: nick.Namespace == "http://jabber.org/protocol/nick"
                                 if (nick.HasChildElements)
                                 {
                                     string nm = (nick.Value != null) ? nick.Value.Trim() : string.Empty;
                                     if (nm != string.Empty)
                                     {
                                         if (contacts.ContainsKey(bare) && contacts[bare].Values.Count > 0)
                                         {
                                             foreach (KeyValuePair<string, Contact> r in contacts[bare])
                                             {
                                                 r.Value.identity.nickname = nm;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         #endregion
                     }
                 }
                 #endregion
             }
         }
     }
 }
示例#6
0
文件: frmMain.cs 项目: don59/agsXmpp
        private void XmppCon_OnIq(object sender, agsXMPP.protocol.client.IQ iq)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke				
                BeginInvoke(new IqHandler(XmppCon_OnIq), new object[] { sender, iq });
                return;
            }
                       

            if (iq != null)
            {
                // No Iq with query
                if (iq.HasTag(typeof(agsXMPP.protocol.extensions.si.SI)))
                {
                    if (iq.Type == IqType.set)
                    {
                        agsXMPP.protocol.extensions.si.SI si = iq.SelectSingleElement(typeof(agsXMPP.protocol.extensions.si.SI)) as agsXMPP.protocol.extensions.si.SI;

                        agsXMPP.protocol.extensions.filetransfer.File file = si.File;
                        if (file != null)
                        {
                            // somebody wants to send a file to us
                            Console.WriteLine(file.Size.ToString());
                            Console.WriteLine(file.Name);
                            frmFileTransfer frmFile = new frmFileTransfer(XmppCon, iq);
                            frmFile.Show();
                        }
                    }
                }                
                else
                {
                    Element query = iq.Query;

                    if (query != null)
                    {
                        if (query.GetType() == typeof(agsXMPP.protocol.iq.version.Version))
                        {
                            // its a version IQ VersionIQ
                            agsXMPP.protocol.iq.version.Version version = query as agsXMPP.protocol.iq.version.Version;
                            if (iq.Type == IqType.get)
                            {
                                // Somebody wants to know our client version, so send it back
                                iq.SwitchDirection();
                                iq.Type = IqType.result;

                                version.Name = "MiniClient";
                                version.Ver = "0.5";
                                version.Os = Environment.OSVersion.ToString();

                                XmppCon.Send(iq);
                            }
                        }                        
                    }
                }
            }
        }
示例#7
0
 /// <summary>
 /// XMPP
 /// </summary>
 /// <param name="sender">Objet parent</param>
 /// <param name="el">Element</param>
 private void ElementError(object sender, agsXMPP.Xml.Dom.Element el)
 {
     if (el.HasTag("error", true)) {
         agsXMPP.Xml.Dom.Element e = el.SelectSingleElement("error", true);
         int code = 0;
         if (e.HasAttribute("code")) { code = Convert.ToInt32(e.Attribute("code")); }
         switch (code) {
             case 302:
                 OnErrorRaised(Enums.ErrorType.Query, "Request redirected.");
                 break;
             case 400:
                 OnErrorRaised(Enums.ErrorType.Query, "Bad Request.");
                 break;
             case 401:
                 OnErrorRaised(Enums.ErrorType.Authentification, "Account not authorized.");
                 break;
             case 402:
                 OnErrorRaised(Enums.ErrorType.Authentification, "Account incorrect.");
                 break;
             case 403:
                 OnErrorRaised(Enums.ErrorType.Authentification, "Account denied.");
                 break;
             case 404:
                 OnErrorRaised(Enums.ErrorType.Warning, "Request discontinued.");
                 break;
             case 405:
                 OnErrorRaised(Enums.ErrorType.Warning, "Request prohibited.");
                 break;
             case 406:
                 OnErrorRaised(Enums.ErrorType.Query, "Request not authorized.");
                 break;
             case 407:
                 OnErrorRaised(Enums.ErrorType.Authentification, "Account not registered.");
                 break;
             case 408:
                 OnErrorRaised(Enums.ErrorType.Server, "Server Timeout.");
                 break;
             case 409:
                 OnErrorRaised(Enums.ErrorType.Warning, "Conflicting request.");
                 break;
             case 500:
                 OnErrorRaised(Enums.ErrorType.Server, "Internal error.");
                 break;
             case 501:
                 OnErrorRaised(Enums.ErrorType.Warning, "Request not implemented.");
                 break;
             case 502:
                 OnErrorRaised(Enums.ErrorType.Server, "Distant error.");
                 break;
             case 503:
                 OnErrorRaised(Enums.ErrorType.Warning, "Service temporarily not available.");
                 break;
             case 504:
                 OnErrorRaised(Enums.ErrorType.Server, "Distant time limit reached.");
                 break;
             case 510:
                 OnErrorRaised(Enums.ErrorType.Warning, "Disconnected.");
                 break;
             default:
                 OnErrorRaised(Enums.ErrorType.Client, "General error.");
                 break;
         }
     } else {
         if (el.HasTag("bad-request", true)) {
             OnErrorRaised(Enums.ErrorType.Query, "Request incorrect.");
         } else if (el.HasTag("conflict", true)) {
             OnErrorRaised(Enums.ErrorType.Warning, "Conflicting request.");
         } else if (el.HasTag("feature-not-implemented", true)) {
             OnErrorRaised(Enums.ErrorType.Warning, "Request not implemented.");
         } else if (el.HasTag("forbidden", true)) {
             OnErrorRaised(Enums.ErrorType.Authentification, "Account not authorized.");
         } else if (el.HasTag("gone", true)) {
             OnErrorRaised(Enums.ErrorType.Query, "Request redirected.");
         } else if (el.HasTag("internal-server-error", true)) {
             OnErrorRaised(Enums.ErrorType.Server, "Internal error.");
         } else if (el.HasTag("item-not-found", true)) {
             OnErrorRaised(Enums.ErrorType.Warning, "Request discontinued.");
         } else if (el.HasTag("jid-malformed", true)) {
             OnErrorRaised(Enums.ErrorType.Query, "Jabber ID incorrect.");
         } else if (el.HasTag("not-acceptable", true)) {
             OnErrorRaised(Enums.ErrorType.Query, "Request not accepted.");
         } else if (el.HasTag("not-allowed", true)) {
             OnErrorRaised(Enums.ErrorType.Server, "Operation not allowed");
         } else if (el.HasTag("not-authorized", true)) {
             OnErrorRaised(Enums.ErrorType.Query, "Request not authorized.");
         } else if (el.HasTag("payment-required", true)) {
             OnErrorRaised(Enums.ErrorType.Query, "Finalisation requise.");
         } else if (el.HasTag("recipient-unavailable", true)) {
             OnErrorRaised(Enums.ErrorType.Query, "Recipient unavailable.");
         } else if (el.HasTag("redirect", true)) {
             OnErrorRaised(Enums.ErrorType.Query, "Request redirected.");
         } else if (el.HasTag("registration-required", true)) {
             OnErrorRaised(Enums.ErrorType.Authentification, "Account not registered.");
         } else if (el.HasTag("remote-server-not-found", true)) {
             OnErrorRaised(Enums.ErrorType.Server, "Distant error.");
         } else if (el.HasTag("remote-server-timeout", true)) {
             OnErrorRaised(Enums.ErrorType.Server, "Server Timeout.");
         } else if (el.HasTag("resource-constraint", true)) {
             OnErrorRaised(Enums.ErrorType.Authentification, "Resource invalid.");
         } else if (el.HasTag("service-unavailable", true)) {
             OnErrorRaised(Enums.ErrorType.Warning, "Service temporary not available");
         } else if (el.HasTag("subscription-required", true)) {
             OnErrorRaised(Enums.ErrorType.Client, "Abonnement required.");
         } else if (el.HasTag("undefined-condition", true)) {
             OnErrorRaised(Enums.ErrorType.Client, "Condition undefined.");
         } else if (el.HasTag("unexpected-request", true)) {
             OnErrorRaised(Enums.ErrorType.Query, "Bad Request.");
         }
     }
 }
示例#8
0
 /// <summary>
 /// XMPP
 /// </summary>
 /// <param name="sender">Objet parent</param>
 /// <param name="el">Element</param>
 private void ElementError(object sender, agsXMPP.Xml.Dom.Element el)
 {
     if (el.HasTag("error", true))
     {
         agsXMPP.Xml.Dom.Element e = el.SelectSingleElement("error", true);
         int code = 0;
         if (e.HasAttribute("code")) { code = Convert.ToInt32(e.Attribute("code")); }
         switch (code)
         {
             case 302:
                 OnErrorRaised(Enumerations.ErrorType.Query, "Demande redirig�.");
                 break;
             case 400:
                 OnErrorRaised(Enumerations.ErrorType.Query, "Demande incorrecte.");
                 break;
             case 401:
                 OnErrorRaised(Enumerations.ErrorType.Authentification, "Compte non autauris�.");
                 break;
             case 402:
                 OnErrorRaised(Enumerations.ErrorType.Authentification, "Compte incorrect.");
                 break;
             case 403:
                 OnErrorRaised(Enumerations.ErrorType.Authentification, "Compte refus�.");
                 break;
             case 404:
                 OnErrorRaised(Enumerations.ErrorType.Warning, "Demande inconnue.");
                 break;
             case 405:
                 OnErrorRaised(Enumerations.ErrorType.Warning, "Demande interdite.");
                 break;
             case 406:
                 OnErrorRaised(Enumerations.ErrorType.Query, "Demande non autoris�e.");
                 break;
             case 407:
                 OnErrorRaised(Enumerations.ErrorType.Authentification, "Compte non enregistr�.");
                 break;
             case 408:
                 OnErrorRaised(Enumerations.ErrorType.Server, "Temps limite atteint.");
                 break;
             case 409:
                 OnErrorRaised(Enumerations.ErrorType.Warning, "Demande en conflit.");
                 break;
             case 500:
                 OnErrorRaised(Enumerations.ErrorType.Server, "Erreur interne.");
                 break;
             case 501:
                 OnErrorRaised(Enumerations.ErrorType.Warning, "Demande non impl�ment�e.");
                 break;
             case 502:
                 OnErrorRaised(Enumerations.ErrorType.Server, "Erreur distante.");
                 break;
             case 503:
                 OnErrorRaised(Enumerations.ErrorType.Warning, "Service temporairement innaccessible.");
                 break;
             case 504:
                 OnErrorRaised(Enumerations.ErrorType.Server, "Temps limite distant atteint.");
                 break;
             case 510:
                 OnErrorRaised(Enumerations.ErrorType.Warning, "D�connect�.");
                 break;
             default:
                 OnErrorRaised(Enumerations.ErrorType.Client, "Erreur g�n�rale.");
                 break;
         }
     }
     else
     {
         if (el.HasTag("bad-request", true)) { OnErrorRaised(Enumerations.ErrorType.Query, "Demande incorrecte."); }
         else if (el.HasTag("conflict", true)) { OnErrorRaised(Enumerations.ErrorType.Warning, "Demande en conflit."); }
         else if (el.HasTag("feature-not-implemented", true)) { OnErrorRaised(Enumerations.ErrorType.Warning, "Demande non impl�ment�e."); }
         else if (el.HasTag("forbidden", true)) { OnErrorRaised(Enumerations.ErrorType.Authentification, "Compte non autoris�."); }
         else if (el.HasTag("gone", true)) { OnErrorRaised(Enumerations.ErrorType.Query, "Demande redirig�e"); }
         else if (el.HasTag("internal-server-error", true)) { OnErrorRaised(Enumerations.ErrorType.Server, "Erreur interne."); }
         else if (el.HasTag("item-not-found", true)) { OnErrorRaised(Enumerations.ErrorType.Warning, "El�ment inconnu."); }
         else if (el.HasTag("jid-malformed", true)) { OnErrorRaised(Enumerations.ErrorType.Query, "Jabber ID incorrect."); }
         else if (el.HasTag("not-acceptable", true)) { OnErrorRaised(Enumerations.ErrorType.Query, "Demande non accept�e."); }
         else if (el.HasTag("not-allowed", true)) { OnErrorRaised(Enumerations.ErrorType.Server, "Op�ration non autoris�e."); }
         else if (el.HasTag("not-authorized", true)) { OnErrorRaised(Enumerations.ErrorType.Query, "Demande non autoris�e."); }
         else if (el.HasTag("payment-required", true)) { OnErrorRaised(Enumerations.ErrorType.Query, "Finalisation requise."); }
         else if (el.HasTag("recipient-unavailable", true)) { OnErrorRaised(Enumerations.ErrorType.Query, "Destinataire non disponible."); }
         else if (el.HasTag("redirect", true)) { OnErrorRaised(Enumerations.ErrorType.Query, "Demande redirig�."); }
         else if (el.HasTag("registration-required", true)) { OnErrorRaised(Enumerations.ErrorType.Authentification, "Compte non enregistr�."); }
         else if (el.HasTag("remote-server-not-found", true)) { OnErrorRaised(Enumerations.ErrorType.Server, "Erreur distante."); }
         else if (el.HasTag("remote-server-timeout", true)) { OnErrorRaised(Enumerations.ErrorType.Server, "Temps limite distant atteint."); }
         else if (el.HasTag("resource-constraint", true)) { OnErrorRaised(Enumerations.ErrorType.Authentification, "Ressource valide requise."); }
         else if (el.HasTag("service-unavailable", true)) { OnErrorRaised(Enumerations.ErrorType.Warning, "Service temporairement innaccessible."); }
         else if (el.HasTag("subscription-required", true)) { OnErrorRaised(Enumerations.ErrorType.Client, "Abonnement requis."); }
         else if (el.HasTag("undefined-condition", true)) { OnErrorRaised(Enumerations.ErrorType.Client, "Condition inconnue."); }
         else if (el.HasTag("unexpected-request", true)) { OnErrorRaised(Enumerations.ErrorType.Query, "Demande incorrecte."); }
     }
 }
        void xmppConnection_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
        {
            //Trace.WriteLine(msg.ToString());
            if (msg.From.Bare != ServiceSender)
                return;

            Element entryE = msg.SelectSingleElement("entry");
            Element sourceE = entryE.SelectSingleElement("source");
            Element authorE = sourceE.SelectSingleElement("author");

            User user = new User
            {
                Description = authorE.GetTag("description"),
                Id = authorE.GetTagInt("twitter_id"),
                Location = authorE.GetTag("location"),
                Protected = authorE.GetTagBool("protected"),
                Name = authorE.GetTag("name"),
                ScreenName = authorE.GetTag("screen_name"),
                Url = authorE.GetTag("url"),
                ProfileImageUrl = authorE.GetTag("profile_image_url")
            };

            String body = msg.Body;
            if (body.IndexOf(": ") > -1)
                body = body.Substring(body.IndexOf(": ") + 2);

            Status status = new Status
            {
                CreatedAt = DateTime.Parse(entryE.GetTag("published")),
                Text = body,
                User = user,
                Id = entryE.GetTagInt((entryE.GetTagInt("twitter_id") == 0 ? "status_id" : "twitter_id")) // HACK: 何故かどっちかでくる
            };

            OnStatusUpdateReceived(status);
        }
示例#10
0
文件: frmMain.cs 项目: phiree/dzdocs
        /// <summary>
        /// We received a message
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="msg"></param>
        private void XmppCon_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke
                BeginInvoke(new OnMessageDelegate(XmppCon_OnMessage), new object[] { sender, msg });
                return;
            }

            // check for xData Message
            Element e = msg.SelectSingleElement(typeof(Data));
            if (e != null)
            {
                Data xdata = e as Data;
                if (xdata.Type == XDataFormType.form)
                {
                    // This is not supported by the WM5 MiniClient sample
                }
            }
            else
            {
                if (msg.Type == MessageType.chat)
                {
                    if (!Util.Forms.ContainsKey(msg.From.Bare))
                    {
                        ListViewItem itm = FindRosterListViewItem(msg.From);
                        string nick = itm == null ? msg.From.Bare : itm.Text;

                        frmChat f = new frmChat(msg.From, XmppCon, nick);
                        f.Show();
                        f.IncomingMessage(msg);
                    }
                }
                else if (msg.Type == MessageType.normal)
                {
                    frmMsg fMsg = new frmMsg(msg);
                    fMsg.Show();
                }
                else if (msg.Type == MessageType.headline)
                {
                    // not handeled in this example
                }
            }
        }
示例#11
0
        public void SwitchIQ(agsXMPP.protocol.client.IQ iq)
        {
            if (iq == null) return;


            // No Iq with query
            if (iq.HasTag(typeof(SI)))
            {
                if (iq.Type == IqType.set)
                {
                    SI si = iq.SelectSingleElement(typeof(SI)) as SI;

                    agsXMPP.protocol.extensions.filetransfer.File file = si.File;
                    if (file != null)
                    {
                        // somebody wants to send a file to us
                        AddLog(string.Concat("Alguien esta enviando un archivo Size:", file.Size.ToString(), " nombre: ", file.Name));

                        //frmFileTransfer frmFile = new frmFileTransfer(XmppCon, iq);
                        //frmFile.Show();
                    }
                }
            }

            if (iq.Type == IqType.error)
            {
                //if (iq.Error.Code == agsXMPP.protocol.client.ErrorCode.NotFound)
                //{
                    string msg = string.Concat(iq.From ," ", iq.Error.Condition);
                    AddLog(msg);
                //}
            }

            if (iq.Type == IqType.get)
            {
                if (iq.Query != null)
                {
                    if (iq.Query is DiscoInfo)
                    {
                        //iq.SwitchDirection();
                        //iq.Type = IqType.result;
                        //DiscoInfo di = getDiscoInfo();
                        //iq.Query = di;
                        //XmppCon.Send(iq);
                    }
                    else if (iq.Query is DiscoItems)
                    {
                        //iq.SwitchDirection();
                        //iq.Type = IqType.error;
                        //iq.Error = new Error(ErrorType.cancel, ErrorCondition.FeatureNotImplemented);
                        //XmppCon.Send(iq);
                    }
                    else if (iq.Query is agsXMPP.protocol.iq.version.Version)
                    {
                        //Suichea  from y to
                        iq.SwitchDirection();
                        iq.Type = IqType.result;//indica retorno o respuesta

                        agsXMPP.protocol.iq.version.Version version = iq.Query as agsXMPP.protocol.iq.version.Version;
                        version.Name = Assembly.GetExecutingAssembly().GetName().Name;
                        version.Ver = Assembly.GetExecutingAssembly().GetName().Version.ToString();
                        version.Os = Environment.OSVersion.ToString();
                        Util.XmppServices.XmppCon.Send(iq);
                        //frmMain.AddLog("IQ: tipo vesion");
                    }
                    else if (iq.Query is agsXMPP.protocol.iq.last.Last)
                    {
                        //iq.SwitchDirection();
                        //iq.Type = IqType.result;
                        //agsXMPP.protocol.iq.last.Last last = iq.Query as agsXMPP.protocol.iq.last.Last;
                        //last.Seconds = new TimeSpan(Jabber._presence.getLastActivityTicks()).Seconds;
                        //Jabber.xmpp.Send(iq);
                    }
                    else if (iq.Query is agsXMPP.protocol.iq.time.Time)
                    {
                        iq.SwitchDirection();
                        iq.Type = IqType.result;
                        agsXMPP.protocol.iq.time.Time time = iq.Query as agsXMPP.protocol.iq.time.Time;
                        time.Display = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
                        time.Tz = TimeZone.CurrentTimeZone.StandardName;
                        time.Utc = agsXMPP.util.Time.ISO_8601Date(DateTime.Now);
                        Util.XmppServices.XmppCon.Send(iq);
                    }
                    else if (iq.Query is agsXMPP.protocol.extensions.ping.Ping)
                    {
                        iq.SwitchDirection();
                        iq.Type = IqType.result;
                        agsXMPP.protocol.extensions.ping.Ping ping = iq.Query as agsXMPP.protocol.extensions.ping.Ping;
                        Util.XmppServices.XmppCon.Send(iq);
                    }
                    else if (iq.Query is agsXMPP.protocol.iq.avatar.Avatar)
                    {
                        iq.SwitchDirection();
                        iq.Type = IqType.result;
                        agsXMPP.protocol.iq.avatar.Avatar avatar = iq.Query as agsXMPP.protocol.iq.avatar.Avatar;
                        avatar.Data = null;
                        if (Jabber._identity.photo != null && Jabber._identity.photoFormat != null)
                        {
                            MemoryStream ms = new MemoryStream();
                            Jabber._identity.photo.Save(ms, Jabber._identity.photoFormat);
                            avatar.Data = ms.ToArray();
                            avatar.MimeType = "image/" + Jabber._identity.photoFormat.ToString();
                            ms.Close();
                            ms.Dispose();
                        }
                        Jabber.xmpp.Send(iq);
                    }
                    else if (iq.Query is agsXMPP.protocol.iq.vcard.Vcard)
                    {
                        iq.SwitchDirection();
                        iq.Type = IqType.result;
                        iq.Query = Jabber._identity.toVcard();
                        Jabber.xmpp.Send(iq);
                    }









                }
            }


        }