public override Packet Handle(Packet packet) { if (packet.GetAttribute("type") == "result") { Logger.Log("Features discovered"); } return packet; }
public override Packet Handle(Packet packet) { if (packet.HasChild("bind")) { var jid = packet.GetChild("bind").GetChild("jid").Value; Logger.Log("Full jid = " + jid); OnBinding(packet); } return packet; }
public void Enqueue(Packet packet) { lock (_lockQ) { if (_packetQ == null) return; if (Stopped) return; _packetQ.Add(packet); // Logger.Log("Enqueuing stanza, count = " + _packetQ.Count); Monitor.Pulse(_lockQ); } }
public void Bind(string resource) { var packet = new Packet("resource") { Value = resource }; var binder = new Packet("bind", "urn:ietf:params:xml:ns:xmpp-bind"); binder.AddChild(packet); var iq = new IQ(IQType.Set); iq.AddChild(binder); Register(iq); Stream.Send(iq); }
private Packet GetAuthPacket() { var auth = new Packet("auth", "urn:ietf:params:xml:ns:xmpp-sasl"); auth.SetAttribute("mechanism", "PLAIN-PW-TOKEN"); var userId = _account.Jid; if (userId.Contains('@'.ToString(CultureInfo.InvariantCulture))) userId = userId.Substring(0, _account.Jid.IndexOf('@')); var token = "\0" + userId + "\0" + _account.Password + "\0" + "somerandomstring"; Logger.Log("Token = " + token); auth.Value = Convert.ToBase64String(Encoding.UTF8.GetBytes(token)); return auth; }
public override Packet Handle(Packet packet) { if (packet.Name == "failure") { // Logger.Log("Auth FAIL - " + packet); } if (packet.Name == "success") { var token = packet.GetChild("pw-token"); var expiry = Int32.Parse(token.GetAttribute("expires_in_minutes")); var value = token.Value; Session.Token = new AuthToken(value, expiry); OnAuthentication(packet); } return packet; }
public override Packet Handle(Packet packet) { if (packet.HasChild("mechanisms")) { var mechanisms = packet.GetChild("mechanisms").GetChildren("mechanism"); if (mechanisms.Any(mechanism => mechanism.Value == "PLAIN-PW-TOKEN")) { var pwAuth = new AuthenticationPlainPw(Session); pwAuth.OnAuthentication += stanza => OnAuthenticated(stanza); pwAuth.Authenticate(); } } if (packet.HasChild("bind")) { var binder = new ResourceBinder(Session); binder.OnBinding += stanza => OnResourceBinding(stanza); binder.Bind(Session.Account.Resource); } return packet; }
public override Packet Handle(Packet packet) { return packet; }
public abstract Packet Handle(Packet packet);
public void Send(Packet packet) { Send(packet.ToString()); }
public void Pulse(Packet packetForStop) { lock (_lockQ) { // Stopped = true; _packetQ.Clear(); _packetQ.Add(packetForStop); Monitor.Pulse(_lockQ); } }
private void HandlePacket(Packet packet) { if (packet == null) return; // Logger.Log("Handling packet ..."); if (packet.Name.Equals("empty")) { Logger.Log("Packet is empty"); } if (packet.Name.Equals("error")) { Logger.Log(packet.HasChild("host-unknown") ? "error - host unknown" : "error"); } if (!packet.HasAttribute("to")) { // Logger.Log("Packet does not have To attribute"); } else { if (!packet.GetAttribute("to").ToLower().Trim().StartsWith(Properties.Account.Jid.ToLower().Trim())) { // Logger.Log("Packet To attribute does not start with Jid " + Properties.Account.Jid); } } _stanzaQueue.Enqueue(packet); }
private void PushPacketOnStackOrProcessPacket(Packet packet) { if (_xmlBuildStack.Count > 0) { _xmlBuildStack.Peek().AddChild(packet); } else { if (packet != null) { Logger.Log("RECD:\n" + packet); HandlePacket(packet); } } }
public override bool HandlingCondition(Packet packet) { return packet.Name == "iq" && packet.GetAttribute("id") == _iq.Id; }
public void CloneAttributesAndChildrenFrom(Packet packetToCloneFrom) { var attribute = packetToCloneFrom.Element.Attributes(); var element = packetToCloneFrom.Element.Elements(); foreach (var xElement in element) { } _element.ReplaceAttributes(attribute); _element.Add(element); }
public override bool HandlingCondition(Packet packet) { return (packet.Name == "features" && packet.HasChild("mechanisms")) || (packet.Name == "features" && packet.HasChild("bind")); }
public static bool IsSuccess(Packet iq) { return iq.HasAttribute(_TYPE, "result"); }
protected void add(Packet node) { _element.Add(node.Element); }
public void UpdateXmlnsIfEmpty(Packet peek) { var aw = peek.Element.Name.Namespace; if (string.IsNullOrEmpty(_element.Name.Namespace.NamespaceName)) _element.Name = aw.GetName(_element.Name.LocalName); }
public bool RemoveChild(Packet child) { var elements = _element.Elements().Where(e => e.Name.LocalName == child.Name); if (elements.Any()) { elements.Remove(); return true; } return false; }
public abstract bool HandlingCondition(Packet packet);
private Packet GetXElement() { var packet = new Packet(_reader.LocalName); if (!_reader.HasAttributes) return packet; while (_reader.MoveToNextAttribute()) { packet.SetAttribute(_reader.LocalName, _reader.Value); } if (_xmlBuildStack.Count > 0) { packet.UpdateXmlnsIfEmpty(_xmlBuildStack.Peek()); } _reader.MoveToElement(); return packet; }
public override bool HandlingCondition(Packet packet) { return (packet.Name == "success" && packet.HasAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl")) || (packet.Name == "failure" && packet.HasAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl")); }
public void AddChild(Packet child) { var aw = _element.Name.Namespace; var xmlElement = child.Element; if (!aw.Equals(XNamespace.None)) { while (xmlElement.Name.Namespace == XNamespace.None) { /*if (String.IsNullOrEmpty(child.getXElement().Name.Namespace.NamespaceName)) { child.getXElement().Name = aw.GetName(child.getXElement().Name.LocalName); }*/ SetNameSpace(aw, xmlElement); } } _element.Add(child.Element); }
public Packet HandleStanza(Packet packet) { // Logger.Log("Handling packet at Xmpp ..."); OnPacketReceived(packet); return packet; }
public static bool IsSet(Packet iq) { return iq.HasAttribute(_TYPE, "set"); }