/// <summary> /// Event arguments for message events. /// </summary> /// <param name="e">Values are taken from this object.</param> public MessageEventArgs(MessageEventArgs e) { this.bodies = e?.bodies; this.subjects = e?.subjects; this.message = e?.message; this.content = e?.content; this.errorElement = e?.errorElement; this.errorType = e?.errorType ?? ErrorType.Undefined; this.stanzaError = e?.stanzaError; this.errorText = e?.errorText; this.client = e?.client; this.component = e?.component; this.type = e?.type ?? MessageType.Normal; this.threadId = e?.threadId; this.parentThreadId = e?.parentThreadId; this.from = e?.from; this.fromBareJid = e?.fromBareJid; this.to = e?.to; this.id = e?.id; this.body = e?.body; this.subject = e?.subject; this.errorCode = e?.errorCode ?? 0; this.ok = e?.ok ?? false; this.e2eEncryption = e?.e2eEncryption; this.e2eReference = e?.e2eReference; }
/// <summary> /// Event arguments for message events. /// </summary> /// <param name="e">Values are taken from this object.</param> public MessageEventArgs(MessageEventArgs e) { this.bodies = e.bodies; this.subjects = e.subjects; this.message = e.message; this.content = e.content; this.errorElement = e.errorElement; this.errorType = e.errorType; this.stanzaError = e.stanzaError; this.errorText = e.errorText; this.client = e.client; this.component = e.component; this.type = e.type; this.threadId = e.threadId; this.parentThreadId = e.parentThreadId; this.from = e.from; this.fromBareJid = e.fromBareJid; this.to = e.to; this.id = e.id; this.body = e.body; this.subject = e.subject; this.errorCode = e.errorCode; this.ok = e.ok; this.e2eEncryption = e.e2eEncryption; this.e2eReference = e.e2eReference; }
/// <summary> /// Event arguments for IQ queries. /// </summary> /// <param name="Component">XMPP Component.</param> /// <param name="Iq">IQ element.</param> /// <param name="Id">Id attribute of IQ stanza.</param> /// <param name="To">To attribute of IQ stanza.</param> /// <param name="From">From attribute of IQ stanza.</param> public IqEventArgs(XmppComponent Component, XmlElement Iq, string Id, string To, string From) { this.client = null; this.component = Component; this.iq = Iq; this.id = Id; this.to = To; this.from = From; }
/// <summary> /// Event arguments for IQ queries. /// </summary> protected IqEventArgs(IqEventArgs e) { this.client = e.client; this.component = e.component; this.iq = e.iq; this.id = e.id; this.to = e.to; this.from = e.from; }
/// <summary> /// Event arguments for IQ queries. /// </summary> /// <param name="Client">XMPP Client.</param> /// <param name="E2eEncryption">End-to-end encryption algorithm used.</param> /// <param name="Iq">IQ element.</param> /// <param name="Id">Id attribute of IQ stanza.</param> /// <param name="To">To attribute of IQ stanza.</param> /// <param name="From">From attribute of IQ stanza.</param> public IqEventArgs(XmppClient Client, IEndToEndEncryption E2eEncryption, XmlElement Iq, string Id, string To, string From) { this.client = Client; this.component = null; this.e2eEncryption = E2eEncryption; this.iq = Iq; this.id = Id; this.to = To; this.from = From; }
/// <summary> /// Event arguments for IQ queries. /// </summary> /// <param name="Component">XMPP Component.</param> /// <param name="Iq">IQ element.</param> /// <param name="Id">Id attribute of IQ stanza.</param> /// <param name="To">To attribute of IQ stanza.</param> /// <param name="From">From attribute of IQ stanza.</param> public IqEventArgs(XmppComponent Component, XmlElement Iq, string Id, string To, string From) { this.client = null; this.component = Component; this.iq = Iq; this.id = Id; this.to = To; this.from = From; this.e2eEncryption = null; this.e2eReference = null; this.e2eSymmetricCipher = null; }
/// <summary> /// Event arguments for IQ queries. /// </summary> protected IqEventArgs(IqEventArgs e) { this.client = e.client; this.component = e.component; this.iq = e.iq; this.id = e.id; this.to = e.to; this.from = e.from; this.e2eEncryption = e.e2eEncryption; this.e2eReference = e.e2eReference; this.e2eSymmetricCipher = e.e2eSymmetricCipher; }
/// <summary> /// Event arguments for IQ queries. /// </summary> /// <param name="Client">XMPP Client.</param> /// <param name="E2eEncryption">End-to-end encryption algorithm used.</param> /// <param name="E2eReference">Reference to End-to-end encryption endpoint used.</param> /// <param name="E2eSymmetricCipher">Type of symmetric cipher used in E2E encryption.</param> /// <param name="Iq">IQ element.</param> /// <param name="Id">Id attribute of IQ stanza.</param> /// <param name="To">To attribute of IQ stanza.</param> /// <param name="From">From attribute of IQ stanza.</param> public IqEventArgs(XmppClient Client, IEndToEndEncryption E2eEncryption, string E2eReference, IE2eSymmetricCipher E2eSymmetricCipher, XmlElement Iq, string Id, string To, string From) { this.client = Client; this.component = null; this.e2eEncryption = E2eEncryption; this.e2eReference = E2eReference; this.e2eSymmetricCipher = E2eSymmetricCipher; this.iq = Iq; this.id = Id; this.to = To; this.from = From; }
public virtual void Setup() { this.clientConnected.Reset(); this.clientError.Reset(); this.clientOffline.Reset(); this.componentConnected.Reset(); this.componentError.Reset(); this.componentOffline.Reset(); this.clientEx = null; this.componentEx = null; this.client = new XmppClient("localhost", 5222, "testuser", "testpass", "en", typeof(CommunicationTests).Assembly) { TrustServer = true, DefaultNrRetries = 2, DefaultRetryTimeout = 1000, DefaultMaxRetryTimeout = 5000, DefaultDropOff = true }; //this.client.Add(new ConsoleOutSniffer(BinaryPresentationMethod.ByteCount)); this.client.OnConnectionError += this.Client_OnConnectionError; this.client.OnError += this.Client_OnError; this.client.OnStateChanged += this.Client_OnStateChanged; this.client.SetPresence(Availability.Chat, new KeyValuePair <string, string>("en", "Live and well")); this.client.Connect(); this.component = new XmppComponent("localhost", 5275, "provisioning.peterwaher-hp14", "provisioning", "collaboration", "provisioning", "Provisioning service") { DefaultNrRetries = 2, DefaultRetryTimeout = 1000, DefaultMaxRetryTimeout = 5000, DefaultDropOff = true }; this.component.Add(new TextWriterSniffer(Console.Out, BinaryPresentationMethod.ByteCount)); this.component.OnConnectionError += this.Component_OnConnectionError; this.component.OnError += this.Component_OnError; this.component.OnStateChanged += this.Component_OnStateChanged; this.WaitConnected(10000); }
/// <summary> /// Event arguments for presence events. /// </summary> /// <param name="e">Copies attributes from this event arguments class.</param> protected PresenceEventArgs(PresenceEventArgs e) { this.statuses = e.statuses; this.presence = e.presence; this.content = e.content; this.errorElement = e.errorElement; this.errorType = e.errorType; this.stanzaError = e.stanzaError; this.errorText = e.errorText; this.client = e.client; this.component = e.component; this.type = e.type; this.availability = e.availability; this.from = e.from; this.fromBareJid = e.fromBareJid; this.to = e.to; this.id = e.id; this.status = e.status; this.errorCode = e.errorCode; this.priority = e.priority; this.ok = e.ok; }
/// <summary> /// Loads simple XMPP component configuration from an XML file. If file does not exist, or is not valid, a console dialog with the /// user is performed, to get the relevant information, test it, and create the corresponding XML file for later use. /// </summary> /// <param name="FileName">Name of configuration file.</param> /// <returns>Simple XMPP component configuration.</returns> public static SimpleComponentConfiguration GetConfigUsingSimpleConsoleDialog(string FileName) { try { return(new SimpleComponentConfiguration(FileName)); } catch (Exception) { SimpleComponentConfiguration Config = new SimpleComponentConfiguration(); bool Ok; Config.host = string.Empty; Config.port = DefaultPort; Config.component = string.Empty; Config.secret = string.Empty; #if WINDOWS_UWP using (XmppComponent Component = new XmppComponent(Config.host, Config.port, Config.component, Config.secret, "collaboration", "test", "Test Component")) { ManualResetEvent Connected = new ManualResetEvent(false); ManualResetEvent Failure = new ManualResetEvent(false); Component.OnStateChanged += (sender, NewState) => { Console.Out.WriteLine(NewState.ToString()); switch (NewState) { case XmppState.Connected: Console.ForegroundColor = ConsoleColor.Green; Console.Out.WriteLine("Connection successful."); Connected.Set(); break; case XmppState.Error: Console.ForegroundColor = ConsoleColor.Red; Console.Out.WriteLine("Connection failed. Please update connection information."); Failure.Set(); break; } }; switch (WaitHandle.WaitAny(new WaitHandle[] { Connected, Failure }, 20000)) { case 0: Ok = true; break; case 1: default: Ok = false; break; } if (!Ok) { throw; } } #else ConsoleColor FgBak = Console.ForegroundColor; string s; string Default; do { Console.ForegroundColor = ConsoleColor.Yellow; Console.Out.WriteLine(); Console.Out.WriteLine("To setup a connection with the XMPP component, please answer the following"); Console.Out.WriteLine("questions:"); Default = Config.host; Console.Out.WriteLine(); Console.Out.WriteLine("What XMPP server do you want to use? Press ENTER to use " + Default); do { Console.ForegroundColor = ConsoleColor.White; Console.Out.Write("XMPP Server: "); Config.host = Console.In.ReadLine(); if (string.IsNullOrEmpty(Config.host)) { Config.host = Default; } Console.ForegroundColor = ConsoleColor.Green; Console.Out.WriteLine(); Console.Out.WriteLine("You've selected to use '" + Config.host + "'. Is this correct? [y/n]"); s = Console.In.ReadLine(); Console.Out.WriteLine(); }while (!s.StartsWith("y", StringComparison.InvariantCultureIgnoreCase)); Default = Config.port.ToString(); Console.ForegroundColor = ConsoleColor.Yellow; Console.Out.WriteLine("What port do you want to connect to? Press ENTER to use " + Default); do { Console.ForegroundColor = ConsoleColor.White; do { Console.Out.Write("Port Number: "); s = Console.In.ReadLine(); if (string.IsNullOrEmpty(s)) { s = Default; } }while (!int.TryParse(s, out Config.port) || Config.port < 1 || Config.port > 65535); Console.ForegroundColor = ConsoleColor.Green; Console.Out.WriteLine(); Console.Out.WriteLine("You've selected to use '" + Config.port.ToString() + "'. Is this correct? [y/n]"); s = Console.In.ReadLine(); Console.Out.WriteLine(); }while (!s.StartsWith("y", StringComparison.InvariantCultureIgnoreCase)); Default = Config.component; Console.ForegroundColor = ConsoleColor.Yellow; Console.Out.WriteLine("What component to you want to connect to?"); if (!string.IsNullOrEmpty(Default)) { Console.Out.WriteLine("Press ENTER to use " + Default); } do { Console.ForegroundColor = ConsoleColor.White; do { Console.Out.Write("Component: "); Config.component = Console.In.ReadLine(); if (string.IsNullOrEmpty(Config.component)) { Config.component = Default; } }while (string.IsNullOrEmpty(Config.component)); Console.ForegroundColor = ConsoleColor.Green; Console.Out.WriteLine(); Console.Out.WriteLine("You've selected to use '" + Config.component + "'. Is this correct? [y/n]"); s = Console.In.ReadLine(); Console.Out.WriteLine(); }while (!s.StartsWith("y", StringComparison.InvariantCultureIgnoreCase)); Default = Config.secret; Console.ForegroundColor = ConsoleColor.Yellow; Console.Out.WriteLine("What secret goes with the component? Remember that the configuration will,"); Console.Out.WriteLine("be stored in a simple text file along with the application."); if (!string.IsNullOrEmpty(Default)) { Console.Out.WriteLine("Press ENTER to use " + Default); } do { Console.ForegroundColor = ConsoleColor.White; do { Console.Out.Write("Secret: "); Config.secret = Console.In.ReadLine(); if (string.IsNullOrEmpty(Config.secret)) { Config.secret = Default; } }while (string.IsNullOrEmpty(Config.secret)); Console.ForegroundColor = ConsoleColor.Green; Console.Out.WriteLine(); Console.Out.WriteLine("You've selected to use '" + Config.secret + "'. Is this correct? [y/n]"); s = Console.In.ReadLine(); Console.Out.WriteLine(); }while (!s.StartsWith("y", StringComparison.InvariantCultureIgnoreCase)); Console.ForegroundColor = ConsoleColor.Yellow; Console.Out.WriteLine("I will now try to connect to the server to see if the information"); Console.Out.WriteLine("provided is correct."); using (XmppComponent Component = new XmppComponent(Config.host, Config.port, Config.component, Config.secret, "collaboration", "test", "Test Component")) { ManualResetEvent Connected = new ManualResetEvent(false); ManualResetEvent Failure = new ManualResetEvent(false); Component.OnStateChanged += (sender, NewState) => { Console.Out.WriteLine(NewState.ToString()); switch (NewState) { case XmppState.Connected: Console.ForegroundColor = ConsoleColor.Green; Console.Out.WriteLine("Connection successful."); Connected.Set(); break; case XmppState.Error: Console.ForegroundColor = ConsoleColor.Red; Console.Out.WriteLine("Connection failed. Please update connection information."); Failure.Set(); break; } }; switch (WaitHandle.WaitAny(new WaitHandle[] { Connected, Failure }, 20000)) { case 0: Ok = true; break; case 1: default: Ok = false; break; } } }while (!Ok); Console.ForegroundColor = ConsoleColor.Yellow; Console.Out.WriteLine("Do you want to use a sniffer? If you use a sniffer, XMPP network"); Console.Out.WriteLine("communication will be Output to the console in real-time. This can"); Console.Out.WriteLine("come in handy when debugging network communication."); do { Console.ForegroundColor = ConsoleColor.White; Console.Out.Write("Sniffer [y/n]? "); s = Console.In.ReadLine(); Config.sniffer = s.StartsWith("y", StringComparison.InvariantCultureIgnoreCase); }while (!Config.sniffer && !s.StartsWith("n", StringComparison.InvariantCultureIgnoreCase)); Console.Out.WriteLine(); Console.ForegroundColor = FgBak; #endif Config.Save(FileName); return(Config); } }
private MessageEventArgs(XmppClient Client, XmppComponent Component, XmlElement Message) { XmlElement E; this.message = Message; this.client = Client; this.component = Component; this.from = XML.Attribute(Message, "from"); this.to = XML.Attribute(Message, "to"); this.id = XML.Attribute(Message, "id"); this.ok = true; this.errorCode = 0; this.fromBareJid = XmppClient.GetBareJID(this.from); switch (XML.Attribute(Message, "type").ToLower()) { case "chat": this.type = MessageType.Chat; break; case "error": this.type = MessageType.Error; this.ok = false; break; case "groupchat": this.type = MessageType.GroupChat; break; case "headline": this.type = MessageType.Headline; break; case "normal": default: this.type = MessageType.Normal; break; } SortedDictionary <string, string> Bodies = new SortedDictionary <string, string>(); SortedDictionary <string, string> Subjects = new SortedDictionary <string, string>(); foreach (XmlNode N in Message.ChildNodes) { E = N as XmlElement; if (E is null) { continue; } if (E.NamespaceURI == Message.NamespaceURI) { switch (E.LocalName) { case "body": if (string.IsNullOrEmpty(this.body)) { this.body = N.InnerText; } string Language = XML.Attribute(E, "xml:lang"); Bodies[Language] = N.InnerText; break; case "subject": if (string.IsNullOrEmpty(this.subject)) { this.subject = N.InnerText; } Language = XML.Attribute(E, "xml:lang"); Subjects[Language] = N.InnerText; break; case "thread": this.threadId = N.InnerText; this.parentThreadId = XML.Attribute(E, "parent"); break; case "error": this.errorElement = E; this.errorCode = XML.Attribute(E, "code", 0); this.ok = false; switch (XML.Attribute(E, "type")) { case "auth": this.errorType = ErrorType.Auth; break; case "cancel": this.errorType = ErrorType.Cancel; break; case "continue": this.errorType = ErrorType.Continue; break; case "modify": this.errorType = ErrorType.Modify; break; case "wait": this.errorType = ErrorType.Wait; break; default: this.errorType = ErrorType.Undefined; break; } this.stanzaError = XmppClient.GetStanzaExceptionObject(E); this.errorText = this.stanzaError.Message; break; } } else if (this.content is null) { this.content = E; } } this.bodies = new KeyValuePair <string, string> [Bodies.Count]; Bodies.CopyTo(this.bodies, 0); this.subjects = new KeyValuePair <string, string> [Subjects.Count]; Subjects.CopyTo(this.subjects, 0); }
/// <summary> /// Event arguments for message events. /// </summary> /// <param name="Component">Component</param> /// <param name="Message">Message element.</param> public MessageEventArgs(XmppComponent Component, XmlElement Message) : this(null, Component, Message) { }
private PresenceEventArgs(XmppClient Client, XmppComponent Component, XmlElement Presence) { XmlElement E; int i; this.presence = Presence; this.client = Client; this.component = Component; this.from = XML.Attribute(Presence, "from"); this.to = XML.Attribute(Presence, "to"); this.id = XML.Attribute(Presence, "id"); this.ok = true; this.errorCode = 0; this.availability = Availability.Online; i = this.from.IndexOf('/'); if (i < 0) { this.fromBareJid = this.from; } else { this.fromBareJid = this.from.Substring(0, i); } switch (XML.Attribute(Presence, "type").ToLower()) { case "error": this.type = PresenceType.Error; break; case "probe": this.type = PresenceType.Probe; break; case "subscribe": this.type = PresenceType.Subscribe; break; case "subscribed": this.type = PresenceType.Subscribed; break; case "unavailable": this.type = PresenceType.Unavailable; this.availability = Availability.Offline; break; case "unsubscribe": this.type = PresenceType.Unsubscribe; break; case "unsubscribed": this.type = PresenceType.Unsubscribed; break; default: this.type = PresenceType.Available; break; } SortedDictionary <string, string> Statuses = new SortedDictionary <string, string>(); foreach (XmlNode N in Presence.ChildNodes) { E = N as XmlElement; if (E == null) { continue; } if (E.NamespaceURI == Presence.NamespaceURI) { switch (E.LocalName) { case "show": switch (E.InnerText.ToLower()) { case "away": this.availability = Availability.Away; break; case "chat": this.availability = Availability.Chat; break; case "dnd": this.availability = Availability.DoNotDisturb; break; case "xa": this.availability = Availability.ExtendedAway; break; default: this.availability = Availability.Online; break; } break; case "status": if (string.IsNullOrEmpty(this.status)) { this.status = N.InnerText; } string Language = XML.Attribute(E, "xml:lang"); Statuses[Language] = N.InnerText; break; case "priority": if (!sbyte.TryParse(N.InnerText, out this.priority)) { this.priority = 0; } break; case "error": this.errorElement = E; this.errorCode = XML.Attribute(E, "code", 0); this.ok = false; switch (XML.Attribute(E, "type")) { case "auth": this.errorType = ErrorType.Auth; break; case "cancel": this.errorType = ErrorType.Cancel; break; case "continue": this.errorType = ErrorType.Continue; break; case "modify": this.errorType = ErrorType.Modify; break; case "wait": this.errorType = ErrorType.Wait; break; default: this.errorType = ErrorType.Undefined; break; } this.stanzaError = XmppClient.GetStanzaExceptionObject(E); this.errorText = this.stanzaError.Message; break; } } else if (E.NamespaceURI == XmppClient.NamespaceEntityCapabilities && E.LocalName == "c") { this.entityCapabilityVersion = XML.Attribute(E, "ver"); this.entityCapabilityNode = XML.Attribute(E, "node"); this.entityCapabilityHashFunction = XML.Attribute(E, "hash"); this.hasEntityCapabilities = true; } else if (this.content == null) { this.content = E; } } this.statuses = new KeyValuePair <string, string> [Statuses.Count]; Statuses.CopyTo(this.statuses, 0); }
internal PresenceEventArgs(XmppComponent Component, XmlElement Presence) : this(null, Component, Presence) { }