private void OnPubSubCreateNode(object sender, IqEventArgs e) { m_bReady = false; var error = e.Iq.Element <Error>(); if (e.Iq.Type == Matrix.Xmpp.IqType.result) { Debug.WriteLine("Node [" + m_node + "] is created!"); m_bReady = true; } else if (e.Iq.Type == Matrix.Xmpp.IqType.error) { if (error != null) { if (error.Condition == Matrix.Xmpp.Base.ErrorCondition.Conflict) { Debug.WriteLine("Node [" + m_node + "] is already exist!"); m_bReady = true; } else { Debug.WriteLine("creation of node [{0}] failed!\r\nError Condition: {1}\r\nError Type: {2}", m_node, error.Condition, error.Type); } } } if ((m_bReady) && (m_node != null)) { SensorCreateEventArgs sce = new SensorCreateEventArgs(m_bReady); OnSensorCreateEvent(sce); } }
void DiscoItemsResult(object sender, IqEventArgs e) { //<iq from="vm-debian" to="alex@vm-debian/MatriX" id="MX_4" type="result" xmlns="jabber:client"> // <query xmlns="http://jabber.org/protocol/disco#items"> // <item jid="conference.vm-debian" /> // <item jid="irc.vm-debian" /> // <item jid="pubsub.vm-debian" /> // <item jid="vjud.vm-debian" /> // </query> //</iq> var query = e.Iq.Element <Matrix.Xmpp.Disco.Items>(); if (query != null) { foreach (var itm in query.GetItems()) { // some servers have problems ifwe flood them weith too many packets here // the sleep is a hack to avpid this problems. //System.Threading.Thread.Sleep(200); //_dm.DiscoverInformation(itm.Jid, itm.Node); _dm.DiscoverInformation(itm.Jid, itm.Node, new EventHandler <IqEventArgs>(DiscoInfoResult)); } } }
void DiscoGroupsResult(object sender, IqEventArgs e) { var query = e.Iq.Element <Matrix.Xmpp.Disco.Items>(); if (query != null) { // int i = 0; int c = query.GetItems().Count(); string[] rooms = new string[c]; foreach (var itm in query.GetItems()) { rooms[i] = itm.Jid; i++; //_dm.DiscoverInformation(itm.Jid, itm.Node); //System.Threading.Thread.Sleep(200); //this.discoManager.DiscoverInformation(itm.Jid, itm.Node, new EventHandler<IqEventArgs>(DiscoInfoResult)); } if (OnListGroup != null) { this.OnListGroup(this, rooms); } } }
// Invoked just after the creation (or retrieving) the node. // If newly created or already exists, then subscribe (or other operations) can be carried out. // otherwise, no-op. private void OnPubSubCreateNode(object sender, IqEventArgs e) { m_bCreated = false; var error = e.Iq.Element <Error>(); if (e.Iq.Type == Matrix.Xmpp.IqType.result) { Debug.WriteLine("node is created!"); m_bCreated = true; } else if (e.Iq.Type == Matrix.Xmpp.IqType.error) { if (error != null) { if (error.Condition == Matrix.Xmpp.Base.ErrorCondition.Conflict) { Debug.WriteLine("Node is already exist!"); m_bCreated = true; } else { Debug.WriteLine("creation of node failed!\r\nError Condition: {0}\r\nError Type: {1}", error.Condition, error.Type); } } } }
internal ValidateStreamEventArgs(XmppClient Client, IqEventArgs e, string StreamId, int BlockSize) : base(e) { this.client = Client; this.streamId = StreamId; this.blockSize = BlockSize; }
private void UnblockPushHandler(object Sender, IqEventArgs e) { XmlElement E; string JID; bool Found = false; lock (this.blockList) { foreach (XmlNode N in e.Query.ChildNodes) { E = N as XmlElement; if (E != null && E.LocalName == "item") { Found = true; JID = XML.Attribute(E, "jid"); this.blockList.Remove(JID); } } if (!Found) { this.blockList.Clear(); } } }
private void RemovedHandler(object Sender, IqEventArgs e) { XmlElement E = e.Query; string NodeId = XML.Attribute(E, "id"); string SourceId = XML.Attribute(E, "src"); string Partition = XML.Attribute(E, "pt"); ThingReference Node; if (string.IsNullOrEmpty(NodeId) && string.IsNullOrEmpty(SourceId) && string.IsNullOrEmpty(Partition)) { Node = ThingReference.Empty; } else { Node = new ThingReference(NodeId, SourceId, Partition); } NodeEventArgs e2 = new NodeEventArgs(e, Node); NodeEventHandler h = this.Removed; if (h != null) { try { h(this, e2); } catch (Exception ex) { Log.Critical(ex); } } e.IqResult(string.Empty); }
private void VcardUpdateResponse(object sender, IqEventArgs e) { if (e.Iq.Type == Matrix.Xmpp.IqType.Result) { MessageBox.Show("The VCard was updated successful!!"); } }
private void CancelHandler(object Sender, IqEventArgs e) { SensorDataServerRequest Request; string Id = XML.Attribute(e.Query, "id"); string Key = e.From + " " + Id; lock (this.requests) { if (this.requests.TryGetValue(Key, out Request)) { this.requests.Remove(Key); } else { Request = null; } } if (Request != null && !Request.Started) { this.scheduler.Remove(Request.When); } e.IqResult(string.Empty); }
private void OpenHandler(object Sender, IqEventArgs e) { int BlockSize = XML.Attribute(e.Query, "block-size", 0); string StreamId = XML.Attribute(e.Query, "sid"); string Stanza = XML.Attribute(e.Query, "stanza", "iq"); if (Stanza != "message" && Stanza != "iq") { throw new BadRequestException("Invalid stanza type.", e.IQ); } if (BlockSize <= 0) { throw new BadRequestException("Invalid block size.", e.IQ); } if (BlockSize > this.maxBlockSize) { throw new ResourceConstraintException("Requested block size too large. Maximum acceptable is " + this.maxBlockSize.ToString(), e.IQ); } ValidateStreamEventHandler h = this.OnOpen; ValidateStreamEventArgs e2 = new ValidateStreamEventArgs(this.client, e, StreamId, BlockSize); if (h != null) { try { h(this, e2); } catch (Exception ex) { Log.Critical(ex); } } if (e2.DataCallback is null || e2.CloseCallback is null) { throw new NotAcceptableException("Stream not expected.", e.IQ); } this.AssertCacheCreated(); string Key = e.From + " " + StreamId; if (this.cache.ContainsKey(Key)) { throw new NotAcceptableException("Stream already open.", e.IQ); } IncomingStream Input = new IncomingStream(e2.DataCallback, e2.CloseCallback, e2.State, BlockSize); this.cache[Key] = Input; e.IqResult(string.Empty); }
private Task CloseHandler(object Sender, IqEventArgs e) { string StreamId = XML.Attribute(e.Query, "sid"); string Key = e.From + " " + StreamId; IncomingStream Input; OutgoingStream Output; lock (this.synchObject) { if (this.cache is null) { Input = null; } else if (this.cache.TryGetValue(Key, out Input)) { this.cache.Remove(Key); } else { Input = null; } } if (Input is null) { lock (this.output) { if (!this.output.TryGetValue(StreamId, out Output)) { throw new ItemNotFoundException("Stream not recognized.", e.Query); } this.output.Remove(StreamId); } Output.Abort(); Output.Dispose(); } else { if (Input.BlocksMissing) { Input.Closed(CloseReason.Aborted); } else { Input.Closed(CloseReason.Done); } Input.Dispose(); } e.IqResult(string.Empty); return(Task.CompletedTask); }
private void PublishResult(object sender, IqEventArgs e) { if (e.Iq.Type == Matrix.Xmpp.IqType.Result) { } else if (e.Iq.Type == Matrix.Xmpp.IqType.Error) { // handle error here. } }
private void DataHandler(object Sender, IqEventArgs e) { if (this.HandleIncomingData(e.Query, e.From)) { e.IqResult(string.Empty); } else { throw new ItemNotFoundException("Stream not recognized.", e.Query); } }
private void SubscribeResult(object sender, IqEventArgs e) { if (e.Iq.Type == Matrix.Xmpp.IqType.Result) { MessageBox.Show(String.Format("You are now subscribed to the node: {0}", e.State as string)); } else if (e.Iq.Type == Matrix.Xmpp.IqType.Error) { // handle error here. } }
private async void QueryVCardHandler(object Sender, IqEventArgs e) { try { e.IqResult(await this.GetVCardXml()); } catch (Exception ex) { e.IqError(ex); } }
private void RosterResponse(object sender, IqEventArgs e) { var iq = e.Iq; if (iq.Type == IqType.Result) { // process result here } else if (iq.Type == IqType.Error) { // process errors here } }
private void VcardResponse(object sender, IqEventArgs e) { if (e.Iq.Type == Matrix.Xmpp.IqType.result) { var vc = e.Iq.Query as Vcard; txtName.Text = vc.Fullname; txtNickname.Text = vc.Nickname; var email = vc.GetEmails().FirstOrDefault(m => m.IsInternet); if (email != null) txtEmail.Text = email.Address; } }
private void ForwardedTokenChallengeResponse(object Sender, IqResultEventArgs e2) { IqEventArgs e = (IqEventArgs)e2.State; if (e2.Ok) { e.IqResult(e2.FirstElement.OuterXml); } else { e.IqError(e2.ErrorElement.OuterXml); } }
private void OnPubSubDeleteNode(object sender, IqEventArgs e) { var pubsub = e.Iq.Element <Matrix.Xmpp.PubSub.PubSub>(); var error = e.Iq.Element <Error>(); if (e.Iq.Type == Matrix.Xmpp.IqType.result) { Debug.WriteLine("node [" + m_node + "] is deleted!"); } else if (e.Iq.Type == Matrix.Xmpp.IqType.error) { Debug.WriteLine("creation of node [{0}] failed!\r\nError Condition: {1}\r\nError Type: {2}", m_node, error.Condition, error.Type); } }
private void GetData(object Sender, IqEventArgs e) { string ContentId = XML.Attribute(e.Query, "cid"); string FileName = this.GetFileName(ContentId); if (!File.Exists(FileName)) { throw new ItemNotFoundException("Content not found.", e.Query); } string Xml = File.ReadAllText(FileName, Encoding.ASCII); e.IqResult(Xml); }
void DiscoPubSubNodesResult(object sender, IqEventArgs e) { var query = e.Iq.Element <Matrix.Xmpp.Disco.Items>(); if (query != null) { foreach (var item in query.GetItems()) { // this seems recursive? //Log.Info("ASDF " + item.Name + " " + item.Node + " " + item.Jid); DiscoPubSubNodes(item.Jid, item.Node); } } }
private void VcardResponse(object sender, IqEventArgs e) { if (e.Iq.Type == Matrix.Xmpp.IqType.Result) { var vc = e.Iq.Query as Vcard; txtName.Text = vc.Fullname; txtNickname.Text = vc.Nickname; var email = vc.GetEmails().FirstOrDefault(m => m.IsInternet); if (email != null) { txtEmail.Text = email.Address; } } }
void _xmppClient_OnIq(object sender, IqEventArgs e) { if (e.Iq.From != null && e.Iq.From.Bare == "search." + FrmLogin.Instance.HostName) { var query = e.Iq.Element <Matrix.Xmpp.Search.Search>(); foreach (var itm in query.GetItems()) { var newItem = new RosterListViewItem(itm.Nick ?? itm.Jid.Bare, 0, null) { Name = itm.Jid.Bare }; listSearchContracts.Items.Add(newItem); } } }
void DiscoItemsResult(object sender, IqEventArgs e) { var query = e.Iq.Element <Matrix.Xmpp.Disco.Items>(); if (query != null) { foreach (var itm in query.GetItems()) { //_dm.DiscoverInformation(itm.Jid, itm.Node); System.Threading.Thread.Sleep(200); Log.Info("Disco: " + itm.Jid); this.discoManager.DiscoverInformation(itm.Jid, itm.Node, new EventHandler <IqEventArgs>(DiscoInfoResult)); } } }
private void VcardResponse(object sender, IqEventArgs e) { if (e.Iq.Type == Matrix.Xmpp.IqType.Result) { var vc = e.Iq.Query as Vcard; UserName = vc.Fullname; if (!Util.ChatForms.ContainsKey(Group.Name)) { var roomJid = new Jid(Group.Name); var f = new FrmGroupChat(xmppClient, roomJid, UserName, listContacts); f.MdiParent = FrmParent.Instance; f.Show(); } } }
private void DeleteNodeResult(object sender, IqEventArgs e) { if (e.Iq.Type == Matrix.Xmpp.IqType.Result) { var pNode = e.State as DiscoNode; if (pNode != null) { MessageBox.Show(String.Format("node {0} was deleted!", pNode.Node)); pNode.Remove(); } } else if (e.Iq.Type == Matrix.Xmpp.IqType.Error) { // handle error here. } }
/// <summary> /// Sets parameters from a data form in a set of objects. /// </summary> /// <param name="e">IQ Event Arguments describing the request.</param> /// <param name="EditableObjects">Objects whose parameters will be set.</param> /// <param name="Form">Data Form.</param> /// <returns>Any errors encountered, or null if parameters was set properly.</returns> public static async Task <KeyValuePair <string, string>[]> SetEditableForm(IqEventArgs e, IEnumerable <object> EditableObjects, DataForm Form) { KeyValuePair <string, string>[] Result; foreach (Object EditableObject in EditableObjects) { Result = await SetEditableForm(e, EditableObject, Form); if (Result != null) { return(Result); } } return(null); }
private void CreateInstantNodeResult(object sender, IqEventArgs e) { if (e.Iq.Type == Matrix.Xmpp.IqType.Result) { var pubsub = e.Iq.Element<PubSub>(); if (pubsub != null) { if (pubsub.Create != null) MessageBox.Show(String.Format("node {0} was created!", pubsub.Create.Node)); } } else if (e.Iq.Type == Matrix.Xmpp.IqType.Error) { // handle error here. } }
void DiscoInfoResult(object sender, IqEventArgs e) { var query = e.Iq.Element <Matrix.Xmpp.Disco.Info>(); if (query != null) { foreach (var id in query.GetIdentities()) { if (id.Category == "pubsub") { Log.Info(e.Iq.From); DiscoPubSubNodes(e.Iq.From, null); } Log.Info("DiscoInfo " + id.Category); } } }
private async Task GetData(object Sender, IqEventArgs e) { string ContentId = XML.Attribute(e.Query, "cid"); string FileName = this.GetFileName(ContentId); if (!File.Exists(FileName)) { throw new ItemNotFoundException("Content not found.", e.Query); } using (FileStream f = File.OpenRead(FileName)) { StreamReader r = new StreamReader(f, Encoding.ASCII); string Xml = await r.ReadToEndAsync(); e.IqResult(Xml); } }
void DiscoInfoResult(object sender, IqEventArgs e) { var query = e.Iq.Element <Info>(); if (query != null) { foreach (var id in query.GetIdentities()) { if (id.Category == "pubsub") { cboService.Items.Add(e.Iq.From); var newnode = new DiscoNode(e.Iq.From, null, e.Iq.From); treeNodes.Nodes.Add(newnode); DiscoPubSubNodes(e.Iq.From, null, newnode); } } } }
private void BlockPushHandler(object Sender, IqEventArgs e) { XmlElement E; string JID; lock (this.blockList) { foreach (XmlNode N in e.Query.ChildNodes) { E = N as XmlElement; if (E != null && E.LocalName == "item") { JID = XML.Attribute(E, "jid"); this.blockList[JID] = true; } } } }
private void xmppClient_OnRegisterError(object sender, IqEventArgs e) { xmppClient.Close(); }
protected void OnSubscribe(object sender, IqEventArgs e) { var error = e.Iq.Element<Error>(); }
void _xmppClient_OnIq(object sender, IqEventArgs e) { if (e.Iq.From != null && e.Iq.From.Bare == "search." + FrmLogin.Instance.HostName) { var query = e.Iq.Element<Matrix.Xmpp.Search.Search>(); foreach (var itm in query.GetItems()) { var newItem = new RosterListViewItem(itm.Nick ?? itm.Jid.Bare, 0, null) { Name = itm.Jid.Bare }; listSearchContracts.Items.Add(newItem); } } }
private void OnPubSubCreateNode(object sender, IqEventArgs e) { m_bReady = false; var error = e.Iq.Element<Error>(); if (e.Iq.Type == Matrix.Xmpp.IqType.result) { Debug.WriteLine("Node [" + m_node + "] is created!"); m_bReady = true; } else if (e.Iq.Type == Matrix.Xmpp.IqType.error) { if (error != null) { if (error.Condition == Matrix.Xmpp.Base.ErrorCondition.Conflict) { Debug.WriteLine("Node [" + m_node + "] is already exist!"); m_bReady = true; } else { Debug.WriteLine("creation of node [{0}] failed!\r\nError Condition: {1}\r\nError Type: {2}", m_node, error.Condition, error.Type); } } } if ((m_bReady) && (m_node != null)) { SensorCreateEventArgs sce = new SensorCreateEventArgs(m_bReady); OnSensorCreateEvent(sce); } }
private void xmppClient_OnIq(object sender, IqEventArgs e) { DisplayEvent("OnIq"); if (e.Iq.Type == IqType.get && e.Iq.Query is Weather) { var weather = e.Iq.Query as Weather; string zip = weather.Zip; // here you should lookup the weather information for the given zip code in a database or webservice // we just return some random numbers var temp = new Random().Next(-10, 40); var humidity = new Random().Next(10, 90); var wiq = new WeatherIq { To = e.Iq.From, Type = IqType.result, Weather = new Weather {Temperature = temp, Humidity = humidity} }; // send the response xmppClient.Send(wiq); } }
void DiscoInfoResult(object sender, IqEventArgs e) { var query = e.Iq.Element<Info>(); if (query != null) { foreach (var id in query.GetIdentities()) { if (id.Category == "pubsub") { cboService.Items.Add(e.Iq.From); var newnode = new DiscoNode(e.Iq.From, null, e.Iq.From); treeNodes.Nodes.Add(newnode); DiscoPubSubNodes(e.Iq.From, null, newnode); } } } }
void DiscoItemsResult(object sender, IqEventArgs e) { //<iq from="vm-debian" to="alex@vm-debian/MatriX" id="MX_4" type="result" xmlns="jabber:client"> // <query xmlns="http://jabber.org/protocol/disco#items"> // <item jid="conference.vm-debian" /> // <item jid="irc.vm-debian" /> // <item jid="pubsub.vm-debian" /> // <item jid="vjud.vm-debian" /> // </query> //</iq> var query = e.Iq.Element<Matrix.Xmpp.Disco.Items>(); if (query != null) { foreach (var itm in query.GetItems()) { // some servers have problems ifwe flood them weith too many packets here // the sleep is a hack to avpid this problems. //System.Threading.Thread.Sleep(200); //_dm.DiscoverInformation(itm.Jid, itm.Node); _dm.DiscoverInformation(itm.Jid, itm.Node, new EventHandler<IqEventArgs>(DiscoInfoResult)); } } }
void DiscoPubSubNodesResult(object sender, IqEventArgs e) { /* <iq from="pubsub.vm-debian" type="result" to="alex@vm-debian/Alex-TP" id="aadda" > <query xmlns="http://jabber.org/protocol/disco#items" node="/home" > <item node="/home/vm-debian" name="vm-debian" jid="pubsub.vm-debian" /> </query> </iq> */ var query = e.Iq.Element<Matrix.Xmpp.Disco.Items>(); if (query != null) { foreach (var item in query.GetItems()) { var newnode = new DiscoNode(item.Name, item.Node, item.Jid) {ContextMenuStrip = contextMenuStripNodes}; ((TreeNode) e.State).Nodes.Add(newnode); DiscoPubSubNodes(item.Jid, item.Node, newnode); } } }
private void xmppClient_OnIq(object sender, IqEventArgs e) { DisplayEvent("OnIq"); }
void client_OnIq(object sender, IqEventArgs e) { Console.WriteLine("{0} iq:{1}", m_Name, e.Iq); }
private void WeatherInfoResponse(object sender, IqEventArgs e) { var iq = e.Iq; if (iq.Type == IqType.result) { var weather = iq.Element<Weather>(); if (weather != null) { var zip = e.State as string; MessageBox.Show(String.Format("weather info for zip code: {0}\r\n\r\nHumidity: {1}\r\nTemperature: {2}", zip, weather.Humidity, weather.Temperature)); } } else if (iq.Type == IqType.error) { // process errors here } }
private void OnRegisterError(object sender, IqEventArgs iqEventArgs) { }
void xmppClient_OnIq(object sender, IqEventArgs e) { DisplayEvent("OnIq"); DisplayEvent(String.Format(" ==> From:{0}", e.Iq.From)); }
private void OnPubSubDeleteNode(object sender, IqEventArgs e) { var pubsub = e.Iq.Element<Matrix.Xmpp.PubSub.PubSub>(); var error = e.Iq.Element<Error>(); if (e.Iq.Type == Matrix.Xmpp.IqType.result) { Debug.WriteLine("node [" + m_node + "] is deleted!"); } else if (e.Iq.Type == Matrix.Xmpp.IqType.error) { Debug.WriteLine("creation of node [{0}] failed!\r\nError Condition: {1}\r\nError Type: {2}", m_node, error.Condition, error.Type); } }
// Invoked just after the creation (or retrieving) the node. // If newly created or already exists, then subscribe (or other operations) can be carried out. // otherwise, no-op. private void OnPubSubCreateNode(object sender, IqEventArgs e) { m_bCreated = false; var error = e.Iq.Element<Error>(); if (e.Iq.Type == Matrix.Xmpp.IqType.result) { Debug.WriteLine("node is created!"); m_bCreated = true; } else if (e.Iq.Type == Matrix.Xmpp.IqType.error) { if (error != null) { if (error.Condition == Matrix.Xmpp.Base.ErrorCondition.Conflict) { Debug.WriteLine("Node is already exist!"); m_bCreated = true; } else { Debug.WriteLine("creation of node failed!\r\nError Condition: {0}\r\nError Type: {1}", error.Condition, error.Type); } } } }
private void CreateNodeResult(object sender, IqEventArgs e) { /* <iq from="pubsub.vm-debian" to="alex@vm-debian/MatriX" id="MX_9" type="result" xmlns="jabber:client"> <pubsub xmlns="http://jabber.org/protocol/pubsub"> <create node="/home/vm-debian/alex" /> </pubsub> </iq> */ if (e.Iq.Type == Matrix.Xmpp.IqType.Result) { var pubsub = e.Iq.Element<PubSub>(); if (pubsub != null) { if (pubsub.Create != null) MessageBox.Show(String.Format("node {0} was created!", pubsub.Create.Node)); } } else if (e.Iq.Type == Matrix.Xmpp.IqType.Error) { string node = ""; var error = e.Iq.Element<Error>(); var pubsub = e.Iq.Element<PubSub>(); if (pubsub != null) { if (pubsub.Create != null) node = pubsub.Create.Node; } if (error != null) { string msg = String.Format("creation of node {0} failed!\r\nError Condition: {1}\r\nError Type: {2}", node, error.Condition, error.Type); MessageBox.Show(msg); } } }
private void VcardUpdateResponse(object sender, IqEventArgs e) { if (e.Iq.Type == Matrix.Xmpp.IqType.result) { MessageBox.Show("The VCard was updated successful!!"); } }