public void QueryServiceItems() { IQItemRequest = new ServiceDiscoveryIQ(); IQItemRequest.ServiceDiscoveryItemQuery = new ServiceDiscoveryItemQuery(); IQItemRequest.From = XMPPClient.JID; IQItemRequest.To = XMPPClient.Domain; IQItemRequest.Type = IQType.get.ToString(); XMPPClient.SendObject(IQItemRequest); }
// Look for subscribe message to subscribe to presence public override bool NewIQ(IQ iq) { //// XEP-0030 ///<iq type='get' from='[email protected]/orchard' to='plays.shakespeare.lit' id='info1'> /// <query xmlns='http://jabber.org/protocol/disco#info'/> ///</iq> if ((iq is ServiceDiscoveryIQ) && (iq.Type == IQType.get.ToString())) { ServiceDiscoveryIQ response = new ServiceDiscoveryIQ(); response.To = iq.From; response.From = XMPPClient.JID; response.ID = iq.ID; response.Type = IQType.result.ToString(); response.ServiceDiscoveryInfoQuery = new ServiceDiscoveryInfoQuery(); response.ServiceDiscoveryInfoQuery.Features = XMPPClient.OurServiceDiscoveryFeatureList.ToArray(); XMPPClient.SendObject(response); return(true); } else if ((IQInfoRequest != null) && (IQInfoRequest.ID == iq.ID)) { if (iq is ServiceDiscoveryIQ) { ServiceDiscoveryIQ response = iq as ServiceDiscoveryIQ; if ((response.ServiceDiscoveryInfoQuery != null) && (response.ServiceDiscoveryInfoQuery.Features != null) && (response.ServiceDiscoveryInfoQuery.Features.Length > 0)) { XMPPClient.ServerServiceDiscoveryFeatureList.Features.Clear(); XMPPClient.ServerServiceDiscoveryFeatureList.Features.AddRange(response.ServiceDiscoveryInfoQuery.Features); } if ((response.ServiceDiscoveryInfoQuery != null) && (response.ServiceDiscoveryInfoQuery.Identities != null) && (response.ServiceDiscoveryInfoQuery.Identities.Length > 0)) { } } return(true); } else if ((IQItemRequest != null) && (IQItemRequest.ID == iq.ID)) { if (iq is ServiceDiscoveryIQ) { ServiceDiscoveryIQ response = iq as ServiceDiscoveryIQ; if ((response.ServiceDiscoveryItemQuery != null) && (response.ServiceDiscoveryItemQuery.Items != null) && (response.ServiceDiscoveryItemQuery.Items.Length > 0)) { XMPPClient.ServerServiceDiscoveryFeatureList.Items.AddRange(response.ServiceDiscoveryItemQuery.Items); System.Threading.ThreadPool.QueueUserWorkItem(QueryItemsForProxy); } } return(true); } return(base.NewIQ(iq)); }
public static string[] GetSubNodes(XMPPClient connection, string strNode) { List <string> SubNodeList = new List <string>(); string strXML = FetchChildNodes.Replace("#NODE#", strNode); 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.Node); } } } //var nodes = IQResponse.InitalXMLElement.Descendants("{http://jabber.org/protocol/disco#items}item"); //foreach (XElement elem in nodes) //{ // XAttribute attrnode = elem.Attribute("node"); // if (attrnode != null) // SubNodeList.Add(attrnode.Value); //} return(SubNodeList.ToArray()); }
void QueryItemType(item item) { if (item.ItemType == ItemType.NotQueried) { ServiceDiscoveryIQ iqqueryproxy = new ServiceDiscoveryIQ(); iqqueryproxy.From = XMPPClient.JID; iqqueryproxy.To = item.JID; iqqueryproxy.ServiceDiscoveryInfoQuery = new ServiceDiscoveryInfoQuery(); iqqueryproxy.Type = IQType.get.ToString(); IQ iqret = XMPPClient.SendRecieveIQ(iqqueryproxy, 15000, SerializationMethod.XMLSerializeObject); if ((iqret != null) && (iqret is ServiceDiscoveryIQ)) { ServiceDiscoveryIQ response = iqret as ServiceDiscoveryIQ; if ((response.ServiceDiscoveryInfoQuery != null) && (response.ServiceDiscoveryInfoQuery.Identities != null) && (response.ServiceDiscoveryInfoQuery.Identities.Length > 0)) { if ((response.ServiceDiscoveryInfoQuery.Identities[0].Category == "proxy") && (response.ServiceDiscoveryInfoQuery.Identities[0].Type == "bytestreams")) { item.ItemType = ItemType.SOCKS5ByteStream; return; } if (response.ServiceDiscoveryInfoQuery.Identities[0].Category == "pubsub") { item.ItemType = ItemType.PubSub; return; } if (response.ServiceDiscoveryInfoQuery.Identities[0].Category == "directory") { item.ItemType = ItemType.Directory; return; } if (response.ServiceDiscoveryInfoQuery.Identities[0].Category == "conference") { item.ItemType = ItemType.Conference; return; } } } item.ItemType = ItemType.Unknown; } }
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 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 }