void Bind() { BindIQ.InnerXML = BindXML.Replace("##RESOURCE##", XMPPClient.JID.Resource); XMPPClient.XMPPState = XMPPState.Binding; XMPPClient.SendXMPP(BindIQ); }
/// <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 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 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); }
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 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 bool SendReceive(int nTimeoutMs) { TimeoutMs = nTimeoutMs; if (SerializationMethod == XMPP.SerializationMethod.MessageXMLProperty) { XMPPClient.SendXMPP(SendIQ); } else { XMPPClient.SendObject(SendIQ); } Success = GotIQEvent.WaitOne(TimeoutMs); return(Success); }
public override bool NewIQ(IQ iq) { try { if (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); } 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); }
/// <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 void SendChatMessage(TextMessage txtmsg) { txtmsg.Sent = true; ChatMessage msg = new ChatMessage(null); msg.From = txtmsg.From; msg.To = txtmsg.To; msg.Type = "chat"; msg.Body = txtmsg.Message; //msg.InnerXML = string.Format(@"<body>{0}</body>", txtmsg.Message); /// Find the roster guy for this message and add it to their conversation /// RosterItem item = XMPPClient.FindRosterItem(txtmsg.To); if (item != null) { item.AddSendTextMessage(txtmsg); // Notify XMPPClient that a new conversation item has been added XMPPClient.FireNewConversationItem(item, false, txtmsg); } XMPPClient.SendXMPP(msg); }
/// <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; }
/// <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 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); }