public GenericIQLogic(XMPPClient client) : base(client) { BindIQ = new IQ(); BindIQ.Type = IQType.set.ToString(); BindIQ.To = null; BindIQ.From = null; }
public override bool NewIQ(IQ iq) { if (ListSentIQs.Contains(iq.ID) == true) { ListSentIQs.Remove(iq.ID); return true; } return base.NewIQ(iq); }
// 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 override bool NewIQ(IQ iq) { try { if ( (BindIQ != null) && (iq.ID == BindIQ.ID)) { /// Extract our jid incase it changed /// <iq type="result" id="bind_1" to="ninethumbs.com/7b5005e1"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>[email protected]/hypnotoad</jid></bind></iq> /// if (iq.Type == IQType.result.ToString()) { /// bound, now do toher things /// XElement elembind = XElement.Parse(iq.InnerXML); XElement nodejid = elembind.FirstNode as XElement; if ((nodejid != null) && (nodejid.Name == "{urn:ietf:params:xml:ns:xmpp-bind}jid")) { XMPPClient.JID = nodejid.Value; } XMPPClient.XMPPState = XMPPState.Bound; } return true; } else if ((sessioniq != null) && (iq.ID == sessioniq.ID)) { XMPPClient.XMPPState = XMPPState.Session; return true; } if ((iq.InnerXML != null) && (iq.InnerXML.Length > 0)) { XElement elem = XElement.Parse(iq.InnerXML); if (elem.Name == "{urn:xmpp:ping}ping") { iq.Type = IQType.result.ToString(); iq.To = iq.From; iq.From = XMPPClient.JID.BareJID; iq.InnerXML = ""; XMPPClient.SendXMPP(iq); } } } catch (Exception) { } return false; }
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> /// 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); }
/// <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); }
protected virtual bool OnIQ(IQ iq) { bool bHandled = false; Logic[] LogicList = null; List <Logic> RemoveList = new List <Logic>(); lock (LogicLock) { LogicList = ActiveServices.ToArray(); } foreach (Logic log in LogicList) { bHandled = log.NewIQ(iq); if (log.IsCompleted == true) { RemoveList.Add(log); } if (bHandled == true) { break; } } lock (LogicLock) { foreach (Logic log in RemoveList) { if (ActiveServices.Contains(log) == true) { ActiveServices.Remove(log); } } } return(bHandled); }
public static string[] GetSubNodes(XMPPClient connection, string strNode) { List <string> SubNodeList = new List <string>(); string strXML = FetchChildNodes.Replace("#NODE#", strNode); IQ IQRequest = new IQ(); IQRequest.From = connection.JID; IQRequest.Type = IQType.get.ToString(); IQRequest.To = string.Format("pubsub.{0}", connection.Domain); IQRequest.InnerXML = strXML; IQ IQResponse = connection.SendRecieveIQ(IQRequest, 10000); if (IQResponse == null) { return(null); } if (IQResponse.Type == IQType.error.ToString()) { return(SubNodeList.ToArray()); } 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()); }
public static void CreateNode(XMPPClient connection, string strNode, string strParentNode, PubSubConfigForm nodeform) { 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 = CreateNodeXML.Replace("#NODE#", strNode); /// Get inner xml /// string strForm = nodeform.BuildAskingForm(nodeform); strXML = strXML.Replace("#x#", strForm); pubsub.InnerXML = strXML; IQ IQResponse = connection.SendRecieveIQ(pubsub, 10000); if (IQResponse == null) return; if (IQResponse.Type == IQType.error.ToString()) { return; } }
public override bool NewIQ(IQ iq) { if (iq is StreamInitIQ) { StreamInitIQ siiq = iq as StreamInitIQ; if (iq.Type == IQType.result.ToString()) { /// May be a response to our pending request to send /// StreamInitIQ initalrequest = null; if (FileSendRequests.ContainsKey(iq.ID) == true) { initalrequest = FileSendRequests[iq.ID]; FileSendRequests.Remove(iq.ID); } if (initalrequest != null) { //if (siiq.StreamOptions != StreamOptions.ibb) //{ // /// Tell the host we failed to send the file because we only support ibb // return true; //} /// Looks like they agree, start an ibb file transfer logic to perform the transfer /// if ((siiq.StreamOptions & StreamOptions.bytestreams) == StreamOptions.bytestreams) initalrequest.FileTransferObject.FileTransferType = FileTransferType.ByteStreams; else if ((siiq.StreamOptions & StreamOptions.ibb) == StreamOptions.ibb) initalrequest.FileTransferObject.FileTransferType = FileTransferType.IBB; XMPPClient.FileTransferManager.StartNewReceiveStream(initalrequest.FileTransferObject); } } else if (iq.Type == IQType.error.ToString()) { /// May be a response to our pending request to send /// StreamInitIQ initalrequest = null; if (FileSendRequests.ContainsKey(iq.ID) == true) { initalrequest = FileSendRequests[iq.ID]; FileSendRequests.Remove(iq.ID); } if (initalrequest != null) { XMPPClient.FileTransferManager.GotStreamErrorResponse(initalrequest.FileTransferObject, iq); } } //else if (siiq.StreamInitIQType == StreamInitIQType.Offer) else if (iq.Type == IQType.set.ToString()) { /// They want to send a file to us? /// Ask the user if it's OK, and if it is, start an ibb to receive it and send ok /// if ((siiq.sid == null) || (siiq.sid.Length <= 0) ) { IQ iqresponse = new StreamInitIQ(StreamInitIQType.Result); iqresponse.ID = siiq.ID; iqresponse.Type = IQType.error.ToString(); iqresponse.To = iq.From; iqresponse.From = XMPPClient.JID; iqresponse.Error = new Error(ErrorType.invalidid); XMPPClient.SendXMPP(iqresponse); return true; } if ((siiq.filename == null) || (siiq.filename.Length <= 0)) { IQ iqresponse = new StreamInitIQ(StreamInitIQType.Result); iqresponse.ID = siiq.ID; iqresponse.Type = IQType.error.ToString(); iqresponse.To = iq.From; iqresponse.From = XMPPClient.JID; iqresponse.Error = new Error(ErrorType.notacceptable); XMPPClient.SendXMPP(iqresponse); return true; } /// Can only do bytes streams or inband byte streams if ( ((siiq.StreamOptions & StreamOptions.ibb) != StreamOptions.ibb) && ((siiq.StreamOptions & StreamOptions.bytestreams) != StreamOptions.bytestreams)) { IQ iqresponse = new StreamInitIQ(StreamInitIQType.Result); iqresponse.ID = siiq.ID; iqresponse.Type = IQType.error.ToString(); iqresponse.To = iq.From; iqresponse.From = XMPPClient.JID; iqresponse.Error = new Error(ErrorType.notacceptable); XMPPClient.SendXMPP(iqresponse); return true; } FileTransfer newreq = new FileTransfer(siiq.filename, siiq.filesize, siiq.From); if ((siiq.StreamOptions & StreamOptions.bytestreams) == StreamOptions.bytestreams) newreq.FileTransferType = FileTransferType.ByteStreams; else if ((siiq.StreamOptions & StreamOptions.ibb) == StreamOptions.ibb) newreq.FileTransferType = FileTransferType.IBB; newreq.sid = siiq.sid; FileDownloadRequests.Add(siiq.sid, siiq); XMPPClient.FileTransferManager.NewIncomingFileRequest(newreq); } return true; } return false; }
internal void StartSession() { sessioniq = new IQ(); sessioniq.InnerXML = "<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>"; sessioniq.From = null; sessioniq.To = null; sessioniq.Type = IQType.set.ToString(); XMPPClient.SendXMPP(sessioniq); }
public override bool NewIQ(IQ iq) { if (this.IsCompleted == true) // We've been cancelled return false; if (FileTransfer.FileTransferDirection == FileTransferDirection.Send) { if ( (IQStart != null) && (iq.ID == IQStart.ID) ) { if (iq.Type == IQType.error.ToString()) { IsCompleted = true; if (iq.Error != null) FileTransfer.Error = iq.Error.ErrorDescription; FileTransfer.FileTransferState = FileTransferState.Error; XMPPClient.FileTransferManager.FinishActiveFileTransfer(FileTransfer); } else if (iq is ByteStreamQueryIQ) { ByteStreamQueryIQ bsiq = iq as ByteStreamQueryIQ; if (bsiq.Type == IQType.result.ToString()) { System.Threading.ThreadPool.QueueUserWorkItem(new Threading.WaitCallback(SendFileThread), bsiq); } else if (bsiq.Type == IQType.error.ToString()) { IsCompleted = true; if (iq.Error != null) FileTransfer.Error = bsiq.Error.ErrorDescription; FileTransfer.FileTransferState = FileTransferState.Error; } } return true; } if ((IQActivate != null) && (iq.ID == IQActivate.ID)) { EventActivate.Set(); return true; } } else { if (iq is ByteStreamQueryIQ) { ByteStreamQueryIQ bsiq = iq as ByteStreamQueryIQ; if ( (bsiq.ByteStreamQuery != null) && (bsiq.ByteStreamQuery.Hosts != null) && (bsiq.ByteStreamQuery.Hosts.Length > 0) ) { System.Threading.ThreadPool.QueueUserWorkItem(new Threading.WaitCallback(DownloadThread), bsiq); } else { ByteStreamQueryIQ response = new ByteStreamQueryIQ(); response.ByteStreamQuery = bsiq.ByteStreamQuery; response.From = XMPPClient.JID; response.To = bsiq.From; response.ID = bsiq.ID; response.Type = IQType.error.ToString(); response.Error = new Error(ErrorType.notacceptable); XMPPClient.SendXMPP(response); } /// See qh /// return true; } } return false; }
public void DownloadAvatarJabberIQMethod(JID jidfor) { IQ iq = new IQ(); iq.From = XMPPClient.JID; iq.To = jidfor; iq.Type = IQType.get.ToString(); iq.InnerXML = "<query xmlns='jabber:iq:avatar' />"; //iq.InnerXML = "<query xmlns='storage:client:avatar' />"; XMPPClient.SendXMPP(iq); }
public void RequestOurVCARD() { iqGetOurVCARD = new IQ(); iqGetOurVCARD.From = null; iqGetOurVCARD.To = XMPPClient.JID.BareJID; iqGetOurVCARD.Type = IQType.get.ToString(); iqGetOurVCARD.InnerXML = "<vCard xmlns='vcard-temp' />"; XMPPClient.SendXMPP(iqGetOurVCARD); }
public SendRecvIQLogic(XMPPClient client, IQ iq) : base(client) { SendIQ = iq; }
// 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)); }
/// <summary> /// Purges the items in a node /// </summary> /// <param name="strNode"></param> /// <returns></returns> public static bool UnsubscribeNode(XMPPClient connection, string strNode, string strJID, string strSID, bool bWaitForResponse) { IQ pubsub = new IQ(); pubsub.Type = IQType.set.ToString(); pubsub.From = connection.JID; pubsub.To = new JID(string.Format("pubsub.{0}", connection.Domain)); pubsub.InnerXML = UnsubscribeNodeXML.Replace("#NODE#", strNode).Replace("#JID#", strJID).Replace("#SID#", strSID); if (bWaitForResponse == false) { connection.SendXMPP(pubsub); return true; } IQ IQResponse = connection.SendRecieveIQ(pubsub, 10000); if (IQResponse.Type == IQType.error.ToString()) { return false; } return true; }
public void UdpateVCARD(vcard vcard) { IQ iq = new IQ(); iq.From = XMPPClient.JID; iq.To = null; iq.Type = IQType.set.ToString(); iq.InnerXML = Utility.GetXMLStringFromObject(vcard); XMPPClient.SendXMPP(iq); }
/// <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> /// Purges the items in a node /// </summary> /// <param name="strNode"></param> /// <returns></returns> public static string SubscribeNode(XMPPClient connection, string strNode, string strJID, bool bWaitForResponse) { IQ pubsub = new IQ(); pubsub.Type = IQType.set.ToString(); pubsub.From = connection.JID; pubsub.To = new JID(string.Format("pubsub.{0}", connection.Domain)); pubsub.InnerXML = SubscribeNodeXML.Replace("#NODE#", strNode).Replace("#JID#", strJID); if (bWaitForResponse == false) { connection.SendXMPP(pubsub); return null; } IQ IQResponse = connection.SendRecieveIQ(pubsub, 10000); if ( (IQResponse == null) || (IQResponse.Type == IQType.error.ToString()) ) { return null; } ///<iq type="result" id="9933bb36-7685-460f-8d7f-e9e5ad80f780" from="pubsub.ninethumbs.com" to="[email protected]/9047e898-aed2-4f58-b3e2-a5f671758544"> /// <pubsub xmlns="http://jabber.org/protocol/pubsub"> /// <subscription node="GroceryList" jid="[email protected]/9047e898-aed2-4f58-b3e2-a5f671758544" subid="tU98QlKDYuEhTiKO443Vs2AWi2Y07i4Pf2l1wc8W" subscription="subscribed"> /// <subscribe-options/></subscription> /// </pubsub> /// </iq> /// if (IQResponse is PubSubIQ) { PubSubIQ psiq = IQResponse as PubSubIQ; if ( (psiq.PubSub != null) && (psiq.PubSub.Subscription != null) ) return psiq.PubSub.Subscription.subid; } return null; }
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> /// 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 string[] GetSubNodes(XMPPClient connection, string strNode) { List<string> SubNodeList = new List<string>(); string strXML = FetchChildNodes.Replace("#NODE#", strNode); IQ IQRequest = new IQ(); IQRequest.From = connection.JID; IQRequest.Type = IQType.get.ToString(); IQRequest.To = string.Format("pubsub.{0}", connection.Domain); IQRequest.InnerXML = strXML; IQ IQResponse = connection.SendRecieveIQ(IQRequest, 10000); if (IQResponse == null) return null; if (IQResponse.Type == IQType.error.ToString()) { return SubNodeList.ToArray(); } 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(); }
public IQ SendRecieveIQ(IQ iq, int nTimeoutMS) { return(SendRecieveIQ(iq, nTimeoutMS, SerializationMethod.MessageXMLProperty)); }
public override bool NewIQ(IQ iq) { try { if (iq.ID == SendIQ.ID) { RecvIQ = iq; IsCompleted = true; Success = true; GotIQEvent.Set(); return true; } } catch (Exception) { } return false; }
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)); }
public static string[] GetNodeItems(XMPPClient connection, string strNode, out string strNodeJID) { strNodeJID = ""; List<string> returnnodes = new List<string>(); IQ IQRequest = new IQ(); IQRequest.Type = IQType.get.ToString(); IQRequest.From = connection.JID; IQRequest.To = string.Format("pubsub.{0}", connection.Domain); IQRequest.InnerXML = GetNodeItemsXML.Replace("#NODE#", strNode);; IQ IQResponse = connection.SendRecieveIQ(IQRequest, 30000); if (IQResponse.Type == IQType.error.ToString()) { return returnnodes.ToArray(); } var nodes = IQResponse.InitalXMLElement.Descendants("{http://jabber.org/protocol/pubsub}items"); foreach (XElement elem in nodes) { strNodeJID = elem.Attribute("node").Value; } nodes = IQResponse.InitalXMLElement.Descendants("{http://jabber.org/protocol/pubsub}item"); foreach (XElement elem in nodes) { returnnodes.Add(elem.Value); } return returnnodes.ToArray(); }
public virtual bool NewIQ(IQ iq) { return false; }
public override bool NewIQ(IQ iq) { if (this.IsCompleted == true) // We've been cancelled return false; if (FileTransfer.FileTransferDirection == FileTransferDirection.Send) { if (iq.ID == InitialIQ.ID) { if (iq.Type == IQType.error.ToString()) { if (iq.Error != null) FileTransfer.Error = iq.Error.ErrorDescription; FileTransfer.FileTransferState = FileTransferState.Error; IsCompleted = true; /// Remove this guy XMPPClient.FileTransferManager.FinishActiveFileTransfer(FileTransfer); return true; } else if (iq.Type == IQType.result.ToString()) { // Send the next chunk SendNextFileIQ(); } return true; } else if ((LastFileDataIQSent != null) && (iq.ID == LastFileDataIQSent.ID)) { if (iq.Type == IQType.error.ToString()) { /// TODO.. notify the user there was a failure transferring blocks /// if (iq.Error != null) FileTransfer.Error = iq.Error.ErrorDescription; FileTransfer.FileTransferState = FileTransferState.Error; XMPPClient.FileTransferManager.FinishActiveFileTransfer(FileTransfer); IsCompleted = true; return true; } else if (iq.Type == IQType.result.ToString()) { // Send the next chunk SendNextFileIQ(); } } } else { if (iq.InitalXMLElement != null) { XElement elem = iq.InitalXMLElement.FirstNode as XElement; if ((elem != null) && (elem.Name == "{http://jabber.org/protocol/ibb}open")) { string strStreamId = null; if (elem.Attribute("sid") != null) strStreamId = elem.Attribute("sid").Value; if ((strStreamId == null) || (strStreamId != this.FileTransfer.sid)) return false; FileBuffer.GetAllSamples(); /// SEnd ack to open /// IQ iqresponse = new IQ(); iqresponse.ID = iq.ID; iqresponse.From = XMPPClient.JID; iqresponse.To = FileTransfer.RemoteJID; iqresponse.Type = IQType.result.ToString(); XMPPClient.SendXMPP(iqresponse); return true; } if ((elem != null) && (elem.Name == "{http://jabber.org/protocol/ibb}data")) { string strStreamId = null; if (elem.Attribute("sid") != null) strStreamId = elem.Attribute("sid").Value; if ((strStreamId == null) || (strStreamId != FileTransfer.sid)) return false; byte[] bData = Convert.FromBase64String(elem.Value); FileTransfer.BytesRemaining -= bData.Length; FileBuffer.AppendData(bData); /// SEnd ack /// IQ iqresponse = new IQ(); iqresponse.ID = iq.ID; iqresponse.From = XMPPClient.JID; iqresponse.To = FileTransfer.RemoteJID; iqresponse.Type = IQType.result.ToString(); XMPPClient.SendXMPP(iqresponse); nActions++; if (FileTransfer.BytesRemaining <= 0) { FileTransfer.Bytes = FileBuffer.GetAllSamples(); FileTransfer.FileTransferState = FileTransferState.Done; IsCompleted = true; XMPPClient.FileTransferManager.FinishActiveFileTransfer(FileTransfer); } return true; } } } 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); } } #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 void Start() { if (FileTransfer.FileTransferDirection == FileTransferDirection.Send) { InitialIQ = new IQ(); InitialIQ.From = XMPPClient.JID; InitialIQ.To = FileTransfer.RemoteJID; InitialIQ.Type = IQType.set.ToString(); InitialIQ.InnerXML = string.Format("<open xmlns='http://jabber.org/protocol/ibb' block-size='{1}' sid='{0}' stanza='iq' />", FileTransfer.sid, nBlockSize); XMPPClient.SendXMPP(InitialIQ); } else { } base.Start(); }
// 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); }
void SendNextFileIQ() { /// For debugging, so we can see our progress //System.Threading.Thread.Sleep(10); if (LastFileDataIQSent == null) { FileTransfer.BytesRemaining = FileTransfer.BytesTotal; FileBuffer.AppendData(FileTransfer.Bytes); nSequence = 0; } if (FileBuffer.Size <= 0) { FileTransfer.FileTransferState = FileTransferState.Done; XMPPClient.FileTransferManager.FinishActiveFileTransfer(FileTransfer); this.IsCompleted = true; return; } int nChunkSize = (FileBuffer.Size > nBlockSize) ? nBlockSize : FileBuffer.Size; FileTransfer.BytesRemaining -= nChunkSize; byte[] bNext = FileBuffer.GetNSamples(nChunkSize); LastFileDataIQSent = new IQ(); LastFileDataIQSent.From = XMPPClient.JID; LastFileDataIQSent.To = FileTransfer.RemoteJID; LastFileDataIQSent.Type = IQType.set.ToString(); string strBase64 = Convert.ToBase64String(bNext); LastFileDataIQSent.InnerXML = string.Format("<data xmlns='http://jabber.org/protocol/ibb' seq='{0}' sid='{1}' >{2}</data>", nSequence++, FileTransfer.sid, strBase64); XMPPClient.SendXMPP(LastFileDataIQSent); nActions++; }
public void RequestVCARD(JID jidfor) { IQ iq = new IQ(); iq.From = XMPPClient.JID; iq.To = jidfor.BareJID; iq.Type = IQType.get.ToString(); iq.InnerXML = "<vCard xmlns='vcard-temp' />"; XMPPClient.SendXMPP(iq); }
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 static bool DeleteNode(XMPPClient connection, string strNode) { string strXML = DeleteNodeXML.Replace("#NODE#", strNode); IQ IQRequest = new IQ(); IQRequest.Type = IQType.set.ToString(); IQRequest.From = connection.JID; IQRequest.To = string.Format("pubsub.{0}", connection.Domain); IQRequest.InnerXML = strXML; IQ IQResponse = connection.SendRecieveIQ(IQRequest, 10000); if (IQResponse.Type == IQType.error.ToString()) { return false; } return true; }
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 virtual bool NewIQ(IQ iq) { return(false); }