Ejemplo n.º 1
0
		public static Stanza GetStanza(XmlNode xml) 
		{
			Stanza s = null;
			switch(xml.Name)
			{
				case "iq":
					s = new IQStanza(xml);
					break;
				case "message":
					s = new MessageStanza(xml);
					break;
				case "presence":
					s = new PresenceStanza(xml);
					break;
				default:
					s = new Stanza(xml);
					break;
			}
			return s;
		}
Ejemplo n.º 2
0
		private void onIqStanzaReceived(IQStanza s)
		{
			switch(s.Type)
			{
				case "get":
					// TODO
					break;
				case "set":
					if(s.Query != null && s.Query.NamespaceURI == "jabber:iq:roster")
						session.SendStanza(StanzaFactory.GetRosterStanza(session.JabberID));
					break;
				case "error":
					// TODO
					break;
				case "result":
					// We have received our roster
					if(s.Query != null && s.Query.NamespaceURI == "jabber:iq:roster")
					{
						Hashtable newRoster = new Hashtable();
						rosterView.Nodes.Clear();

						// Create new roster containing only those people in the query
						foreach(XmlNode item in s.Query.ChildNodes)
						{
							if(item.Name == "item")
							{
								string jid = item.Attributes["jid"].Value;
								Contact c = new Contact();							
								c.BaseJabberId = jid;
								c.Name = item.Attributes["name"] == null ? jid : item.Attributes["name"].Value;
								newRoster.Add(jid, c);
							}
						}

						// Preserve resource information for people in our old roster
						foreach(Contact c in roster.Values)
						{
							if(newRoster[c.BaseJabberId] != null) newRoster[c.BaseJabberId] = c;
						}

						roster = newRoster;
							
						refreshRosterView();
					}
					break;
			}
		}