public static IQ RequestItem(XMPPClient connection, string strNode, string strItemName) { IQ pubsub = new IQ(); pubsub.Type = IQType.get.ToString(); pubsub.From = connection.JID; pubsub.To = new JID(string.Format("pubsub.{0}", connection.Domain)); string strXML = RequestItemXML.Replace("#NODE#", strNode); strXML = strXML.Replace("#ITEM#", strItemName); pubsub.InnerXML = strXML; IQ IQResponse = connection.SendRecieveIQ(pubsub, 15000); if (IQResponse.Type == IQType.error.ToString()) { return(null); } return(IQResponse); }
/// <summary> /// Retracts an item on the pubsub node. This client must be the owner /// </summary> /// <param name="strNode"></param> /// <param name="strItem"></param> /// <param name="nTimeoutMs"></param> /// <returns></returns> public static bool RetractItem(XMPPClient connection, string strNode, string strItem) { IQ pubsub = new IQ(); pubsub.Type = IQType.set.ToString(); pubsub.From = connection.JID; pubsub.To = new JID(string.Format("pubsub.{0}", connection.Domain)); string strXML = RetractNodeXML.Replace("#NODE#", strNode); strXML = strXML.Replace("#ITEM#", strItem); pubsub.InnerXML = strXML; IQ IQResponse = connection.SendRecieveIQ(pubsub, 10000); if (IQResponse.Type == IQType.error.ToString()) { return(false); } return(true); }
/// <summary> /// Checks to see if a given node exists /// </summary> /// <param name="connection"></param> /// <param name="strNode"></param> /// <returns></returns> public static bool NodeExists(XMPPClient connection, string strNode) { string strXML = QueryNodeXML.Replace("#NODE#", strNode); IQ IQRequest = new IQ(); IQRequest.From = connection.JID; IQRequest.To = string.Format("pubsub.{0}", connection.Domain); IQRequest.InnerXML = strXML; IQ IQResponse = connection.SendRecieveIQ(IQRequest, 10000); if (IQResponse == null) { return(false); } if (IQResponse.Type == IQType.error.ToString()) // && (IQResponse.Error.Code >= 0)) { return(false); } return(true); }
public static PubSubItem[] GetNodeItems(XMPPClient connection, string strNode, out string strNodeJID) { strNodeJID = ""; List <PubSubItem> returnnodes = new List <PubSubItem>(); PubSubIQ IQRequest = new PubSubIQ(); IQRequest.Type = IQType.get.ToString(); IQRequest.From = connection.JID; IQRequest.To = string.Format("pubsub.{0}", connection.Domain); IQRequest.PubSub = new PubSub(); IQRequest.PubSub.Items = new PubSubItems(); IQRequest.PubSub.Items.Node = strNode; IQ IQResponse = connection.SendRecieveIQ(IQRequest, 30000, SerializationMethod.XMLSerializeObject); if (IQResponse.Type == IQType.error.ToString()) { return(returnnodes.ToArray()); } if (IQResponse is PubSubIQ) { PubSubIQ psiq = IQResponse as PubSubIQ; if ((psiq.PubSub != null) && (psiq.PubSub.Items != null)) { strNodeJID = psiq.PubSub.Items.Node; if (psiq.PubSub.Items.Items != null) { foreach (PubSubItem item in psiq.PubSub.Items.Items) { returnnodes.Add(item); } } } } return(returnnodes.ToArray()); }
public static item[] GetSubNodeItems(XMPPClient connection, string strNode) { List <item> SubNodeList = new List <item>(); ServiceDiscoveryIQ IQRequest = new ServiceDiscoveryIQ(); IQRequest.ServiceDiscoveryItemQuery = new ServiceDiscoveryItemQuery(); IQRequest.From = connection.JID; IQRequest.To = string.Format("pubsub.{0}", connection.Domain); IQRequest.Type = IQType.get.ToString(); IQRequest.ServiceDiscoveryItemQuery.Node = strNode; IQ IQResponse = connection.SendRecieveIQ(IQRequest, 10000, SerializationMethod.XMLSerializeObject); if (IQResponse == null) { return(null); } if (IQResponse.Type == IQType.error.ToString()) { return(SubNodeList.ToArray()); } if (IQResponse is ServiceDiscoveryIQ) { ServiceDiscoveryIQ sdiq = IQResponse as ServiceDiscoveryIQ; if ((sdiq.ServiceDiscoveryItemQuery != null) && (sdiq.ServiceDiscoveryItemQuery.Items != null)) { foreach (item it in sdiq.ServiceDiscoveryItemQuery.Items) { SubNodeList.Add(it); } } } return(SubNodeList.ToArray()); }
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; }
public SendRecvIQLogic(XMPPClient client, IQ iq) : base(client) { SendIQ = iq; }
public virtual bool NewIQ(IQ iq) { return(false); }
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); } //else if (((XElement)elem.FirstNode).Name == "{urn:ietf:params:xml:ns:xmpp-bind}bind") //{ // BindIQ query = Utility.ParseObjectFromXMLString(strXML, typeof(BindIQ)) as BindIQ; // 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 }
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)); }