/// <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 responses to IQ queries. /// </summary> /// <param name="Response">Response element.</param> /// <param name="Id">ID attribute.</param> /// <param name="To">To attribute.</param> /// <param name="From">From attribute.</param> /// <param name="Ok">If response is a proper response (true), or an error response (false).</param> /// <param name="State">State object passed in the original request.</param> public IqResultEventArgs(XmlElement Response, string Id, string To, string From, bool Ok, object State) { XmlElement E; this.response = Response; this.id = Id; this.to = To; this.from = From; this.ok = Ok; this.state = State; this.errorCode = 0; if (!Ok && Response != null) { foreach (XmlNode N in Response.ChildNodes) { E = N as XmlElement; if (E is null) { continue; } if (E.LocalName == "error" && E.NamespaceURI == Response.NamespaceURI) { this.errorElement = E; this.errorCode = XML.Attribute(E, "code", 0); 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; } } } }
/// <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 responses to IQ queries. /// </summary> /// <param name="e">Values are taken from this object.</param> protected IqResultEventArgs(IqResultEventArgs e) { this.response = e.response; this.errorElement = e.errorElement; this.errorType = e.errorType; this.stanzaError = e.stanzaError; this.errorText = e.errorText; this.state = e.state; this.id = e.id; this.to = e.to; this.from = e.from; this.errorCode = e.errorCode; this.ok = e.ok; }
/// <summary> /// Event arguments for responses to IQ queries. /// </summary> /// <param name="e">Values are taken from this object.</param> protected IqResultEventArgs(IqResultEventArgs e) { this.response = e.response; this.errorElement = e.errorElement; this.errorType = e.errorType; this.stanzaError = e.stanzaError; this.errorText = e.errorText; this.state = e.state; this.id = e.id; this.to = e.to; this.from = e.from; this.errorCode = e.errorCode; this.ok = e.ok; this.e2eEncryption = e.e2eEncryption; this.e2eReference = e.e2eReference; this.e2eSymmetricCipher = e.e2eSymmetricCipher; }
/// <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; }
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); }
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); }